-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathlogout_spec.rb
More file actions
65 lines (57 loc) · 1.7 KB
/
logout_spec.rb
File metadata and controls
65 lines (57 loc) · 1.7 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
require 'rails_helper'
RSpec.describe 'Logout Requests' do
include_context 'with graphql query request'
let(:user) { create(:user, :confirmed) }
let(:query) do
<<-GRAPHQL
mutation {
userLogout {
authenticable { email }
}
}
GRAPHQL
end
before { post_request }
context 'when user is logged in' do
let(:headers) { user.create_new_auth_token }
it 'logs out the user' do
expect(response).not_to include_auth_headers
expect(user.reload.tokens.keys).to be_empty
expect(json_response[:data][:userLogout]).to match(
authenticable: { email: user.email }
)
expect(json_response[:errors]).to be_nil
end
end
context 'when user is not logged in' do
it 'returns an error' do
expect(response).not_to include_auth_headers
expect(user.reload.tokens.keys).to be_empty
expect(json_response[:data][:userLogout]).to be_nil
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
context 'when using the admin model' do
let(:query) do
<<-GRAPHQL
mutation {
adminLogout {
authenticable { email }
}
}
GRAPHQL
end
let(:admin) { create(:admin, :confirmed) }
let(:headers) { admin.create_new_auth_token }
it 'logs out the admin' do
expect(response).not_to include_auth_headers
expect(admin.reload.tokens.keys).to be_empty
expect(json_response[:data][:adminLogout]).to match(
authenticable: { email: admin.email }
)
expect(json_response[:errors]).to be_nil
end
end
end