|
| 1 | + |
| 2 | +require 'rails_helper' |
| 3 | + |
| 4 | +RSpec.describe 'Sign Up process' do |
| 5 | + include_context 'with graphql schema test' |
| 6 | + |
| 7 | + let(:schema) { DummySchema } |
| 8 | + let(:user) { create(:user, :confirmed) } |
| 9 | + |
| 10 | + describe 'publicField' do |
| 11 | + let(:query) do |
| 12 | + <<-GRAPHQL |
| 13 | + query { |
| 14 | + publicField |
| 15 | + } |
| 16 | + GRAPHQL |
| 17 | + end |
| 18 | + |
| 19 | + context 'when using a regular schema' do |
| 20 | + it 'does not require authentication' do |
| 21 | + expect(response[:data][:publicField]).to eq('Field does not require authentication') |
| 22 | + end |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + describe 'privateField' do |
| 27 | + let(:query) do |
| 28 | + <<-GRAPHQL |
| 29 | + query { |
| 30 | + privateField |
| 31 | + } |
| 32 | + GRAPHQL |
| 33 | + end |
| 34 | + |
| 35 | + context 'when using a regular schema' do |
| 36 | + context 'when user is authenticated' do |
| 37 | + let(:resource) { user } |
| 38 | + |
| 39 | + it 'allows to perform the query' do |
| 40 | + expect(response[:data][:privateField]).to eq('Field will always require authentication') |
| 41 | + end |
| 42 | + |
| 43 | + context 'when using a SchemaUser' do |
| 44 | + let(:resource) { create(:schema_user, :confirmed) } |
| 45 | + |
| 46 | + it 'allows to perform the query' do |
| 47 | + expect(response[:data][:privateField]).to eq('Field will always require authentication') |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + context 'when user is not authenticated' do |
| 53 | + it 'returns a must sign in error' do |
| 54 | + expect(response[:errors]).to contain_exactly( |
| 55 | + hash_including( |
| 56 | + message: 'privateField field requires authentication', |
| 57 | + extensions: { code: 'AUTHENTICATION_ERROR' } |
| 58 | + ) |
| 59 | + ) |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + context 'when using an interpreter schema' do |
| 65 | + let(:schema) { InterpreterSchema } |
| 66 | + |
| 67 | + context 'when user is authenticated' do |
| 68 | + let(:resource) { user } |
| 69 | + |
| 70 | + it 'allows to perform the query' do |
| 71 | + expect(response[:data][:privateField]).to eq('Field will always require authentication') |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context 'when user is not authenticated' do |
| 76 | + it 'returns a must sign in error' do |
| 77 | + expect(response[:errors]).to contain_exactly( |
| 78 | + hash_including( |
| 79 | + message: 'privateField field requires authentication', |
| 80 | + extensions: { code: 'AUTHENTICATION_ERROR' } |
| 81 | + ) |
| 82 | + ) |
| 83 | + end |
| 84 | + end |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + describe 'user' do |
| 89 | + let(:query) do |
| 90 | + <<-GRAPHQL |
| 91 | + query { |
| 92 | + user(id: #{user.id}) { |
| 93 | + id |
| 94 | + email |
| 95 | + } |
| 96 | + } |
| 97 | + GRAPHQL |
| 98 | + end |
| 99 | + |
| 100 | + context 'when using a regular schema' do |
| 101 | + context 'when user is authenticated' do |
| 102 | + let(:resource) { user } |
| 103 | + |
| 104 | + it 'allows to perform the query' do |
| 105 | + expect(response[:data][:user]).to match( |
| 106 | + email: user.email, |
| 107 | + id: user.id |
| 108 | + ) |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + context 'when user is not authenticated' do |
| 113 | + it 'returns a must sign in error' do |
| 114 | + expect(response[:errors]).to contain_exactly( |
| 115 | + hash_including( |
| 116 | + message: 'user field requires authentication', |
| 117 | + extensions: { code: 'AUTHENTICATION_ERROR' } |
| 118 | + ) |
| 119 | + ) |
| 120 | + end |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + context 'when using an interpreter schema' do |
| 125 | + let(:schema) { InterpreterSchema } |
| 126 | + |
| 127 | + context 'when user is authenticated' do |
| 128 | + let(:resource) { user } |
| 129 | + |
| 130 | + it 'allows to perform the query' do |
| 131 | + expect(response[:data][:user]).to match( |
| 132 | + email: user.email, |
| 133 | + id: user.id |
| 134 | + ) |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + context 'when user is not authenticated' do |
| 139 | + # Interpreter schema fields are public unless specified otherwise (plugin setting) |
| 140 | + it 'allows to perform the query' do |
| 141 | + expect(response[:data][:user]).to match( |
| 142 | + email: user.email, |
| 143 | + id: user.id |
| 144 | + ) |
| 145 | + end |
| 146 | + end |
| 147 | + end |
| 148 | + end |
| 149 | +end |
0 commit comments