Skip to content

Commit

Permalink
Add changes for confirmation email
Browse files Browse the repository at this point in the history
  • Loading branch information
David Revelo committed Jun 17, 2020
1 parent 7aebf5f commit b1a0d30
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

<p><%= t('.confirm_link_msg') %></p>

<p><%= link_to t('.confirm_account_link'), url_for(controller: 'graphql_devise/graphql', action: :auth, **confirmation_query(resource_name: @resource.class.to_s, redirect_url: message['redirect-url'], token: @token)) %></p>
<p><%= link_to t('.confirm_account_link'), url_for(controller: message['controller'], action: message['action'], **confirmation_query(resource_name: @resource.class.to_s, redirect_url: message['redirect-url'], token: @token)) %></p>
3 changes: 2 additions & 1 deletion lib/graphql_devise/mutations/resend_confirmation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def resolve(email:, redirect_url:)

resource.send_confirmation_instructions(
redirect_url: redirect_url,
template_path: ['graphql_devise/mailer']
template_path: ['graphql_devise/mailer'],
**controller.params.permit('controller', 'action').to_h.symbolize_keys
)

{ message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) }
Expand Down
3 changes: 2 additions & 1 deletion lib/graphql_devise/mutations/sign_up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def resolve(confirm_success_url: nil, **attrs)
unless resource.confirmed?
resource.send_confirmation_instructions(
redirect_url: confirm_success_url,
template_path: ['graphql_devise/mailer']
template_path: ['graphql_devise/mailer'],
**controller.params.permit('controller', 'action').to_h.symbolize_keys
)
end

Expand Down
8 changes: 7 additions & 1 deletion spec/dummy/app/graphql/dummy_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ class DummySchema < GraphQL::Schema
resource_loaders: [
GraphqlDevise::ResourceLoader.new(
'User',
only: [:login, :confirm_account, :send_password_reset, :check_password_token]
only: [
:login,
:confirm_account,
:send_password_reset,
:resend_confirmation,
:check_password_token
]
),
GraphqlDevise::ResourceLoader.new('Guest', only: [:logout])
]
Expand Down
59 changes: 43 additions & 16 deletions spec/requests/mutations/resend_confirmation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,52 @@
end

context 'when params are correct' do
it 'sends an email to the user with confirmation url and returns a success message' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(json_response[:data][:userResendConfirmation]).to include(
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
)
context 'when using the gem schema' do
it 'sends an email to the user with confirmation url and returns a success message' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(json_response[:data][:userResendConfirmation]).to include(
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
)

email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
confirm_link_msg_text = email.css('p')[1].inner_html
confirm_account_link_text = link.inner_html

expect(link['href']).to include('/api/v1/graphql_auth?')
expect(confirm_link_msg_text).to eq('You can confirm your account email through the link below:')
expect(confirm_account_link_text).to eq('Confirm my account')

expect do
get link['href']
user.reload
end.to change(user, :confirmed_at).from(NilClass).to(ActiveSupport::TimeWithZone)
end
end

context 'when using a custom schema' do
let(:custom_path) { '/api/v1/graphql' }

it 'sends an email to the user with confirmation url and returns a success message' do
expect { post_request(custom_path) }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(json_response[:data][:userResendConfirmation]).to include(
message: 'You will receive an email with instructions for how to confirm your email address in a few minutes.'
)

email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
confirm_link_msg_text = email.css('p')[1].inner_html
confirm_account_link_text = link.inner_html
email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
confirm_link_msg_text = email.css('p')[1].inner_html
confirm_account_link_text = link.inner_html

expect(confirm_link_msg_text).to eq('You can confirm your account email through the link below:')
expect(confirm_account_link_text).to eq('Confirm my account')
expect(link['href']).to include("#{custom_path}?")
expect(confirm_link_msg_text).to eq('You can confirm your account email through the link below:')
expect(confirm_account_link_text).to eq('Confirm my account')

# TODO: Move to feature spec
expect do
get link['href']
user.reload
end.to change(user, :confirmed_at).from(NilClass).to(ActiveSupport::TimeWithZone)
expect do
get link['href']
user.reload
end.to change(user, :confirmed_at).from(NilClass).to(ActiveSupport::TimeWithZone)
end
end

context 'when email address uses different casing' do
Expand Down
4 changes: 1 addition & 3 deletions spec/requests/mutations/send_password_reset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

context 'when params are correct' do
context 'when using gem' do
context 'when using the gem schema' do
it 'sends password reset email' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)

Expand All @@ -32,7 +32,6 @@
link = email.css('a').first
expect(link['href']).to include('/api/v1/graphql_auth?')

# TODO: Move to feature spec
expect do
get link['href']
user.reload
Expand All @@ -54,7 +53,6 @@
link = email.css('a').first
expect(link['href']).to include("#{custom_path}?")

# TODO: Move to feature spec
expect do
get link['href']
user.reload
Expand Down

0 comments on commit b1a0d30

Please sign in to comment.