graphql_devise 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -0
  3. data/Appraisals +14 -0
  4. data/CHANGELOG.md +62 -1
  5. data/Gemfile +2 -0
  6. data/README.md +125 -82
  7. data/Rakefile +2 -0
  8. data/app/controllers/graphql_devise/application_controller.rb +2 -0
  9. data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +12 -4
  10. data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
  11. data/app/helpers/graphql_devise/application_helper.rb +2 -0
  12. data/app/helpers/graphql_devise/mailer_helper.rb +2 -0
  13. data/app/models/graphql_devise/concerns/model.rb +10 -0
  14. data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
  15. data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
  16. data/config/locales/en.yml +1 -0
  17. data/config/routes.rb +2 -0
  18. data/graphql_devise.gemspec +4 -2
  19. data/lib/generators/graphql_devise/install_generator.rb +3 -1
  20. data/lib/graphql_devise.rb +10 -6
  21. data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
  22. data/lib/graphql_devise/default_operations/mutations.rb +8 -6
  23. data/lib/graphql_devise/default_operations/resolvers.rb +4 -2
  24. data/lib/graphql_devise/engine.rb +2 -0
  25. data/lib/graphql_devise/errors/authentication_error.rb +9 -0
  26. data/lib/graphql_devise/{detailed_user_error.rb → errors/detailed_user_error.rb} +3 -1
  27. data/lib/graphql_devise/errors/error_codes.rb +8 -0
  28. data/lib/graphql_devise/errors/execution_error.rb +6 -0
  29. data/lib/graphql_devise/{user_error.rb → errors/user_error.rb} +3 -1
  30. data/lib/graphql_devise/model/with_email_updater.rb +74 -0
  31. data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -0
  32. data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
  33. data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +8 -2
  34. data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +3 -1
  35. data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +5 -2
  36. data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +3 -1
  37. data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +3 -1
  38. data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
  39. data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
  40. data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
  41. data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
  42. data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
  43. data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
  44. data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
  45. data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
  46. data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
  47. data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
  48. data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
  49. data/lib/graphql_devise/mutations/base.rb +2 -0
  50. data/lib/graphql_devise/mutations/login.rb +2 -0
  51. data/lib/graphql_devise/mutations/logout.rb +2 -0
  52. data/lib/graphql_devise/mutations/resend_confirmation.rb +5 -5
  53. data/lib/graphql_devise/mutations/send_password_reset.rb +7 -2
  54. data/lib/graphql_devise/mutations/sign_up.rb +13 -3
  55. data/lib/graphql_devise/mutations/update_password.rb +2 -0
  56. data/lib/graphql_devise/rails/routes.rb +2 -0
  57. data/lib/graphql_devise/resolvers/base.rb +2 -0
  58. data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
  59. data/lib/graphql_devise/resolvers/confirm_account.rb +4 -2
  60. data/lib/graphql_devise/resolvers/dummy.rb +2 -0
  61. data/lib/graphql_devise/resource_loader.rb +2 -0
  62. data/lib/graphql_devise/schema.rb +2 -0
  63. data/lib/graphql_devise/schema_plugin.rb +31 -4
  64. data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
  65. data/lib/graphql_devise/types/credential_type.rb +2 -0
  66. data/lib/graphql_devise/types/mutation_type.rb +2 -0
  67. data/lib/graphql_devise/types/query_type.rb +2 -0
  68. data/lib/graphql_devise/version.rb +3 -1
  69. data/spec/dummy/Rakefile +2 -0
  70. data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +35 -4
  71. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  72. data/spec/dummy/app/graphql/dummy_schema.rb +14 -2
  73. data/spec/dummy/app/graphql/interpreter_schema.rb +2 -0
  74. data/spec/dummy/app/graphql/mutations/login.rb +2 -0
  75. data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
  76. data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
  77. data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
  78. data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
  79. data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
  80. data/spec/dummy/app/graphql/types/base_object.rb +2 -0
  81. data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
  82. data/spec/dummy/app/graphql/types/mutation_type.rb +3 -0
  83. data/spec/dummy/app/graphql/types/query_type.rb +2 -0
  84. data/spec/dummy/app/graphql/types/user_type.rb +2 -0
  85. data/spec/dummy/app/jobs/application_job.rb +2 -0
  86. data/spec/dummy/app/mailers/application_mailer.rb +2 -0
  87. data/spec/dummy/app/models/admin.rb +2 -0
  88. data/spec/dummy/app/models/application_record.rb +2 -0
  89. data/spec/dummy/app/models/guest.rb +2 -0
  90. data/spec/dummy/app/models/schema_user.rb +13 -0
  91. data/spec/dummy/app/models/user.rb +2 -0
  92. data/spec/dummy/app/models/users.rb +2 -0
  93. data/spec/dummy/app/models/users/customer.rb +2 -0
  94. data/spec/dummy/config.ru +2 -0
  95. data/spec/dummy/config/application.rb +2 -0
  96. data/spec/dummy/config/environment.rb +2 -0
  97. data/spec/dummy/config/environments/development.rb +2 -0
  98. data/spec/dummy/config/environments/production.rb +2 -0
  99. data/spec/dummy/config/environments/test.rb +2 -0
  100. data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
  101. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  102. data/spec/dummy/config/initializers/cors.rb +2 -0
  103. data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
  104. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  105. data/spec/dummy/config/initializers/i18n.rb +2 -0
  106. data/spec/dummy/config/initializers/inflections.rb +2 -0
  107. data/spec/dummy/config/initializers/mime_types.rb +2 -0
  108. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  109. data/spec/dummy/config/puma.rb +2 -0
  110. data/spec/dummy/config/routes.rb +4 -0
  111. data/spec/dummy/config/spring.rb +2 -0
  112. data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
  113. data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
  114. data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
  115. data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
  116. data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
  117. data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
  118. data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
  119. data/spec/dummy/db/schema.rb +30 -2
  120. data/spec/dummy/db/seeds.rb +2 -0
  121. data/spec/factories/admins.rb +2 -0
  122. data/spec/factories/guests.rb +2 -0
  123. data/spec/factories/schema_users.rb +13 -0
  124. data/spec/factories/users.rb +2 -0
  125. data/spec/factories/users_customers.rb +2 -0
  126. data/spec/generators/graphql_devise/install_generator_spec.rb +3 -1
  127. data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
  128. data/spec/graphql_devise_spec.rb +2 -0
  129. data/spec/models/user_spec.rb +2 -0
  130. data/spec/rails_helper.rb +3 -0
  131. data/spec/requests/graphql_controller_spec.rb +2 -0
  132. data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
  133. data/spec/requests/mutations/additional_queries_spec.rb +2 -0
  134. data/spec/requests/mutations/login_spec.rb +2 -0
  135. data/spec/requests/mutations/logout_spec.rb +2 -0
  136. data/spec/requests/mutations/resend_confirmation_spec.rb +46 -29
  137. data/spec/requests/mutations/send_password_reset_spec.rb +42 -12
  138. data/spec/requests/mutations/sign_up_spec.rb +15 -2
  139. data/spec/requests/mutations/update_password_spec.rb +2 -0
  140. data/spec/requests/queries/check_password_token_spec.rb +2 -0
  141. data/spec/requests/queries/confirm_account_spec.rb +9 -1
  142. data/spec/requests/user_controller_spec.rb +70 -12
  143. data/spec/services/mount_method/operation_preparer_spec.rb +8 -1
  144. data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +2 -0
  145. data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +16 -7
  146. data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
  147. data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +20 -4
  148. data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
  149. data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +2 -0
  150. data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
  151. data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
  152. data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
  153. data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
  154. data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
  155. data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
  156. data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
  157. data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
  158. data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
  159. data/spec/services/mount_method/options_validator_spec.rb +2 -0
  160. data/spec/services/resource_loader_spec.rb +2 -0
  161. data/spec/services/schema_plugin_spec.rb +2 -0
  162. data/spec/spec_helper.rb +2 -0
  163. data/spec/support/contexts/graphql_request.rb +2 -0
  164. data/spec/support/factory_bot.rb +2 -0
  165. data/spec/support/matchers/auth_headers_matcher.rb +2 -0
  166. data/spec/support/matchers/not_change_matcher.rb +2 -0
  167. data/spec/support/requests/auth_helpers.rb +2 -0
  168. data/spec/support/requests/json_helpers.rb +2 -0
  169. metadata +94 -87
  170. data/lib/graphql_devise/error_codes.rb +0 -5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file should contain all the record creation needed to seed the database with its default values.
