-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathcheck_password_token_spec.rb
More file actions
81 lines (66 loc) · 2.28 KB
/
check_password_token_spec.rb
File metadata and controls
81 lines (66 loc) · 2.28 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'rails_helper'
RSpec.describe 'Check Password Token Requests' do
include_context 'with graphql query request'
let(:user) { create(:user, :confirmed) }
let(:redirect_url) { 'https://google.com' }
let(:query) do
<<-GRAPHQL
mutation {
userCheckPasswordToken(
resetPasswordToken: "#{token}",
redirectUrl: "#{redirect_url}"
) {
authenticable { email }
}
}
GRAPHQL
end
context 'when reset password token is valid' do
let(:token) { user.send(:set_reset_password_token) }
context 'when redirect_url is not provided' do
let(:redirect_url) { nil }
it 'returns authenticable and credentials in the headers' do
get_request
expect(response).to include_auth_headers
expect(json_response[:data][:userCheckPasswordToken]).to match(
authenticable: { email: user.email }
)
end
end
context 'when redirect url is provided' do
it 'redirects to redirect url' do
expect do
get_request
user.reload
end.to change { user.tokens.keys.count }.from(0).to(1).and(
change(user, :allow_password_change).from(false).to(true)
)
expect(response).to redirect_to %r{\Ahttps://google.com}
expect(response.body).to include("client=#{user.reload.tokens.keys.first}")
expect(response.body).to include('access-token=')
expect(response.body).to include('uid=')
expect(response.body).to include('expiry=')
end
end
context 'when token has expired' do
it 'returns an expired token error' do
travel_to 10.hours.ago do
token
end
get_request
expect(json_response[:errors]).to contain_exactly(
hash_including(message: 'Reset password token is no longer valid.', extensions: { code: 'USER_ERROR' })
)
end
end
end
context 'when reset password token is not found' do
let(:token) { user.send(:set_reset_password_token) + 'invalid' }
it 'redirects to redirect url' do
get_request
expect(json_response[:errors]).to contain_exactly(
hash_including(message: 'No user found for the specified reset token.', extensions: { code: 'USER_ERROR' })
)
end
end
end