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

73 lines
1.9 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# 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) }
2021-02-22 17:27:13 +05:30
let_it_be(:reviewer) { create(:user) }
2020-11-24 15:15:51 +05:30
2021-02-22 17:27:13 +05:30
let_it_be(:merge_request) do
2020-11-24 15:15:51 +05:30
create(:merge_request,
:unique_branches,
source_project: project,
target_project: project,
author: other_user,
2021-02-22 17:27:13 +05:30
assignee: other_user,
reviewers: [reviewer])
2020-11-24 15:15:51 +05:30
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)
2021-02-22 17:27:13 +05:30
expect(result).to contain_exactly(merge_request)
2020-11-24 15:15:51 +05:30
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)
2021-02-22 17:27:13 +05:30
expect(result).to contain_exactly(merge_request)
2020-11-24 15:15:51 +05:30
end
it 'does not find anything' do
result = resolve_mr(project, author_username: 'unknown-user')
expect(result).to be_empty
end
end
2021-02-22 17:27:13 +05:30
context 'by reviewer' do
it 'filters merge requests by reviewer username' do
result = resolve_mr(project, reviewer_username: reviewer.username)
expect(result).to contain_exactly(merge_request)
end
it 'does not find anything' do
result = resolve_mr(project, reviewer_username: 'unknown-user')
expect(result).to be_empty
end
end
def resolve_mr(project, resolver: described_class, user: current_user, **args)
2020-11-24 15:15:51 +05:30
resolve(resolver, obj: project, args: args, ctx: { current_user: user })
end
end