Skip to content

Commit 8c62e0f

Browse files
author
David Revelo
committed
Apply code review suggestions
1 parent af0af51 commit 8c62e0f

9 files changed

Lines changed: 28 additions & 43 deletions

File tree

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ en:
1414
password_not_required: "This account does not require a password. Sign in using your '%{provider}' account instead."
1515
reset_token_not_found: "No user found for the specified reset token."
1616
reset_token_expired: "Reset password token is no longer valid."
17+
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
1718
sessions:
1819
bad_credentials: "Invalid login credentials. Please try again."
1920
not_confirmed: "A confirmation email was sent to your account at '%{email}'. You must follow the instructions in the email before your account can be activated"

lib/graphql_devise/default_operations/mutations.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
module GraphqlDevise
1010
module DefaultOperations
1111
MUTATIONS = {
12-
login: { klass: GraphqlDevise::Mutations::Login, authenticable: true },
13-
logout: { klass: GraphqlDevise::Mutations::Logout, authenticable: true },
14-
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticable: true },
15-
update_password: { klass: GraphqlDevise::Mutations::UpdatePassword, authenticable: true },
16-
send_password_reset: { klass: GraphqlDevise::Mutations::SendPasswordReset, authenticable: true },
17-
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticable: true }
18-
12+
login: { klass: GraphqlDevise::Mutations::Login, authenticatable: true },
13+
logout: { klass: GraphqlDevise::Mutations::Logout, authenticatable: true },
14+
sign_up: { klass: GraphqlDevise::Mutations::SignUp, authenticatable: true },
15+
update_password: { klass: GraphqlDevise::Mutations::UpdatePassword, authenticatable: true },
16+
send_password_reset: { klass: GraphqlDevise::Mutations::SendPasswordReset, authenticatable: false },
17+
resend_confirmation: { klass: GraphqlDevise::Mutations::ResendConfirmation, authenticatable: false }
1918
}.freeze
2019
end
2120
end

lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ def initialize(authenticatable_type)
66
@authenticatable_type = authenticatable_type
77
end
88

9-
def call(mutation, authenticable: true)
10-
return unless authenticable
9+
def call(mutation, authenticatable: true)
10+
return mutation unless authenticatable
1111

1212
mutation.field(:authenticatable, @authenticatable_type, null: false)
1313
mutation

lib/graphql_devise/mutations/resend_confirmation.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ def resolve(email:, redirect_url:)
2222
template_path: ['graphql_devise/mailer']
2323
)
2424

25-
{
26-
authenticatable: resource,
27-
message: I18n.t('graphql_devise.confirmations.send_instructions', email: email)
28-
}
25+
{ message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) }
2926
else
3027
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email))
3128
end

lib/graphql_devise/mutations/send_password_reset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def resolve(email:, redirect_url:)
2020
)
2121

2222
if resource.errors.empty?
23-
{ message: I18n.t('devise.passwords.send_instructions') }
23+
{ message: I18n.t('graphql_devise.passwords.send_instructions') }
2424
else
2525
raise_user_error_list(I18n.t('graphql_devise.invalid_resource'), errors: resource.errors.full_messages)
2626
end

spec/requests/mutations/resend_confirmation_spec.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
redirectUrl:"#{redirect}"
1616
) {
1717
message
18-
authenticatable {
19-
id
20-
email
21-
}
2218
}
2319
}
2420
GRAPHQL
@@ -28,11 +24,7 @@
2824
it 'sends an email to the user with confirmation url and returns a success message' do
2925
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
3026
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-
}
27+
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
3628
)
3729

3830
email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
@@ -56,11 +48,7 @@
5648
it 'honors devise configuration for case insensitive fields' do
5749
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
5850
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-
}
51+
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
6452
)
6553
end
6654
end

spec/requests/mutations/send_password_reset_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
it 'sends password reset email' do
2424
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
2525

