Skip to content

Commit 1acc97b

Browse files
committed
Increase GraphqlDevise::GraphqlController coverage
1 parent aa9ac82 commit 1acc97b

3 files changed

Lines changed: 60 additions & 13 deletions

File tree

spec/rails_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
config.include(Requests::JsonHelpers, type: :request)
3939
config.include(Requests::AuthHelpers, type: :request)
4040
config.include(ActiveSupport::Testing::TimeHelpers)
41-
config.include(Generators::FileHelpers, type: :generator)
4241

4342
config.before(:suite) do
4443
ActionController::Base.allow_forgery_protection = true
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe GraphqlDevise::GraphqlController do
4+
let(:password) { 'password123' }
5+
let(:user) { create(:user, :confirmed, password: password) }
6+
7+
context 'when variables are a string' do
8+
it 'parses the string variables' do
9+
post '/api/v1/graphql_auth',
10+
params: {
11+
query: "mutation($email: String!) { userLogin(email: $email, password: \"#{password}\") { user { email name signInCount } } }",
12+
variables: "{\"email\": \"#{user.email}\"}"
13+
14+
}
15+
16+
expect(json_response).to match(
17+
data: { userLogin: { user: { email: user.email, name: user.name, signInCount: 1 } } }
18+
)
19+
end
20+
end
21+
22+
context 'when variables are not a string or hash' do
23+
it 'raises an error' do
24+
expect do
25+
post '/api/v1/graphql_auth',
26+
params: {
27+
query: "mutation($email: String!) { userLogin(email: $email, password: \"#{password}\") { user { email name signInCount } } }",
28+
variables: 1
29+
30+
}
31+
end.to raise_error(ArgumentError)
32+
end
33+
end
34+
35+
context 'when multiplexing queries' do
36+
it 'executes multiple queries in the same request' do
37+
post '/api/v1/graphql_auth',
38+
params: {
39+
_json: [
40+
{ query: "mutation { userLogin(email: \"#{user.email}\", password: \"#{password}\") { user { email name signInCount } } }" },
41+
{ query: "mutation { userLogin(email: \"#{user.email}\", password: \"wrong password\") { user { email name signInCount } } }" }
42+
]
43+
}
44+
45+
expect(json_response).to match(
46+
[
47+
{ data: { userLogin: { user: { email: user.email, name: user.name, signInCount: 1 } } } },
48+
{
49+
data: { userLogin: nil },
50+
errors: [
51+
hash_including(
52+
message: 'Invalid login credentials. Please try again.', extensions: { code: 'USER_ERROR' }
53+
)
54+
]
55+
}
56+
]
57+
)
58+
end
59+
end
60+
end

spec/support/generators/file_helpers.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)