graphql_devise 0.12.3 → 0.13.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -0
  3. data/Gemfile +2 -0
  4. data/README.md +116 -65
  5. data/Rakefile +2 -0
  6. data/app/controllers/graphql_devise/application_controller.rb +2 -0
  7. data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +6 -0
  8. data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
  9. data/app/helpers/graphql_devise/application_helper.rb +2 -0
  10. data/app/helpers/graphql_devise/mailer_helper.rb +2 -0
  11. data/app/models/graphql_devise/concerns/model.rb +16 -0
  12. data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
  13. data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
  14. data/config/routes.rb +2 -0
  15. data/lib/generators/graphql_devise/install_generator.rb +3 -1
  16. data/lib/graphql_devise.rb +2 -0
  17. data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
  18. data/lib/graphql_devise/default_operations/mutations.rb +2 -0
  19. data/lib/graphql_devise/default_operations/resolvers.rb +2 -0
  20. data/lib/graphql_devise/engine.rb +2 -0
  21. data/lib/graphql_devise/errors/authentication_error.rb +2 -0
  22. data/lib/graphql_devise/errors/detailed_user_error.rb +2 -0
  23. data/lib/graphql_devise/errors/error_codes.rb +2 -0
  24. data/lib/graphql_devise/errors/execution_error.rb +2 -0
  25. data/lib/graphql_devise/errors/user_error.rb +2 -0
  26. data/lib/graphql_devise/model/with_email_updater.rb +74 -0
  27. data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -0
  28. data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
  29. data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +2 -0
  30. data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +2 -0
  31. data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +2 -0
  32. data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +2 -0
  33. data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +2 -0
  34. data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
  35. data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
  36. data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
  37. data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
  38. data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
  39. data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
  40. data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
  41. data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
  42. data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
  43. data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
  44. data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
  45. data/lib/graphql_devise/mutations/base.rb +2 -0
  46. data/lib/graphql_devise/mutations/login.rb +2 -0
  47. data/lib/graphql_devise/mutations/logout.rb +2 -0
  48. data/lib/graphql_devise/mutations/resend_confirmation.rb +16 -6
  49. data/lib/graphql_devise/mutations/send_password_reset.rb +3 -1
  50. data/lib/graphql_devise/mutations/sign_up.rb +12 -3
  51. data/lib/graphql_devise/mutations/update_password.rb +2 -0
  52. data/lib/graphql_devise/rails/routes.rb +2 -0
  53. data/lib/graphql_devise/resolvers/base.rb +2 -0
  54. data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
  55. data/lib/graphql_devise/resolvers/confirm_account.rb +7 -2
  56. data/lib/graphql_devise/resolvers/dummy.rb +2 -0
  57. data/lib/graphql_devise/resource_loader.rb +2 -0
  58. data/lib/graphql_devise/schema.rb +2 -0
  59. data/lib/graphql_devise/schema_plugin.rb +8 -0
  60. data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
  61. data/lib/graphql_devise/types/credential_type.rb +2 -0
  62. data/lib/graphql_devise/types/mutation_type.rb +2 -0
  63. data/lib/graphql_devise/types/query_type.rb +2 -0
  64. data/lib/graphql_devise/version.rb +3 -1
  65. data/spec/dummy/Rakefile +2 -0
  66. data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +3 -1
  67. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  68. data/spec/dummy/app/graphql/dummy_schema.rb +4 -1
  69. data/spec/dummy/app/graphql/interpreter_schema.rb +2 -0
  70. data/spec/dummy/app/graphql/mutations/login.rb +2 -0
  71. data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
  72. data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
  73. data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
  74. data/spec/dummy/app/graphql/resolvers/confirm_admin_account.rb +13 -0
  75. data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
  76. data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
  77. data/spec/dummy/app/graphql/types/admin_type.rb +8 -0
  78. data/spec/dummy/app/graphql/types/base_object.rb +2 -0
  79. data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
  80. data/spec/dummy/app/graphql/types/mutation_type.rb +3 -0
  81. data/spec/dummy/app/graphql/types/query_type.rb +2 -0
  82. data/spec/dummy/app/graphql/types/user_type.rb +2 -0
  83. data/spec/dummy/app/jobs/application_job.rb +2 -0
  84. data/spec/dummy/app/mailers/application_mailer.rb +2 -0
  85. data/spec/dummy/app/models/admin.rb +2 -0
  86. data/spec/dummy/app/models/application_record.rb +2 -0
  87. data/spec/dummy/app/models/guest.rb +2 -0
  88. data/spec/dummy/app/models/schema_user.rb +13 -0
  89. data/spec/dummy/app/models/user.rb +2 -0
  90. data/spec/dummy/app/models/users.rb +2 -0
  91. data/spec/dummy/app/models/users/customer.rb +2 -0
  92. data/spec/dummy/config.ru +2 -0
  93. data/spec/dummy/config/application.rb +2 -0
  94. data/spec/dummy/config/environment.rb +2 -0
  95. data/spec/dummy/config/environments/development.rb +2 -0
  96. data/spec/dummy/config/environments/production.rb +2 -0
  97. data/spec/dummy/config/environments/test.rb +2 -0
  98. data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
  99. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  100. data/spec/dummy/config/initializers/cors.rb +2 -0
  101. data/spec/dummy/config/initializers/devise.rb +1 -1
  102. data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
  103. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  104. data/spec/dummy/config/initializers/i18n.rb +2 -0
  105. data/spec/dummy/config/initializers/inflections.rb +2 -0
  106. data/spec/dummy/config/initializers/mime_types.rb +2 -0
  107. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  108. data/spec/dummy/config/puma.rb +2 -0
  109. data/spec/dummy/config/routes.rb +5 -0
  110. data/spec/dummy/config/spring.rb +2 -0
  111. data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
  112. data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
  113. data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
  114. data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
  115. data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
  116. data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
  117. data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
  118. data/spec/dummy/db/schema.rb +28 -2
  119. data/spec/dummy/db/seeds.rb +2 -0
  120. data/spec/factories/admins.rb +2 -0
  121. data/spec/factories/guests.rb +2 -0
  122. data/spec/factories/schema_users.rb +13 -0
  123. data/spec/factories/users.rb +2 -0
  124. data/spec/factories/users_customers.rb +2 -0
  125. data/spec/generators/graphql_devise/install_generator_spec.rb +3 -1
  126. data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
  127. data/spec/graphql_devise_spec.rb +2 -0
  128. data/spec/models/user_spec.rb +2 -0
  129. data/spec/rails_helper.rb +3 -0
  130. data/spec/requests/graphql_controller_spec.rb +2 -0
  131. data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
  132. data/spec/requests/mutations/additional_queries_spec.rb +2 -0
  133. data/spec/requests/mutations/login_spec.rb +2 -0
  134. data/spec/requests/mutations/logout_spec.rb +2 -0
  135. data/spec/requests/mutations/resend_confirmation_spec.rb +29 -4
  136. data/spec/requests/mutations/send_password_reset_spec.rb +2 -0
  137. data/spec/requests/mutations/sign_up_spec.rb +15 -2
  138. data/spec/requests/mutations/update_password_spec.rb +2 -0
  139. data/spec/requests/queries/check_password_token_spec.rb +2 -0
  140. data/spec/requests/queries/confirm_account_spec.rb +102 -42
  141. data/spec/requests/user_controller_spec.rb +57 -8
  142. data/spec/services/mount_method/operation_preparer_spec.rb +2 -0
  143. data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +2 -0
  144. data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +2 -0
  145. data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
  146. data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +2 -0
  147. data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
  148. data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +2 -0
  149. data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
  150. data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
  151. data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
  152. data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
  153. data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
  154. data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
  155. data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
  156. data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
  157. data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
  158. data/spec/services/mount_method/options_validator_spec.rb +2 -0
  159. data/spec/services/resource_loader_spec.rb +2 -0
  160. data/spec/services/schema_plugin_spec.rb +2 -0
  161. data/spec/spec_helper.rb +2 -0
  162. data/spec/support/contexts/graphql_request.rb +2 -0
  163. data/spec/support/factory_bot.rb +2 -0
  164. data/spec/support/matchers/auth_headers_matcher.rb +2 -0
  165. data/spec/support/matchers/not_change_matcher.rb +2 -0
  166. data/spec/support/requests/auth_helpers.rb +2 -0
  167. data/spec/support/requests/json_helpers.rb +2 -0
  168. metadata +19 -2
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Resend confirmation' do
4
6
  include_context 'with graphql query request'
