-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathadditional_mutations_spec.rb
More file actions
66 lines (56 loc) · 1.77 KB
/
additional_mutations_spec.rb
File metadata and controls
66 lines (56 loc) · 1.77 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
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Additional Mutations' do
include_context 'with graphql query request'
let(:name) { Faker::Name.name }
let(:password) { Faker::Internet.password }
let(:password_confirmation) { password }
let(:email) { Faker::Internet.email }
context 'when using the user model' do
let(:query) do
<<-GRAPHQL
mutation {
registerConfirmedUser(
email: "#{email}",
name: "#{name}",
password: "#{password}",
passwordConfirmation: "#{password_confirmation}"
) {
user {
email
name
}
}
}
GRAPHQL
end
context 'when params are correct' do
it 'creates a new resource that is already confirmed' do
expect { post_request }.to(
change(User, :count).by(1)
.and(not_change(ActionMailer::Base.deliveries, :count))
)
user = User.last
expect(user).to be_confirmed
expect(json_response[:data][:registerConfirmedUser]).to include(
user: {
email: email,
name: name
}
)
end
end
context 'when params are incorrect' do
let(:password_confirmation) { 'not the same' }
it 'returns descriptive errors' do
expect { post_request }.to not_change(User, :count)
expect(json_response[:errors]).to contain_exactly(
hash_including(
message: 'Custom registration failed',
extensions: { code: 'USER_ERROR', detailed_errors: ["Password confirmation doesn't match Password"] }
)
)
end
end
end
end