add createUser mutation
This commit is contained in:
11
spec/graphql/inputs/user_attributes_input_spec.rb
Normal file
11
spec/graphql/inputs/user_attributes_input_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe(Inputs::UserAttributesInput) do
|
||||
subject { described_class }
|
||||
|
||||
describe "arguments" do
|
||||
it { is_expected.to(accept_argument(:first_name).of_type("String!")) }
|
||||
it { is_expected.to(accept_argument(:last_name).of_type("String!")) }
|
||||
end
|
||||
end
|
||||
66
spec/graphql/mutations/create_user_spec.rb
Normal file
66
spec/graphql/mutations/create_user_spec.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
# frozen_string_literal: true
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe(Mutations::CreateUser) do
|
||||
describe "#resolve" do
|
||||
let(:mutation_string) do
|
||||
<<~GQL
|
||||
mutation($input: CreateUserInput!) {
|
||||
createUser(input: $input) {
|
||||
success
|
||||
errors
|
||||
}
|
||||
}
|
||||
GQL
|
||||
end
|
||||
|
||||
let(:context) do
|
||||
{
|
||||
current_auth: Auth::Profile.new({
|
||||
id: "_",
|
||||
email: "user@example.com",
|
||||
}),
|
||||
}
|
||||
end
|
||||
|
||||
let(:variables) do
|
||||
{
|
||||
input: { user: {
|
||||
firstName: "First Name",
|
||||
lastName: "Last Name",
|
||||
} },
|
||||
}
|
||||
end
|
||||
|
||||
context "when current_auth is not being used by any user" do
|
||||
it "create a user to auth" do
|
||||
result = XStakeSchema.execute(
|
||||
mutation_string,
|
||||
variables: variables,
|
||||
context: context
|
||||
).to_h
|
||||
|
||||
expect(result["data"]["createUser"]["success"]).to(eq(true))
|
||||
end
|
||||
end
|
||||
|
||||
context "when auth is being used by no users" do
|
||||
it "returns error" do
|
||||
User.create(
|
||||
first_name: "First Name",
|
||||
last_name: "Last Name",
|
||||
email: "user@example.com"
|
||||
)
|
||||
|
||||
result = XStakeSchema.execute(
|
||||
mutation_string,
|
||||
variables: variables,
|
||||
context: context
|
||||
).to_h
|
||||
|
||||
expect(result["data"]["createUser"]["success"]).to(eq(false))
|
||||
expect(result["data"]["createUser"]["errors"]).to(eq(["Validation failed: Email has already been taken"]))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user