debian-mirror-gitlab/spec/graphql/resolvers/user_resolver_spec.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Resolvers::UserResolver do
2020-06-23 00:09:42 +05:30
include GraphqlHelpers
describe '#resolve' do
let_it_be(:user) { create(:user) }
context 'when neither an ID or a username is provided' do
2022-05-07 20:08:51 +05:30
it 'generates an ArgumentError' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_user
end
2020-06-23 00:09:42 +05:30
end
end
2022-05-07 20:08:51 +05:30
it 'generates an ArgumentError when both an ID and username are provided' do
expect_graphql_error_to_be_created(Gitlab::Graphql::Errors::ArgumentError) do
resolve_user(id: user.to_global_id, username: user.username)
end
2020-06-23 00:09:42 +05:30
end
context 'by username' do
it 'returns the correct user' do
expect(
resolve_user(username: user.username)
).to eq(user)
end
end
context 'by ID' do
it 'returns the correct user' do
expect(
resolve_user(id: user.to_global_id)
).to eq(user)
end
end
end
private
def resolve_user(args = {})
sync(resolve(described_class, args: args))
end
end