debian-mirror-gitlab/spec/services/quick_actions/target_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.3 KiB
Ruby
Raw Permalink Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe QuickActions::TargetService, feature_category: :team_planning do
2018-11-20 20:47:30 +05:30
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:service) { described_class.new(project, user) }
before do
project.add_maintainer(user)
end
describe '#execute' do
2023-04-23 21:23:45 +05:30
shared_examples 'no target' do |type_iid:|
2018-11-20 20:47:30 +05:30
it 'returns nil' do
2023-04-23 21:23:45 +05:30
target = service.execute(type, type_iid)
2018-11-20 20:47:30 +05:30
expect(target).to be_nil
end
end
shared_examples 'find target' do
it 'returns the target' do
2023-04-23 21:23:45 +05:30
found_target = service.execute(type, target_iid)
2018-11-20 20:47:30 +05:30
expect(found_target).to eq(target)
end
end
2023-04-23 21:23:45 +05:30
shared_examples 'build target' do |type_iid:|
2018-11-20 20:47:30 +05:30
it 'builds a new target' do
2023-04-23 21:23:45 +05:30
target = service.execute(type, type_iid)
2018-11-20 20:47:30 +05:30
expect(target.project).to eq(project)
expect(target).to be_new_record
end
end
context 'for issue' do
let(:target) { create(:issue, project: project) }
2023-04-23 21:23:45 +05:30
let(:target_iid) { target.iid }
2018-11-20 20:47:30 +05:30
let(:type) { 'Issue' }
it_behaves_like 'find target'
2023-04-23 21:23:45 +05:30
it_behaves_like 'build target', type_iid: nil
it_behaves_like 'build target', type_iid: -1
end
context 'for work item' do
let(:target) { create(:work_item, :task, project: project) }
let(:target_iid) { target.iid }
let(:type) { 'WorkItem' }
it_behaves_like 'find target'
2018-11-20 20:47:30 +05:30
end
context 'for merge request' do
let(:target) { create(:merge_request, source_project: project) }
2023-04-23 21:23:45 +05:30
let(:target_iid) { target.iid }
2018-11-20 20:47:30 +05:30
let(:type) { 'MergeRequest' }
it_behaves_like 'find target'
2023-04-23 21:23:45 +05:30
it_behaves_like 'build target', type_iid: nil
it_behaves_like 'build target', type_iid: -1
2018-11-20 20:47:30 +05:30
end
context 'for commit' do
let(:project) { create(:project, :repository) }
let(:target) { project.commit.parent }
2023-04-23 21:23:45 +05:30
let(:target_iid) { target.sha }
2018-11-20 20:47:30 +05:30
let(:type) { 'Commit' }
it_behaves_like 'find target'
2023-04-23 21:23:45 +05:30
it_behaves_like 'no target', type_iid: 'invalid_sha'
2018-11-20 20:47:30 +05:30
2023-04-23 21:23:45 +05:30
context 'with nil target_iid' do
2018-11-20 20:47:30 +05:30
let(:target) { project.commit }
2023-04-23 21:23:45 +05:30
let(:target_iid) { nil }
2018-11-20 20:47:30 +05:30
it_behaves_like 'find target'
end
end
context 'for unknown type' do
let(:type) { 'unknown' }
2023-04-23 21:23:45 +05:30
it_behaves_like 'no target', type_iid: :unused
2018-11-20 20:47:30 +05:30
end
end
end