Created
October 12, 2019 02:34
-
-
Save jameswritescode/335b9d3a85ef283c40bba256be7fa328 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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