5
7
 
6
- let!(:user) { create(:user, confirmed_at: nil, email: 'mwallace@wallaceinc.com') }
7
- let(:email) { user.email }
8
- let(:id) { user.id }
9
- let(:redirect) { Faker::Internet.url }
8
+ let(:confirmed_at) { nil }
9
+ let!(:user) { create(:user, confirmed_at: nil, email: 'mwallace@wallaceinc.com') }
10
+ let(:email) { user.email }
11
+ let(:id) { user.id }
12
+ let(:redirect) { Faker::Internet.url }
10
13
  let(:query) do
11
14
  <<-GRAPHQL
12
15
  mutation {
@@ -96,6 +99,28 @@ RSpec.describe 'Resend confirmation' do
96
99
  end
97
100
  end
98
101
 
102
+ context 'when the email was changed' do
103
+ let(:confirmed_at) { 2.seconds.ago }
104
+ let(:email) { 'new-email@wallaceinc.com' }
105
+ let(:new_email) { email }
106
+
107
+ before do
108
+ user.update_with_email(
109
+ email: new_email,
110
+ schema_url: 'http://localhost/test',
111
+ confirmation_success_url: 'https://google.com'
112
+ )
113
+ end
114
+
115
+ it 'sends new confirmation email' do
116
+ expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
117
+ expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(new_email)
118
+ expect(json_response[:data][:userResendConfirmation]).to include(
119
+ message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
120
+ )
121
+ end
122
+ end
123
+
99
124
  context "when the email isn't in the system" do
100
125
  let(:email) { 'nothere@gmail.com' }
101
126
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Send Password Reset Requests' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Sign Up process' do
@@ -19,6 +21,7 @@ RSpec.describe 'Sign Up process' do
19
21
  passwordConfirmation: "#{password}"
20
22
  confirmSuccessUrl: "#{redirect}"
21
23
  ) {
24
+ credentials { accessToken }
22
25
  user {
23
26
  email
24
27
  name
@@ -41,7 +44,8 @@ RSpec.describe 'Sign Up process' do
41
44
  expect(user.confirmed_at).to be_nil
42
45
  expect(user).to be_valid_password(password)
43
46
  expect(json_response[:data][:userSignUp]).to include(
44
- user: {
47
+ credentials: nil,
48
+ user: {
45
49
  email: email,
46
50
  name: name
47
51
  }
@@ -124,6 +128,7 @@ RSpec.describe 'Sign Up process' do
124
128
  passwordConfirmation: "#{password}"
125
129
  confirmSuccessUrl: "#{redirect}"
126
130
  ) {
131
+ credentials { accessToken client uid }
127
132
  authenticatable {
128
133
  email
129
134
  }
@@ -132,8 +137,16 @@ RSpec.describe 'Sign Up process' do
132
137
  GRAPHQL
133
138
  end
134
139
 
135
- it 'works without the confirmable module' do
140
+ it 'returns credentials as no confirmation is required' do
136
141
  expect { post_request }.to change(Guest, :count).from(0).to(1)
142
+
143
+ expect(json_response[:data][:guestSignUp]).to include(
144
+ authenticatable: { email: email },
145
+ credentials: hash_including(
146
+ uid: email,
147
+ client: Guest.last.tokens.keys.first
148
+ )
149
+ )
137
150
  end
138
151
  end
139
152
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Update Password Requests' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Check Password Token Requests' do
@@ -1,62 +1,122 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Account confirmation' do
4
6
  include_context 'with graphql query request'
5
7
 
6
- let(:user) { create(:user, confirmed_at: nil) }
7
- let(:redirect) { Faker::Internet.url }
8
- let(:query) do
9
- <<-GRAPHQL
10
- {
11
- userConfirmAccount(
12
- confirmationToken: "#{token}"
13
- redirectUrl: "#{redirect}"
14
- ) {
15
- email
16
- name
8
+ context 'when using the user model' do
9
+ let(:user) { create(:user, confirmed_at: nil) }
10
+ let(:redirect) { Faker::Internet.url }
11
+ let(:query) do
12
+ <<-GRAPHQL
13
+ {
14
+ userConfirmAccount(
15
+ confirmationToken: "#{token}"
16
+ redirectUrl: "#{redirect}"
17
+ ) {
18
+ email
19
+ name
20
+ }
17
21
  }
18
- }
19
- GRAPHQL
20
- end
22
+ GRAPHQL
23
+ end
24
+
25
+ context 'when confirmation token is correct' do
26
+ let(:token) { user.confirmation_token }
27
+
28
+ before do
29
+ user.send_confirmation_instructions(
30
+ template_path: ['graphql_devise/mailer'],
31
+ controller: 'graphql_devise/graphql',
32
+ schema_url: 'http://not-using-this-value.com/gql'
33
+ )
34
+ end
35
+
36
+ it 'confirms the resource and redirects to the sent url' do
37
+ expect do
38
+ get_request
39
+ user.reload
40
+ end.to(change(user, :confirmed_at).from(nil))
41
+
42
+ expect(response).to redirect_to("#{redirect}?account_confirmation_success=true")
43
+ expect(user).to be_active_for_authentication
44
+ end
21
45
 
22
- context 'when confirmation token is correct' do
23
- let(:token) { user.confirmation_token }
46
+ context 'when unconfirmed_email is present' do
47
+ let(:user) { create(:user, :confirmed, unconfirmed_email: 'vvega@wallaceinc.com') }
24
48
 
25
- before do
26
- user.send_confirmation_instructions(
27
- template_path: ['graphql_devise/mailer'],
28
- controller: 'graphql_devise/graphql',
29
- action: 'auth'
30
- )
49
+ it 'confirms the unconfirmed email and redirects' do
50
+ expect do
51
+ get_request
52
+ user.reload
53
+ end.to change(user, :email).from(user.email).to('vvega@wallaceinc.com').and(
54
+ change(user, :unconfirmed_email).from('vvega@wallaceinc.com').to(nil)
55
+ )
56
+
57
+ expect(response).to redirect_to("#{redirect}?account_confirmation_success=true")
58
+ end
59
+ end
31
60
  end
32
61
 
33
- it 'confirms the resource and redirects to the sent url' do
34
- expect do
35
- get_request
36
- user.reload
37
- end.to(change(user, :confirmed_at).from(nil))
62
+ context 'when reset password token is not found' do
63
+ let(:token) { "#{user.confirmation_token}-invalid" }
64
+
65
+ it 'does *NOT* confirm the user nor does the redirection' do
66
+ expect do
67
+ get_request
68
+ user.reload
69
+ end.not_to(change(user, :confirmed_at).from(nil))
38
70
 
39
- expect(response).to redirect_to "#{redirect}?account_confirmation_success=true"
40
- expect(user).to be_active_for_authentication
71
+ expect(response).not_to be_redirect
72
+ expect(json_response[:errors]).to contain_exactly(
73
+ hash_including(
74
+ message: 'Invalid confirmation token. Please try again',
75
+ extensions: { code: 'USER_ERROR' }
76
+ )
77
+ )
78
+ end
41
79
  end
42
80
  end
43
81
 
44
- context 'when reset password token is not found' do
45
- let(:token) { "#{user.confirmation_token}-invalid" }
82
+ context 'when using the admin model' do
83
+ let(:admin) { create(:admin, confirmed_at: nil) }
84
+ let(:redirect) { Faker::Internet.url }
85
+ let(:query) do
86
+ <<-GRAPHQL
87
+ {
88
+ adminConfirmAccount(
89
+ confirmationToken: "#{token}"
90
+ redirectUrl: "#{redirect}"
91
+ ) {
92
+ email
93
+ }
94
+ }
95
+ GRAPHQL
96
+ end
97
+
98
+ context 'when confirmation token is correct' do
99
+ let(:token) { admin.confirmation_token }
46
100
 
47
- it 'does *NOT* confirm the user nor does the redirection' do
48
- expect do
49
- get_request
50
- user.reload
51
- end.not_to(change(user, :confirmed_at).from(nil))
101
+ before do
102
+ admin.send_confirmation_instructions(
103
+ template_path: ['graphql_devise/mailer'],
104
+ controller: 'graphql_devise/graphql',
105
+ schema_url: 'http://not-using-this-value.com/gql'
106
+ )
107
+ end
52
108
 
53
- expect(response).not_to be_redirect
54
- expect(json_response[:errors]).to contain_exactly(
55
- hash_including(
56
- message: 'Invalid confirmation token. Please try again',
57
- extensions: { code: 'USER_ERROR' }
109
+ it 'confirms the resource, persists credentials on the DB and redirects to the sent url' do
110
+ expect do
111
+ get_request
112
+ admin.reload
113
+ end.to change(admin, :confirmed_at).from(nil).and(
114
+ change { admin.tokens.keys.count }.from(0).to(1)
58
115
  )
59
- )
116
+
117
+ expect(response).to redirect_to(/\A#{redirect}.+access\-token=/)
118
+ expect(admin).to be_active_for_authentication
119
+ end
60
120
  end
61
121
  end
62
122
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe "Integrations with the user's controller" do
@@ -34,7 +36,7 @@ RSpec.describe "Integrations with the user's controller" do
34
36
  it 'raises an invalid resource_name error' do
35
37
  expect { post_request('/api/v1/failing') }.to raise_error(
36
38
  GraphqlDevise::Error,
37
- 'Invalid resource_name `fail` provided to `graphql_context`. Possible values are: [:user, :admin, :guest, :users_customer].'
39
+ 'Invalid resource_name `fail` provided to `graphql_context`. Possible values are: [:user, :admin, :guest, :users_customer, :schema_user].'
38
40
  )
39
41
  end
40
42
  end
@@ -55,9 +57,17 @@ RSpec.describe "Integrations with the user's controller" do
55
57
  context 'when user is authenticated' do
56
58
  let(:headers) { user.create_new_auth_token }
57
59
 
58
- it 'allow to perform the query' do
60
+ it 'allows to perform the query' do
59
61
  expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
60
62
  end
63
+
64
+ context 'when using a SchemaUser' do
65
+ let(:headers) { create(:schema_user, :confirmed).create_new_auth_token }
66
+
67
+ it 'allows to perform the query' do
68
+ expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
69
+ end
70
+ end
61
71
  end
62
72
 
63
73
  context 'when user is not authenticated' do
@@ -75,7 +85,7 @@ RSpec.describe "Integrations with the user's controller" do
75
85
  context 'when user is authenticated' do
76
86
  let(:headers) { user.create_new_auth_token }
77
87
 
78
- it 'allow to perform the query' do
88
+ it 'allows to perform the query' do
79
89
  expect(json_response[:data][:privateField]).to eq('Field will always require authentication')
80
90
  end
81
91
  end
@@ -105,7 +115,7 @@ RSpec.describe "Integrations with the user's controller" do
105
115
  context 'when user is authenticated' do
106
116
  let(:headers) { user.create_new_auth_token }
107
117
 
108
- it 'allow to perform the query' do
118
+ it 'allows to perform the query' do
109
119
  expect(json_response[:data][:dummyMutation]).to eq('Necessary so GraphQL gem does not complain about empty mutation type')
110
120
  end
111
121
  end
@@ -125,7 +135,7 @@ RSpec.describe "Integrations with the user's controller" do
125
135
  context 'when user is authenticated' do
126
136
  let(:headers) { user.create_new_auth_token }
127
137
 
128
- it 'allow to perform the query' do
138
+ it 'allows to perform the query' do
129
139
  expect(json_response[:data][:dummyMutation]).to eq('Necessary so GraphQL gem does not complain about empty mutation type')
130
140
  end
131
141
  end
@@ -160,7 +170,7 @@ RSpec.describe "Integrations with the user's controller" do
160
170
  context 'when user is authenticated' do
161
171
  let(:headers) { user.create_new_auth_token }
162
172
 
163
- it 'allow to perform the query' do
173
+ it 'allows to perform the query' do
164
174
  expect(json_response[:data][:user]).to match(
165
175
  email: user.email,
166
176
  id: user.id
@@ -183,7 +193,7 @@ RSpec.describe "Integrations with the user's controller" do
183
193
  context 'when user is authenticated' do
184
194
  let(:headers) { user.create_new_auth_token }
185
195
 
186
- it 'allow to perform the query' do
196
+ it 'allows to perform the query' do
187
197
  expect(json_response[:data][:user]).to match(
188
198
  email: user.email,
189
199
  id: user.id
@@ -193,7 +203,7 @@ RSpec.describe "Integrations with the user's controller" do
193
203
 
194
204
  context 'when user is not authenticated' do
195
205
  # Interpreter schema fields are public unless specified otherwise (plugin setting)
196
- it 'allow to perform the query' do
206
+ it 'allows to perform the query' do
197
207
  expect(json_response[:data][:user]).to match(
198
208
  email: user.email,
199
209
  id: user.id
@@ -202,4 +212,43 @@ RSpec.describe "Integrations with the user's controller" do
202
212
  end
203
213
  end
204
214
  end
215
+
216
+ describe 'updateUser' do
217
+ let(:headers) { user.create_new_auth_token }
218
+ let(:query) do
219
+ <<-GRAPHQL
220
+ mutation {
221
+ updateUser(email: "updated@gmail.com", name: "updated name") {
222
+ user { email name }
223
+ }
224
+ }
225
+ GRAPHQL
226
+ end
227
+
228
+ it 'requires new email confirmation' do
229
+ original_email = user.email
230
+
231
+ expect do
232
+ post_request('/api/v1/graphql?test=value')
233
+ user.reload
234
+ end.to not_change(user, :email).from(original_email).and(
235
+ change(user, :unconfirmed_email).from(nil).to('updated@gmail.com')
236
+ ).and(
237
+ not_change(user, :uid).from(original_email)
238
+ ).and(
239
+ change(user, :name).from(user.name).to('updated name')
240
+ )
241
+
242
+ email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
243
+ link = email.css('a').first
244
+ expect(link['href']).to include('/api/v1/graphql')
245
+
246
+ expect do
247
+ get link['href']
248
+ user.reload
249
+ end.to change(user, :email).from(original_email).to('updated@gmail.com').and(
250
+ change(user, :uid).from(original_email).to('updated@gmail.com')
251
+ )
252
+ end
253
+ end
205
254
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::MountMethod::OperationPreparer do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::CustomOperationPreparer do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::DefaultOperationPreparer do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::GqlNameSetter do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::MutationFieldSetter do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::ResolverTypeSetter do