-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathlogout_spec.rb
More file actions
42 lines (36 loc) · 1.14 KB
/
logout_spec.rb
File metadata and controls
42 lines (36 loc) · 1.14 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
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 '/api/v1/graphql_auth', *graphql_params }
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
end