-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase GraphqlDevise::GraphqlController coverage
- Loading branch information
1 parent
aa9ac82
commit 1acc97b
Showing
3 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GraphqlDevise::GraphqlController do | ||
let(:password) { 'password123' } | ||
let(:user) { create(:user, :confirmed, password: password) } | ||
|
||
context 'when variables are a string' do | ||
it 'parses the string variables' do | ||
post '/api/v1/graphql_auth', | ||
params: { | ||
query: "mutation($email: String!) { userLogin(email: $email, password: \"#{password}\") { user { email name signInCount } } }", | ||
variables: "{\"email\": \"#{user.email}\"}" | ||
|
||
} | ||
|
||
expect(json_response).to match( | ||
data: { userLogin: { user: { email: user.email, name: user.name, signInCount: 1 } } } | ||
) | ||
end | ||
end | ||
|
||
context 'when variables are not a string or hash' do | ||
it 'raises an error' do | ||
expect do | ||
post '/api/v1/graphql_auth', | ||
params: { | ||
query: "mutation($email: String!) { userLogin(email: $email, password: \"#{password}\") { user { email name signInCount } } }", | ||
variables: 1 | ||
|
||
} | ||
end.to raise_error(ArgumentError) | ||
end | ||
end | ||
|
||
context 'when multiplexing queries' do | ||
it 'executes multiple queries in the same request' do | ||
post '/api/v1/graphql_auth', | ||
params: { | ||
_json: [ | ||
{ query: "mutation { userLogin(email: \"#{user.email}\", password: \"#{password}\") { user { email name signInCount } } }" }, | ||
{ query: "mutation { userLogin(email: \"#{user.email}\", password: \"wrong password\") { user { email name signInCount } } }" } | ||
] | ||
} | ||
|
||
expect(json_response).to match( | ||
[ | ||
{ data: { userLogin: { user: { email: user.email, name: user.name, signInCount: 1 } } } }, | ||
{ | ||
data: { userLogin: nil }, | ||
errors: [ | ||
hash_including( | ||
message: 'Invalid login credentials. Please try again.', extensions: { code: 'USER_ERROR' } | ||
) | ||
] | ||
} | ||
] | ||
) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.