26-
expect(json_response.dig(:data, :userSendPasswordReset)).to include(
26+
expect(json_response[:data][:userSendPasswordReset]).to include(
2727
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
2828
)
2929

@@ -43,7 +43,7 @@
4343

4444
it 'honors devise configuration for case insensitive fields' do
4545
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
46-
expect(json_response.dig(:data, :userSendPasswordReset)).to include(
46+
expect(json_response[:data][:userSendPasswordReset]).to include(
4747
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
4848
)
4949
end

spec/services/mount_method/operation_preparers/default_operation_preparer_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
let(:custom_keys) { [:login, :logout] }
1515
let(:operations) do
1616
{
17-
confirm: { klass: confirm_operation, authenticable: false },
18-
sign_up: { klass: sign_up_operation, authenticable: true },
19-
login: { klass: login_operation, authenticable: true },
20-
logout: { klass: logout_operation, authenticable: true }
17+
confirm: { klass: confirm_operation, authenticatable: false },
18+
sign_up: { klass: sign_up_operation, authenticatable: true },
19+
login: { klass: login_operation, authenticatable: true },
20+
logout: { klass: logout_operation, authenticatable: true }
2121
}
2222
end
2323

@@ -26,10 +26,10 @@
2626
allow(default_preparer).to receive(:child_class).with(sign_up_operation).and_return(sign_up_operation)
2727
allow(default_preparer).to receive(:child_class).with(login_operation).and_return(login_operation)
2828
allow(default_preparer).to receive(:child_class).with(logout_operation).and_return(logout_operation)
29-
allow(preparer).to receive(:call).with(confirm_operation, authenticable: false).and_return(confirm_operation)
30-
allow(preparer).to receive(:call).with(sign_up_operation, authenticable: true).and_return(sign_up_operation)
31-
allow(preparer).to receive(:call).with(login_operation, authenticable: true).and_return(login_operation)
32-
allow(preparer).to receive(:call).with(logout_operation, authenticable: true).and_return(logout_operation)
29+
allow(preparer).to receive(:call).with(confirm_operation, authenticatable: false).and_return(confirm_operation)
30+
allow(preparer).to receive(:call).with(sign_up_operation, authenticatable: true).and_return(sign_up_operation)
31+
allow(preparer).to receive(:call).with(login_operation, authenticatable: true).and_return(login_operation)
32+
allow(preparer).to receive(:call).with(logout_operation, authenticatable: true).and_return(logout_operation)
3333
end
3434

3535
it 'returns only those operations with no custom operation provided' do
@@ -39,8 +39,8 @@
3939
it 'prepares default operations' do
4040
expect(confirm_operation).to receive(:graphql_name).with('UserConfirm')
4141
expect(sign_up_operation).to receive(:graphql_name).with('UserSignUp')
42-
expect(preparer).to receive(:call).with(confirm_operation, authenticable: false)
43-
expect(preparer).to receive(:call).with(sign_up_operation, authenticable: true)
42+
expect(preparer).to receive(:call).with(confirm_operation, authenticatable: false)
43+
expect(preparer).to receive(:call).with(sign_up_operation, authenticatable: true)
4444

4545
prepared
4646

spec/services/mount_method/operation_preparers/mutation_field_setter_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::MutationFieldSetter do
44
describe '#call' do
5-
subject(:prepared_operation) { described_class.new(field_type).call(operation, authenticable: authenticable) }
5+
subject(:prepared_operation) { described_class.new(field_type).call(operation, authenticatable: authenticatable) }
66

77
let(:operation) { double(:operation) }
88
let(:field_type) { double(:type) }
99

1010
context 'when resource is authtenticable' do
11-
let(:authenticable) { true }
11+
let(:authenticatable) { true }
1212

1313
it 'sets a field for the mutation' do
1414
expect(operation).to receive(:field).with(:authenticatable, field_type, null: false)
@@ -18,7 +18,7 @@
1818
end
1919

2020
context 'when resource is *NOT* authtenticable' do
21-
let(:authenticable) { false }
21+
let(:authenticatable) { false }
2222

2323
it 'does *NOT* set a field for the mutation' do
2424
expect(operation).not_to receive(:field)

0 commit comments

Comments
 (0)