|
17 | 17 | passwordConfirmation: "#{password}" |
18 | 18 | confirmSuccessUrl: "#{redirect}" |
19 | 19 | ) { |
20 | | - success |
21 | | - errors |
22 | 20 | user { |
23 | 21 | email |
24 | 22 | name |
|
28 | 26 | GRAPHQL |
29 | 27 | end |
30 | 28 |
|
31 | | - it 'creates a new resource that requires confirmation' do |
32 | | - expect { |
33 | | - post '/api/v1/graphql_auth', *graphql_params |
34 | | - json_response |
35 | | - }.to( |
36 | | - change(User, :count).by(1) |
37 | | - .and(change(ActionMailer::Base.deliveries, :count).by(1)) |
38 | | - ) |
39 | | - |
40 | | - user = User.last |
41 | | - expect(user).not_to be_active_for_authentication |
42 | | - expect(user.confirmed_at).to be_nil |
43 | | - expect(user.valid_password?(password)).to be_truthy |
44 | | - expect(json_response[:data][:userSignUp]).to include( |
45 | | - success: true, |
46 | | - errors: [], |
47 | | - user: { |
48 | | - email: email, |
49 | | - name: name |
50 | | - } |
51 | | - ) |
| 29 | + context 'when params are correct' do |
| 30 | + it 'creates a new resource that requires confirmation' do |
| 31 | + expect { post_request }.to( |
| 32 | + change(User, :count).by(1) |
| 33 | + .and(change(ActionMailer::Base.deliveries, :count).by(1)) |
| 34 | + ) |
| 35 | + |
| 36 | + user = User.last |
| 37 | + expect(user).not_to be_active_for_authentication |
| 38 | + expect(user.confirmed_at).to be_nil |
| 39 | + expect(user.valid_password?(password)).to be_truthy |
| 40 | + expect(json_response[:data][:userSignUp]).to include( |
| 41 | + user: { |
| 42 | + email: email, |
| 43 | + name: name |
| 44 | + } |
| 45 | + ) |
| 46 | + |
| 47 | + email = ActionMailer::Base.deliveries.last |
| 48 | + query = ERB::Util.url_encode("confirmAccount($token:ID!,$clientConfig:String,redirect:String!){userConfirmAccount(token:$token,clientConfig:$clientConfig,redirect:$redirect){success,errors}}&variables={token:\"#{user.confirmation_token}\",clientConfig:\"default\",redirect:\"#{redirect}\"}").html_safe |
| 49 | + expect(email.body.encoded).to match(/query="#{query}"/) |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + context 'when required params are missing' do |
| 54 | + let(:email) { '' } |
| 55 | + |
| 56 | + it 'does *NOT* create resource a resource nor send an email' do |
| 57 | + expect { post_request }.to( |
| 58 | + not_change(User, :count) |
| 59 | + .and(not_change(ActionMailer::Base.deliveries, :count)) |
| 60 | + ) |
52 | 61 |
|
53 | | - email = ActionMailer::Base.deliveries.last |
54 | | - query = ERB::Util.url_encode("confirmAccount($token:ID!,$clientConfig:String,redirect:String!){userConfirmAccount(token:$token,clientConfig:$clientConfig,redirect:$redirect){success,errors}}&variables={token:\"#{user.confirmation_token}\",clientConfig:\"default\",redirect:\"#{redirect}\"}").html_safe |
55 | | - expect(email.body.encoded).to match(/query="#{query}"/) |
| 62 | + expect(json_response[:data][:userSignUp]).to be_nil |
| 63 | + expect(json_response[:errors]).to containing_exactly( |
| 64 | + hash_including( |
| 65 | + message: "User couldn't be registered", |
| 66 | + extensions: { code: 'USER_ERROR', detailed_errors: ["Email can't be blank"] } |
| 67 | + ) |
| 68 | + ) |
| 69 | + end |
56 | 70 | end |
57 | 71 | end |
0 commit comments