-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathsend_password_reset_spec.rb
More file actions
63 lines (52 loc) · 1.92 KB
/
send_password_reset_spec.rb
File metadata and controls
63 lines (52 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'rails_helper'
RSpec.describe 'Send Password Reset Requests' do
include_context 'with graphql query request'
let!(:user) { create(:user, :confirmed, email: 'jwinnfield@wallaceinc.com') }
let(:email) { user.email }
let(:redirect_url) { Faker::Internet.url }
let(:query) do
<<-GRAPHQL
mutation {
userSendPasswordReset(
email: "#{email}",
redirectUrl: "#{redirect_url}"
) {
message
}
}
GRAPHQL
end
context 'when params are correct' do
it 'sends password reset email' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(json_response[:data][:userSendPasswordReset]).to include(
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
)
email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
# TODO: Move to feature spec
expect do
get link['href']
user.reload
end.to change(user, :allow_password_change).from(false).to(true)
end
end
context 'when email address uses different casing' do
let(:email) { 'jWinnfield@wallaceinc.com' }
it 'honors devise configuration for case insensitive fields' do
expect { post_request }.to change(ActionMailer::Base.deliveries, :count).by(1)
expect(json_response[:data][:userSendPasswordReset]).to include(
message: 'You will receive an email with instructions on how to reset your password in a few minutes.'
)
end
end
context 'when user email is not found' do
let(:email) { 'nothere@gmail.com' }
before { post_request }
it 'returns an error' do
expect(json_response[:errors]).to contain_exactly(
hash_including(message: 'User was not found or was not logged in.', extensions: { code: 'USER_ERROR' })
)
end
end
end