2020-05-28 11:08:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Resolvers::UserResolver do
|
2020-05-28 11:08:02 -04:00
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
context 'when neither an ID or a username is provided' do
|
|
|
|
it 'raises an ArgumentError' do
|
|
|
|
expect { resolve_user }
|
|
|
|
.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an ArgumentError when both an ID and username are provided' do
|
|
|
|
expect { resolve_user(id: user.to_global_id, username: user.username) }
|
|
|
|
.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
|
|
|
|
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 = {})
|
2020-06-02 11:08:24 -04:00
|
|
|
sync(resolve(described_class, args: args))
|
2020-05-28 11:08:02 -04:00
|
|
|
end
|
|
|
|
end
|