2019-10-25 05:06:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-16 16:58:20 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe CommitStatusPresenter do
|
2018-05-16 16:58:20 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
|
|
|
|
subject(:presenter) do
|
|
|
|
described_class.new(build)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'inherits from Gitlab::View::Presenter::Delegated' do
|
|
|
|
expect(described_class.superclass).to eq(Gitlab::View::Presenter::Delegated)
|
|
|
|
end
|
2018-07-30 11:05:50 -04:00
|
|
|
|
2021-10-04 14:12:46 -04:00
|
|
|
describe '#callout_failure_message' do
|
|
|
|
subject { presenter.callout_failure_message }
|
|
|
|
|
|
|
|
context 'when troubleshooting doc is available' do
|
|
|
|
let(:failure_reason) { :environment_creation_failure }
|
|
|
|
|
|
|
|
before do
|
|
|
|
build.failure_reason = failure_reason
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appends the troubleshooting link' do
|
|
|
|
doc = described_class::TROUBLESHOOTING_DOC[failure_reason]
|
|
|
|
|
|
|
|
expect(subject).to eq("#{described_class.callout_failure_messages[failure_reason]} " \
|
|
|
|
"<a href=\"#{presenter.help_page_path(doc[:path], anchor: doc[:anchor])}\">How do I fix it?</a>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-30 11:05:50 -04:00
|
|
|
describe 'covers all failure reasons' do
|
|
|
|
let(:message) { presenter.callout_failure_message }
|
|
|
|
|
|
|
|
CommitStatus.failure_reasons.keys.each do |failure_reason|
|
|
|
|
context failure_reason do
|
|
|
|
before do
|
|
|
|
build.failure_reason = failure_reason
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is a valid status" do
|
|
|
|
expect { message }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'invalid failure message' do
|
|
|
|
before do
|
|
|
|
expect(build).to receive(:failure_reason) { 'invalid failure message' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is an invalid status" do
|
|
|
|
expect { message }.to raise_error(/key not found:/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-05-16 16:58:20 -04:00
|
|
|
end
|