Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameswritescode/335b9d3a85ef283c40bba256be7fa328 to your computer and use it in GitHub Desktop.
Save jameswritescode/335b9d3a85ef283c40bba256be7fa328 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Mutations::CreateOrganization, type: :graphql do
let(:query) do
<<~GQL
mutation($input: CreateOrganizationInput!) {
admin {
createOrganization(input: $input) {
error
organization {
id
}
}
}
}
GQL
end
let(:success_response) do
{
'createOrganization' => {
'error' => nil,
'organization' => { 'id' => Organization.last.id.to_s },
},
}
end
def execute(user = nil)
execute_graphql(
query,
user: user,
variables: { input: { seats: 1, name: 'WhatPulse' } },
)
end
it 'is undefined for non-admins' do
expect(execute).to be_missing_graphql_field('Mutation', 'admin')
end
it 'creates organization' do
expect(execute(build(:user, admin: true))).to have_graphql_response('admin', success_response)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment