-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathsign_up_spec.rb
More file actions
129 lines (113 loc) · 3.4 KB
/
sign_up_spec.rb
File metadata and controls
129 lines (113 loc) · 3.4 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'rails_helper'
RSpec.describe 'Sign Up process' do
include_context 'with graphql query request'
let(:name) { Faker::Name.name }
let(:password) { Faker::Internet.password }
let(:email) { Faker::Internet.email }
let(:redirect) { Faker::Internet.url }
context 'when using the user model' do
let(:query) do
<<-GRAPHQL
mutation {
userSignUp(
email: "#{email}"
name: "#{name}"
password: "#{password}"
passwordConfirmation: "#{password}"
confirmSuccessUrl: "#{redirect}"
) {
user {
email
name
}
}
}
GRAPHQL
end
context 'when params are correct' do
it 'creates a new resource that requires confirmation' do
expect { post_request }.to(
change(User, :count).by(1)
.and(change(ActionMailer::Base.deliveries, :count).by(1))
)
user = User.last
expect(user).not_to be_active_for_authentication
expect(user.confirmed_at).to be_nil
expect(user).to be_valid_password(password)
expect(json_response[:data][:userSignUp]).to include(
user: {
email: email,
name: name
}
)
email = Nokogiri::HTML(ActionMailer::Base.deliveries.last.body.encoded)
link = email.css('a').first
expect do
get link['href']
user.reload
end.to change { user.active_for_authentication? }.to(true)
end
end
context 'when required params are missing' do
let(:email) { '' }
it 'does *NOT* create resource a resource nor send an email' do
expect { post_request }.to(
not_change(User, :count)
.and(not_change(ActionMailer::Base.deliveries, :count))
)
expect(json_response[:data][:userSignUp]).to be_nil
expect(json_response[:errors]).to containing_exactly(
hash_including(
message: "User couldn't be registered",
extensions: { code: 'USER_ERROR', detailed_errors: ["Email can't be blank"] }
)
)
end
end
end
context 'when using the admin model' do
let(:query) do
<<-GRAPHQL
mutation {
adminSignUp(
email: "#{email}"
password: "#{password}"
passwordConfirmation: "#{password}"
confirmSuccessUrl: "#{redirect}"
) {
authenticable {
email
}
}
}
GRAPHQL
end
before { post_request }
it 'skips the sign up mutation' do
expect(json_response[:errors]).to contain_exactly(
hash_including(message: "Field 'adminSignUp' doesn't exist on type 'Mutation'")
)
end
end
context 'when using the guest model' do
let(:query) do
<<-GRAPHQL
mutation {
guestSignUp(
email: "#{email}"
password: "#{password}"
passwordConfirmation: "#{password}"
confirmSuccessUrl: "#{redirect}"
) {
authenticable {
email
}
}
}
GRAPHQL
end
it 'works without the confirmable module' do
expect { post_request }.to change(Guest, :count).from(0).to(1)
end
end
end