blob: d5881d3b204d2fa037c3c596249a08dc0197798f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::ExternalPullRequests::CreatePipelineService do
describe '#execute' do
let_it_be(:project) { create(:project, :auto_devops, :repository) }
let_it_be(:user) { create(:user) }
let_it_be_with_reload(:pull_request) { create(:external_pull_request, project: project) }
before do
project.add_maintainer(user)
end
subject(:execute) { described_class.new(project, user).execute(pull_request) }
context 'when pull request is open' do
before do
pull_request.update!(status: :open)
end
context 'when source sha is the head of the source branch' do
let(:source_branch) { project.repository.branches.last }
before do
pull_request.update!(source_branch: source_branch.name, source_sha: source_branch.target)
end
it 'enqueues Ci::ExternalPullRequests::CreatePipelineWorker' do
expect { execute }
.to change { ::Ci::ExternalPullRequests::CreatePipelineWorker.jobs.count }
.by(1)
args = ::Ci::ExternalPullRequests::CreatePipelineWorker.jobs.last['args']
expect(args[0]).to eq(project.id)
expect(args[1]).to eq(user.id)
expect(args[2]).to eq(pull_request.id)
end
end
context 'when source sha is not the head of the source branch (force push upon rebase)' do
let(:source_branch) { project.repository.branches.first }
let(:commit) { project.repository.commits(source_branch.name, limit: 2).last }
before do
pull_request.update!(source_branch: source_branch.name, source_sha: commit.sha)
end
it 'does nothing', :aggregate_failures do
expect { execute }
.not_to change { ::Ci::ExternalPullRequests::CreatePipelineWorker.jobs.count }
expect(execute).to be_error
expect(execute.message).to eq('The source sha is not the head of the source branch')
expect(execute.payload).to be_nil
end
end
end
context 'when pull request is not opened' do
before do
pull_request.update!(status: :closed)
end
it 'does nothing', :aggregate_failures do
expect { execute }
.not_to change { ::Ci::ExternalPullRequests::CreatePipelineWorker.jobs.count }
expect(execute).to be_error
expect(execute.message).to eq('The pull request is not opened')
expect(execute.payload).to be_nil
end
end
end
end
|