-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathuser_queries_spec.rb
More file actions
118 lines (98 loc) · 2.91 KB
/
user_queries_spec.rb
File metadata and controls
118 lines (98 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Users controller specs' do
include_context 'with graphql schema test'
let(:schema) { DummySchema }
let(:user) { create(:user, :confirmed) }
let(:field) { 'privateField' }
let(:public_message) { 'Field does not require authentication' }
let(:private_message) { 'Field will always require authentication' }
let(:private_error) do
{
message: "#{field} field requires authentication",
extensions: { code: 'AUTHENTICATION_ERROR' }
}
end
describe 'publicField' do
let(:query) do
<<-GRAPHQL
query {
publicField
}
GRAPHQL
end
context 'when using a regular schema' do
it 'does not require authentication' do
expect(response[:data][:publicField]).to eq(public_message)
end
end
end
describe 'privateField' do
let(:query) do
<<-GRAPHQL
query {
privateField
}
GRAPHQL
end
context 'when using a regular schema' do
context 'when user is authenticated' do
let(:resource) { user }
it 'allows to perform the query' do
expect(response[:data][:privateField]).to eq(private_message)
end
context 'when using a SchemaUser' do
let(:resource) { create(:schema_user, :confirmed) }
it 'allows to perform the query' do
expect(response[:data][:privateField]).to eq(private_message)
end
end
end
end
context 'when using an interpreter schema' do
let(:schema) { InterpreterSchema }
context 'when user is authenticated' do
let(:resource) { user }
it 'allows to perform the query' do
expect(response[:data][:privateField]).to eq(private_message)
end
end
end
end
describe 'user' do
let(:user_data) { { email: user.email, id: user.id } }
let(:query) do
<<-GRAPHQL
query {
user(id: #{user.id}) {
id
email
}
}
GRAPHQL
end
context 'when using a regular schema' do
context 'when user is authenticated' do
let(:resource) { user }
it 'allows to perform the query' do
expect(response[:data][:user]).to match(**user_data)
end
end
end
context 'when using an interpreter schema' do
let(:schema) { InterpreterSchema }
context 'when user is authenticated' do
let(:resource) { user }
it 'allows to perform the query' do
expect(response[:data][:user]).to match(**user_data)
end
end
context 'when user is not authenticated' do
# Interpreter schema fields are public unless specified otherwise (plugin setting)
it 'allows to perform the query' do
expect(response[:data][:user]).to match(**user_data)
end
end
end
end
end