2020-08-28 02:10:45 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Resolvers::ProjectMergeRequestsResolver do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:other_user) { create(:user) }
|
2020-12-10 07:09:43 -05:00
|
|
|
let_it_be(:reviewer) { create(:user) }
|
2020-08-28 02:10:45 -04:00
|
|
|
|
2020-12-10 07:09:43 -05:00
|
|
|
let_it_be(:merge_request) do
|
2020-08-28 02:10:45 -04:00
|
|
|
create(:merge_request,
|
|
|
|
:unique_branches,
|
|
|
|
source_project: project,
|
|
|
|
target_project: project,
|
|
|
|
author: other_user,
|
2020-12-10 07:09:43 -05:00
|
|
|
assignee: other_user,
|
|
|
|
reviewers: [reviewer])
|
2020-08-28 02:10:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by assignee' do
|
|
|
|
it 'filters merge requests by assignee username' do
|
|
|
|
result = resolve_mr(project, assignee_username: other_user.username)
|
|
|
|
|
2020-12-13 22:10:06 -05:00
|
|
|
expect(result).to contain_exactly(merge_request)
|
2020-08-28 02:10:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not find anything' do
|
|
|
|
result = resolve_mr(project, assignee_username: 'unknown-user')
|
|
|
|
|
|
|
|
expect(result).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'by author' do
|
|
|
|
it 'filters merge requests by author username' do
|
|
|
|
result = resolve_mr(project, author_username: other_user.username)
|
|
|
|
|
2020-12-13 22:10:06 -05:00
|
|
|
expect(result).to contain_exactly(merge_request)
|
2020-08-28 02:10:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not find anything' do
|
|
|
|
result = resolve_mr(project, author_username: 'unknown-user')
|
|
|
|
|
|
|
|
expect(result).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-10 07:09:43 -05:00
|
|
|
context 'by reviewer' do
|
|
|
|
it 'filters merge requests by reviewer username' do
|
|
|
|
result = resolve_mr(project, reviewer_username: reviewer.username)
|
|
|
|
|
2020-12-13 22:10:06 -05:00
|
|
|
expect(result).to contain_exactly(merge_request)
|
2020-12-10 07:09:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not find anything' do
|
|
|
|
result = resolve_mr(project, reviewer_username: 'unknown-user')
|
|
|
|
|
|
|
|
expect(result).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-18 13:09:08 -05:00
|
|
|
def resolve_mr(project, resolver: described_class, user: current_user, **args)
|
2020-08-28 02:10:45 -04:00
|
|
|
resolve(resolver, obj: project, args: args, ctx: { current_user: user })
|
|
|
|
end
|
|
|
|
end
|