graphql_devise 0.12.0 → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +62 -1
- data/Gemfile +2 -0
- data/README.md +125 -82
- data/Rakefile +2 -0
- data/app/controllers/graphql_devise/application_controller.rb +2 -0
- data/app/controllers/graphql_devise/concerns/set_user_by_token.rb +12 -4
- data/app/controllers/graphql_devise/graphql_controller.rb +2 -0
- data/app/helpers/graphql_devise/application_helper.rb +2 -0
- data/app/helpers/graphql_devise/mailer_helper.rb +2 -0
- data/app/models/graphql_devise/concerns/model.rb +10 -0
- data/app/views/graphql_devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/graphql_devise/mailer/reset_password_instructions.html.erb +1 -1
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +2 -0
- data/graphql_devise.gemspec +4 -2
- data/lib/generators/graphql_devise/install_generator.rb +3 -1
- data/lib/graphql_devise.rb +10 -6
- data/lib/graphql_devise/concerns/controller_methods.rb +2 -0
- data/lib/graphql_devise/default_operations/mutations.rb +8 -6
- data/lib/graphql_devise/default_operations/resolvers.rb +4 -2
- data/lib/graphql_devise/engine.rb +2 -0
- data/lib/graphql_devise/errors/authentication_error.rb +9 -0
- data/lib/graphql_devise/{detailed_user_error.rb → errors/detailed_user_error.rb} +3 -1
- data/lib/graphql_devise/errors/error_codes.rb +8 -0
- data/lib/graphql_devise/errors/execution_error.rb +6 -0
- data/lib/graphql_devise/{user_error.rb → errors/user_error.rb} +3 -1
- data/lib/graphql_devise/model/with_email_updater.rb +74 -0
- data/lib/graphql_devise/mount_method/operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/custom_operation_preparer.rb +2 -0
- data/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb +8 -2
- data/lib/graphql_devise/mount_method/operation_preparers/gql_name_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb +5 -2
- data/lib/graphql_devise/mount_method/operation_preparers/resolver_type_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_preparers/resource_name_setter.rb +3 -1
- data/lib/graphql_devise/mount_method/operation_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizer.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/array_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/class_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/hash_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_sanitizers/string_checker.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/provided_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/skip_only_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/option_validators/supported_operations_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/options_validator.rb +2 -0
- data/lib/graphql_devise/mount_method/supported_options.rb +2 -0
- data/lib/graphql_devise/mutations/base.rb +2 -0
- data/lib/graphql_devise/mutations/login.rb +2 -0
- data/lib/graphql_devise/mutations/logout.rb +2 -0
- data/lib/graphql_devise/mutations/resend_confirmation.rb +5 -5
- data/lib/graphql_devise/mutations/send_password_reset.rb +7 -2
- data/lib/graphql_devise/mutations/sign_up.rb +13 -3
- data/lib/graphql_devise/mutations/update_password.rb +2 -0
- data/lib/graphql_devise/rails/routes.rb +2 -0
- data/lib/graphql_devise/resolvers/base.rb +2 -0
- data/lib/graphql_devise/resolvers/check_password_token.rb +2 -0
- data/lib/graphql_devise/resolvers/confirm_account.rb +4 -2
- data/lib/graphql_devise/resolvers/dummy.rb +2 -0
- data/lib/graphql_devise/resource_loader.rb +2 -0
- data/lib/graphql_devise/schema.rb +2 -0
- data/lib/graphql_devise/schema_plugin.rb +31 -4
- data/lib/graphql_devise/types/authenticatable_type.rb +2 -0
- data/lib/graphql_devise/types/credential_type.rb +2 -0
- data/lib/graphql_devise/types/mutation_type.rb +2 -0
- data/lib/graphql_devise/types/query_type.rb +2 -0
- data/lib/graphql_devise/version.rb +3 -1
- data/spec/dummy/Rakefile +2 -0
- data/spec/dummy/app/controllers/api/v1/graphql_controller.rb +35 -4
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/graphql/dummy_schema.rb +14 -2
- data/spec/dummy/app/graphql/interpreter_schema.rb +2 -0
- data/spec/dummy/app/graphql/mutations/login.rb +2 -0
- data/spec/dummy/app/graphql/mutations/register_confirmed_user.rb +2 -0
- data/spec/dummy/app/graphql/mutations/sign_up.rb +2 -0
- data/spec/dummy/app/graphql/mutations/update_user.rb +22 -0
- data/spec/dummy/app/graphql/resolvers/public_user.rb +2 -0
- data/spec/dummy/app/graphql/resolvers/user_show.rb +2 -0
- data/spec/dummy/app/graphql/types/base_object.rb +2 -0
- data/spec/dummy/app/graphql/types/custom_admin_type.rb +2 -0
- data/spec/dummy/app/graphql/types/mutation_type.rb +3 -0
- data/spec/dummy/app/graphql/types/query_type.rb +2 -0
- data/spec/dummy/app/graphql/types/user_type.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +2 -0
- data/spec/dummy/app/models/admin.rb +2 -0
- data/spec/dummy/app/models/application_record.rb +2 -0
- data/spec/dummy/app/models/guest.rb +2 -0
- data/spec/dummy/app/models/schema_user.rb +13 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/models/users.rb +2 -0
- data/spec/dummy/app/models/users/customer.rb +2 -0
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/environment.rb +2 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
- data/spec/dummy/config/initializers/cors.rb +2 -0
- data/spec/dummy/config/initializers/devise_token_auth.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/i18n.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/puma.rb +2 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/spring.rb +2 -0
- data/spec/dummy/db/migrate/20190815114303_create_users.rb +2 -0
- data/spec/dummy/db/migrate/20190824215150_add_auth_available_to_users.rb +2 -0
- data/spec/dummy/db/migrate/20190916012505_create_admins.rb +2 -0
- data/spec/dummy/db/migrate/20191013213045_create_guests.rb +2 -0
- data/spec/dummy/db/migrate/20200321121807_create_users_customers.rb +2 -0
- data/spec/dummy/db/migrate/20200621182414_remove_uncofirmed_email_from_admins.rb +7 -0
- data/spec/dummy/db/migrate/20200623003142_create_schema_users.rb +46 -0
- data/spec/dummy/db/schema.rb +30 -2
- data/spec/dummy/db/seeds.rb +2 -0
- data/spec/factories/admins.rb +2 -0
- data/spec/factories/guests.rb +2 -0
- data/spec/factories/schema_users.rb +13 -0
- data/spec/factories/users.rb +2 -0
- data/spec/factories/users_customers.rb +2 -0
- data/spec/generators/graphql_devise/install_generator_spec.rb +3 -1
- data/spec/graphql_devise/model/with_email_updater_spec.rb +131 -0
- data/spec/graphql_devise_spec.rb +2 -0
- data/spec/models/user_spec.rb +2 -0
- data/spec/rails_helper.rb +3 -0
- data/spec/requests/graphql_controller_spec.rb +2 -0
- data/spec/requests/mutations/additional_mutations_spec.rb +2 -0
- data/spec/requests/mutations/additional_queries_spec.rb +2 -0
- data/spec/requests/mutations/login_spec.rb +2 -0
- data/spec/requests/mutations/logout_spec.rb +2 -0
- data/spec/requests/mutations/resend_confirmation_spec.rb +46 -29
- data/spec/requests/mutations/send_password_reset_spec.rb +42 -12
- data/spec/requests/mutations/sign_up_spec.rb +15 -2
- data/spec/requests/mutations/update_password_spec.rb +2 -0
- data/spec/requests/queries/check_password_token_spec.rb +2 -0
- data/spec/requests/queries/confirm_account_spec.rb +9 -1
- data/spec/requests/user_controller_spec.rb +70 -12
- data/spec/services/mount_method/operation_preparer_spec.rb +8 -1
- data/spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb +16 -7
- data/spec/services/mount_method/operation_preparers/gql_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb +20 -4
- data/spec/services/mount_method/operation_preparers/resolver_type_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_preparers/resource_name_setter_spec.rb +2 -0
- data/spec/services/mount_method/operation_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizer_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/array_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/class_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/hash_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_sanitizers/string_checker_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/provided_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/skip_only_validator_spec.rb +2 -0
- data/spec/services/mount_method/option_validators/supported_operations_validator_spec.rb +2 -0
- data/spec/services/mount_method/options_validator_spec.rb +2 -0
- data/spec/services/resource_loader_spec.rb +2 -0
- data/spec/services/schema_plugin_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/contexts/graphql_request.rb +2 -0
- data/spec/support/factory_bot.rb +2 -0
- data/spec/support/matchers/auth_headers_matcher.rb +2 -0
- data/spec/support/matchers/not_change_matcher.rb +2 -0
- data/spec/support/requests/auth_helpers.rb +2 -0
- data/spec/support/requests/json_helpers.rb +2 -0
- metadata +94 -87
- data/lib/graphql_devise/error_codes.rb +0 -5
data/spec/dummy/db/seeds.rb
CHANGED
data/spec/factories/admins.rb
CHANGED
data/spec/factories/guests.rb
CHANGED
@@ -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
|
data/spec/factories/users.rb
CHANGED
@@ -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: '
|
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
|
data/spec/graphql_devise_spec.rb
CHANGED
data/spec/models/user_spec.rb
CHANGED
data/spec/rails_helper.rb
CHANGED
@@ -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 '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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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:
|
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
|
-
|
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
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
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 '
|
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
|