Created
May 31, 2022 19:41
-
-
Save eebs/dde6e1f625d48a9bf1bd938ca609c4d8 to your computer and use it in GitHub Desktop.
GraphQL Mutation Testing
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
require "rails_helper" | |
RSpec.describe "mutation RegenerateGroupSignupLink" do | |
def mutation | |
mutation = <<~GRAPHQL | |
mutation RegenerateGroupSignupLink($input: RegenerateGroupSignupLinkInput!){ | |
regenerateGroupSignupLink(input: $input){ | |
group { | |
id | |
name | |
signupUrl | |
} | |
} | |
} | |
GRAPHQL | |
end | |
context "when the current user is an admin of the group" do | |
it "regenerates the signup token" do | |
admin = create(:user) | |
group = create(:group, :with_payment, name: "Group Name") | |
create(:group_user, user: admin, group: group, admin: true) | |
variables = { input: { groupId: global_id(group) } } | |
result = query(mutation).as(admin).with(variables).run | |
expect(result).to have_data( | |
regenerateGroupSignupLink: { | |
group: { | |
id: global_id(group), | |
name: "Group Name", | |
signupUrl: a_kind_of(String) | |
} | |
} | |
) | |
end | |
end | |
context "when the current user is not an admin of the group" do | |
it "returns an error" do | |
user = create(:user) | |
group = create(:group, :with_payment) | |
variables = { input: { groupId: global_id(group) } } | |
result = query(mutation).as(user).with(variables).run | |
expect(result).to have_error( | |
"You do not have the correct permissions to execute `regenerateGroupSignupLink`" | |
).at_path("regenerateGroupSignupLink") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment