2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'email_spec'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Emails::Pipelines do
|
2019-12-21 20:55:43 +05:30
|
|
|
include EmailSpec::Matchers
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
shared_examples_for 'correct pipeline information' do
|
|
|
|
it 'has a correct information' do
|
|
|
|
expect(subject)
|
2021-03-08 18:12:59 +05:30
|
|
|
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
|
|
|
|
"#{project.name} | " \
|
2019-12-21 20:55:43 +05:30
|
|
|
"#{pipeline.short_sha}".to_s
|
|
|
|
|
|
|
|
expect(subject).to have_body_text pipeline.source_ref
|
|
|
|
expect(subject).to have_body_text status_text
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
context 'when pipeline on master branch has a merge request' do
|
|
|
|
let(:pipeline) { create(:ci_pipeline, ref: 'master', sha: sha, project: project) }
|
|
|
|
|
|
|
|
let!(:merge_request) do
|
|
|
|
create(:merge_request, source_branch: 'master', target_branch: 'feature',
|
|
|
|
source_project: project, target_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has correct information that there is no merge request link' do
|
|
|
|
expect(subject)
|
2021-03-08 18:12:59 +05:30
|
|
|
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
|
|
|
|
"#{project.name} | " \
|
2020-03-13 15:44:24 +05:30
|
|
|
"#{pipeline.short_sha}".to_s
|
|
|
|
|
|
|
|
expect(subject).to have_body_text pipeline.source_ref
|
|
|
|
expect(subject).to have_body_text status_text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
context 'when pipeline for merge requests' do
|
|
|
|
let(:pipeline) { merge_request.all_pipelines.first }
|
|
|
|
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, :with_detached_merge_request_pipeline,
|
|
|
|
source_project: project,
|
|
|
|
target_project: project)
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'has correct information that there is a merge request link' do
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(subject)
|
2021-03-08 18:12:59 +05:30
|
|
|
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
|
|
|
|
"#{project.name} | " \
|
|
|
|
"#{pipeline.short_sha}".to_s
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
expect(subject).to have_body_text merge_request.to_reference
|
|
|
|
expect(subject).to have_body_text pipeline.source_ref
|
|
|
|
expect(subject).not_to have_body_text pipeline.ref
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
context 'when branch pipeline is set to a merge request as a head pipeline' do
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_pipeline, project: project, ref: ref, sha: sha,
|
|
|
|
merge_requests_as_head_pipeline: [merge_request])
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: project, target_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has correct information that there is a merge request link' do
|
|
|
|
expect(subject)
|
2021-03-08 18:12:59 +05:30
|
|
|
.to have_subject "#{status} pipeline for #{pipeline.source_ref} | " \
|
|
|
|
"#{project.name} | " \
|
|
|
|
"#{pipeline.short_sha}".to_s
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
expect(subject).to have_body_text merge_request.to_reference
|
|
|
|
expect(subject).to have_body_text pipeline.source_ref
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pipeline_success_email' do
|
|
|
|
subject { Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) }
|
|
|
|
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) }
|
|
|
|
let(:ref) { 'master' }
|
|
|
|
let(:sha) { project.commit(ref).sha }
|
|
|
|
|
|
|
|
it_behaves_like 'correct pipeline information' do
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:status) { 'Successful' }
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:status_text) { "Pipeline ##{pipeline.id} has passed!" }
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pipeline_failed_email' do
|
|
|
|
subject { Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email)) }
|
|
|
|
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) }
|
|
|
|
let(:ref) { 'master' }
|
|
|
|
let(:sha) { project.commit(ref).sha }
|
|
|
|
|
|
|
|
it_behaves_like 'correct pipeline information' do
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:status) { 'Failed' }
|
|
|
|
let(:status_text) { "Pipeline ##{pipeline.id} has failed!" }
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
describe '#pipeline_fixed_email' do
|
|
|
|
subject { Notify.pipeline_fixed_email(pipeline, pipeline.user.try(:email)) }
|
|
|
|
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) }
|
|
|
|
let(:ref) { 'master' }
|
|
|
|
let(:sha) { project.commit(ref).sha }
|
|
|
|
|
|
|
|
it_behaves_like 'correct pipeline information' do
|
2021-03-08 18:12:59 +05:30
|
|
|
let(:status) { 'Fixed' }
|
|
|
|
let(:status_text) { "Pipeline has been fixed and ##{pipeline.id} has passed!" }
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|