2
4
  # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :admin do
3
5
  email { Faker::Internet.unique.email }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :guest do
3
5
  email { Faker::Internet.unique.email }
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :schema_user do
5
+ name { Faker::FunnyName.two_word_name }
6
+ email { Faker::Internet.unique.email }
7
+ password { Faker::Internet.password }
8
+
9
+ trait :confirmed do
10
+ confirmed_at { Time.zone.now }
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :user do
3
5
  name { Faker::FunnyName.two_word_name }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :users_customer, class: 'Users::Customer' do
3
5
  name { Faker::FunnyName.two_word_name }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Generators are not automatically loaded by Rails
2
4
  require 'rails_helper'
3
5
  require 'generators/graphql_devise/install_generator'
@@ -39,7 +41,7 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
39
41
  let(:args) { [] }
40
42
 
41
43
  it 'creates and updated required files' do
42
- assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'auth'/
44
+ assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'graphql_auth'/
43
45
  expect(routes_content).not_to match(dta_route)
44
46
 
45
47
  assert_file 'config/initializers/devise.rb'
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe GraphqlDevise::Model::WithEmailUpdater do
6
+ describe '#call' do
7
+ subject(:updater) { described_class.new(resource, attributes).call }
8
+
9
+ context 'when the model does not have an unconfirmed_email column' do
10
+ let(:resource) { create(:admin, :confirmed) }
11
+
12
+ context 'when attributes contain email' do
13
+ let(:attributes) { { email: 'new@gmail.com', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
14
+
15
+ it 'does not postpone email update' do
16
+ expect do
17
+ updater
18
+ resource.reload
19
+ end.to change(resource, :email).from(resource.email).to('new@gmail.com').and(
20
+ change(resource, :uid).from(resource.uid).to('new@gmail.com')
21
+ )
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'when the model has an unconfirmed_email column' do
27
+ let(:resource) { create(:user, :confirmed) }
28
+
29
+ context 'when attributes do not contain email' do
30
+ let(:attributes) { { name: 'Updated Name', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
31
+
32
+ it 'updates resource, ignores url params' do
33
+ expect do
34
+ updater
35
+ resource.reload
36
+ end.to change(resource, :name).from(resource.name).to('Updated Name')
37
+ end
38
+ end
39
+
40
+ context 'when attributes contain email' do
41
+ context 'when schema_url is missing' do
42
+ let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name' } }
43
+
44
+ it 'raises an error' do
45
+ expect { updater }.to raise_error(
46
+ GraphqlDevise::Error,
47
+ 'Method `update_with_email` requires attributes `confirmation_success_url` and `schema_url` for email reconfirmation to work'
48
+ )
49
+ end
50
+
51
+ context 'when email will not change' do
52
+ let(:attributes) { { email: resource.email, name: 'changed' } }
53
+
54
+ it 'updates name and does not raise an error' do
55
+ expect do
56
+ updater
57
+ resource.reload
58
+ end.to change(resource, :name).from(resource.name).to('changed').and(
59
+ not_change(resource, :email).from(resource.email)
60
+ ).and(
61
+ not_change(ActionMailer::Base.deliveries, :count).from(0)
62
+ )
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'when only confirmation_success_url is missing' do
68
+ let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name', schema_url: 'http://localhost/test' } }
69
+
70
+ it 'uses DTA default_confirm_success_url on the email' do
71
+ expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
72
+
73
+ email = ActionMailer::Base.deliveries.first
74
+ expect(email.body.decoded).to include(CGI.escape('https://google.com'))
75
+ end
76
+ end
77
+
78
+ context 'when both required urls are provided' do
79
+ let(:attributes) { { email: 'new@gmail.com', name: 'Updated Name', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
80
+
81
+ it 'postpones email update' do
82
+ expect do
83
+ updater
84
+ resource.reload
85
+ end.to not_change(resource, :email).from(resource.email).and(
86
+ not_change(resource, :uid).from(resource.uid)
87
+ ).and(
88
+ change(resource, :unconfirmed_email).from(nil).to('new@gmail.com')
89
+ ).and(
90
+ change(resource, :name).from(resource.name).to('Updated Name')
91
+ )
92
+ end
93
+
94
+ it 'sends out a confirmation email to the unconfirmed_email' do
95
+ expect { updater }.to change(ActionMailer::Base.deliveries, :count).by(1)
96
+
97
+ email = ActionMailer::Base.deliveries.first
98
+ expect(email.to).to contain_exactly('new@gmail.com')
99
+ end
100
+
101
+ context 'when email value is the same on the DB' do
102
+ let(:attributes) { { email: resource.email, name: 'changed', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
103
+
104
+ it 'updates attributes and does not send confirmation email' do
105
+ expect do
106
+ updater
107
+ resource.reload
108
+ end.to change(resource, :name).from(resource.name).to('changed').and(
109
+ not_change(resource, :email).from(resource.email)
110
+ ).and(
111
+ not_change(ActionMailer::Base.deliveries, :count).from(0)
112
+ )
113
+ end
114
+ end
115
+
116
+ context 'when provided params are invalid' do
117
+ let(:attributes) { { email: 'newgmail.com', name: '', schema_url: 'http://localhost/test', confirmation_success_url: 'https://google.com' } }
118
+
119
+ it 'returns false and adds errors to the model' do
120
+ expect(updater).to be_falsey
121
+ expect(resource.errors.full_messages).to contain_exactly(
122
+ 'Email is not an email',
123
+ "Name can't be blank"
124
+ )
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe GraphqlDevise do
2
4
  it 'has a version number' do
3
5
  expect(GraphqlDevise::VERSION).not_to be_nil
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe User do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  ENV['RAILS_ENV'] ||= 'test'
@@ -42,4 +44,5 @@ RSpec.configure do |config|
42
44
  config.before(:suite) do
43
45
  ActionController::Base.allow_forgery_protection = true
44
46
  end
47
+ config.before { ActionMailer::Base.deliveries.clear }
45
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe GraphqlDevise::GraphqlController do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Additional Mutations' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Additional Queries' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Login Requests' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Logout Requests' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'Resend confirmation' do
@@ -15,39 +17,58 @@ RSpec.describe 'Resend confirmation' do
15
17
  redirectUrl:"#{redirect}"
16
18
  ) {
17
19
  message
18
- authenticatable {
19
- id
20
- email
21
- }
22
20
  }
23
21
  }
24
22
  GRAPHQL
25
23
  end
26
24
 
27
25
  context 'when params are correct' do
28
- it 'sends an email to the user with confirmation url and returns a success message' do
29
- expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
30
- expect(json_response[:data][:userResendConfirmation]).to include(
31
- message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.',
32
- authenticatable: {
33
- id: id,
34
- email: email
35
- }
36
- )
26
+ context 'when using the gem schema' do
27
+ it 'sends an email to the user with confirmation url and returns a success message' do
28
+ expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
29
+ expect(json_response[:data][:userResendConfirmation]).to include(
30
+ message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
31
+ )
32
+
33
+ email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
34
+ link = email.css('a').first
35
+ confirm_link_msg_text = email.css('p')[1].inner_html
36
+ confirm_account_link_text = link.inner_html
37
+
38
+ expect(link['href']).to include('/api/v1/graphql_auth?')
39
+ expect(confirm_link_msg_text).to eq('You can confirm your account email through the link below:')
40
+ expect(confirm_account_link_text).to eq('Confirm my account')
37
41
 
38
- email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
39
- link = email.css('a').first
40
- confirm_link_msg_text = email.css('p')[1].inner_html
41
- confirm_account_link_text = link.inner_html
42
+ expect do
43
+ get link['href']
44
+ user.reload
45
+ end.to change(user, :confirmed_at).from(NilClass).to(ActiveSupport::TimeWithZone)
46
+ end
47
+ end
48
+
49
+ context 'when using a custom schema' do
50
+ let(:custom_path) { '/api/v1/graphql' }
51
+
52
+ it 'sends an email to the user with confirmation url and returns a success message' do
53
+ expect { post_request(custom_path) }.to change(ActionMailer::Base.deliveries, :count).by(1)
54
+ expect(json_response[:data][:userResendConfirmation]).to include(
55
+ message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
56
+ )
42
57
 
43
- expect(confirm_link_msg_text).to eq('You can confirm your account email through the link below:')
44
- expect(confirm_account_link_text).to eq('Confirm my account')
58
+ email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
59
+ link = email.css('a').first
60
+ confirm_link_msg_text = email.css('p')[1].inner_html
61
+ confirm_account_link_text = link.inner_html
45
62
 
46
- # TODO: Move to feature spec
47
- expect do
48
- get link['href']
49
- user.reload
50
- end.to change(user, :confirmed_at).from(NilClass).to(ActiveSupport::TimeWithZone)
63
+ expect(link['href']).to include("#{custom_path}?")
64
+ expect(confirm_link_msg_text).to eq('You can confirm your account email through the link below:')
65
+ expect(confirm_account_link_text).to eq('Confirm my account')
66
+
67
+ expect do
68
+ get link['href']
69
+ user.reload
70
+ end.to change(user, :confirmed_at).from(NilClass).to(ActiveSupport::TimeWithZone)
71
+ end
51
72
  end
52
73
 
53
74
  context 'when email address uses different casing' do
@@ -56,11 +77,7 @@ RSpec.describe 'Resend confirmation' do
56
77
  it 'honors devise configuration for case insensitive fields' do
57
78
  expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
58
79
  expect(json_response[:data][:userResendConfirmation]).to include(
59
- message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.',
60
- authenticatable: {
61
- id: id,
62
- email: user.email
63
- }
80
+ message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
64
81
  )
65
82
  end
66
83
  end
@@ -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
@@ -13,26 +15,51 @@ RSpec.describe 'Send Password Reset Requests' do
13
15
  email: "#{email}",
14
16
  redirectUrl: "#{redirect_url}"
15
17
  ) {
16
- authenticatable {
17
- email
18
- }
18
+ message
19
19
  }
20
20
  }
21
21
  GRAPHQL
22
22
  end
23
23
 
24
24
  context 'when params are correct' do
25
- it 'sends password reset email' do
26
- expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
25
+ context 'when using the gem schema' do
26
+ it 'sends password reset email' do
27
+ expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
28
+
29
+ expect(json_response[:data][:userSendPasswordReset]).to include(
30
+ message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
31
+ )
32
+
33
+ email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
34
+ link = email.css('a').first
35
+ expect(link['href']).to include('/api/v1/graphql_auth?')
36
+
37
+ expect do
38
+ get link['href']
39
+ user.reload
40
+ end.to change(user, :allow_password_change).from(false).to(true)
41
+ end
42
+ end
43
+
44
+ context 'when using a custom schema' do
45
+ let(:custom_path) { '/api/v1/graphql' }
46
+
47
+ it 'sends password reset email' do
48
+ expect { post_request(custom_path) }.to change(ActionMailer::Base.deliveries, :count).by(1)
27
49
 
28
- email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
29
- link = email.css('a').first
50
+ expect(json_response[:data][:userSendPasswordReset]).to include(
51
+ message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
52
+ )
30
53
 
31
- # TODO: Move to feature spec
32
- expect do
33
- get link['href']
34
- user.reload
35
- end.to change(user, :allow_password_change).from(false).to(true)
54
+ email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
55
+ link = email.css('a').first
56
+ expect(link['href']).to include("#{custom_path}?")
57
+
58
+ expect do
59
+ get link['href']
60
+ user.reload
61
+ end.to change(user, :allow_password_change).from(false).to(true)
62
+ end
36
63
  end
37
64
  end
38
65
 
@@ -41,6 +68,9 @@ RSpec.describe 'Send Password Reset Requests' do
41
68
 
42
69
  it 'honors devise configuration for case insensitive fields' do
43
70
  expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
71
+ expect(json_response[:data][:userSendPasswordReset]).to include(
72
+ message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
73
+ )
44
74
  end
45
75
  end
46
76
 
@@ -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