-
Notifications
You must be signed in to change notification settings - Fork 49
Added ResendConfirmation GraphQL method. #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mcelicalderon
merged 16 commits into
graphql-devise:master
from
aarona:resend_confirmation
Nov 24, 2019
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d6324c4
Updated documentation for the mutation and query graphql methods.
aarona 898a652
Added ResendConfirmation GraphQL method.
aarona 7e27c65
Fixed a misspelling
aarona ac9c1ab
Add github templates for issues (#36)
00dav00 ee76d39
Merge pull request #34 from aarona/mut_que_docs
mcelicalderon 1e09349
Merged master into resend_confirmation.
aarona 083570f
Added ResendConfirmation GraphQL method.
aarona 9ee3fbc
Merge branch 'resend_confirmation' of https://github.com/aarona/graph…
aarona 537e3f2
Pulled upstream master and then rebased master on send_confirmation
aarona 2236216
Pulled upstream master and rebased master in resend_confirmation
aarona d1539bf
Removed rebased code to seperate the Resend Confirmation changes.
aarona 53e7bd4
Removed rebased code to seperate the Resend Confirmation changes.
aarona 0ced80c
Code review fixes and test enhancements per @00dav00's request.
aarona 4e83a8b
Code review requests per @mcelicalderon and @00dav00
aarona 58014a4
Moved reliance for Resend Instructions from Devise to Graphql Devise.
aarona 247819e
Some RSpec styling changes per @mcelicalderon's request.
aarona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/graphql/graphql_devise/mutations/resend_confirmation.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module GraphqlDevise | ||
module Mutations | ||
class ResendConfirmation < Base | ||
argument :email, String, required: true, prepare: ->(email, _) { email.downcase } | ||
argument :redirect_url, String, required: true | ||
|
||
field :message, String, null: false | ||
aarona marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def resolve(email:, redirect_url:) | ||
resource = controller.find_resource(:uid, email) | ||
|
||
if resource | ||
yield resource if block_given? | ||
|
||
raise_user_error(I18n.t('errors.messages.already_confirmed')) if resource.confirmed? | ||
|
||
resource.send_confirmation_instructions({ | ||
redirect_url: redirect_url, | ||
template_path: ['graphql_devise/mailer'] | ||
}) | ||
|
||
{ | ||
authenticable: resource, | ||
message: I18n.t('graphql_devise.confirmations.send_instructions', email: email) | ||
} | ||
aarona marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
raise_user_error(I18n.t('graphql_devise.confirmations.user_not_found', email: email)) | ||
end | ||
end | ||
end | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
app/views/graphql_devise/mailer/confirmation_instructions.html.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<p><%= t(:welcome).capitalize + ' ' + @email %>!</p> | ||
|
||
<p><%= t '.confirm_link_msg' %> </p> | ||
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Resend confirmation' do | ||
include_context 'with graphql query request' | ||
|
||
let(:user) { create(:user, confirmed_at: nil) } | ||
let(:email) { user.email } | ||
let(:id) { user.id } | ||
let(:redirect) { Faker::Internet.url } | ||
let(:query) do | ||
<<-GRAPHQL | ||
mutation { | ||
userResendConfirmation( | ||
email:"#{email}", | ||
redirectUrl:"#{redirect}" | ||
) { | ||
message | ||
authenticable { | ||
id | ||
} | ||
} | ||
} | ||
GRAPHQL | ||
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( | ||
authenticable: { | ||
id: id, | ||
email: email | ||
}, | ||
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(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) | ||
end | ||
|
||
context 'when the user has already been confirmed' do | ||
before { user.confirm } | ||
|
||
it 'does *NOT* send an email and raises an error' do | ||
expect { post_request }.to not_change(ActionMailer::Base.deliveries, :count) | ||
expect(json_response[:data][:userResendConfirmation]).to be_nil | ||
expect(json_response[:errors]).to contain_exactly( | ||
hash_including( | ||
message: "Email was already confirmed, please try signing in", | ||
extensions: { code: 'USER_ERROR' } | ||
) | ||
) | ||
end | ||
end | ||
end | ||
|
||
context "when the email isn't in the system" do | ||
let(:email) { 'nothere@gmail.com' } | ||
|
||
it 'does *NOT* send an email and raises an error' do | ||
expect { post_request }.to not_change(ActionMailer::Base.deliveries, :count) | ||
expect(json_response[:data][:userResendConfirmation]).to be_nil | ||
expect(json_response[:errors]).to contain_exactly( | ||
hash_including( | ||
message: "Unable to find user with email '#{email}'.", | ||
extensions: { code: 'USER_ERROR' } | ||
) | ||
) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.