debian-mirror-gitlab/spec/serializers/merge_requests/pipeline_entity_spec.rb

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

55 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MergeRequests::PipelineEntity do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
2023-01-13 00:05:48 +05:30
let_it_be(:pipeline) { create(:ci_pipeline, project: project, name: 'Build pipeline') }
2020-10-24 23:57:45 +05:30
let(:request) { double('request') }
before do
stub_not_protect_default_branch
allow(request).to receive(:current_user).and_return(user)
allow(request).to receive(:project).and_return(project)
2022-01-26 12:08:38 +05:30
allow(pipeline).to receive(:coverage).and_return(35.0)
2020-10-24 23:57:45 +05:30
end
let(:entity) do
described_class.represent(pipeline, request: request)
end
subject { entity.as_json }
describe '#as_json' do
it 'contains required fields' do
2023-01-13 00:05:48 +05:30
allow(pipeline).to receive(:merge_request_event_type).and_return(:merged_result)
2020-10-24 23:57:45 +05:30
is_expected.to include(
:id, :path, :active, :coverage, :ref, :commit, :details,
2023-01-13 00:05:48 +05:30
:flags, :triggered, :triggered_by, :name
2020-10-24 23:57:45 +05:30
)
expect(subject[:commit]).to include(:short_id, :commit_path)
expect(subject[:ref]).to include(:branch)
2023-04-23 21:23:45 +05:30
expect(subject[:details]).to include(:artifacts, :event_type_name, :status, :stages, :finished_at)
2020-10-24 23:57:45 +05:30
expect(subject[:details][:status]).to include(:icon, :favicon, :text, :label, :tooltip)
expect(subject[:flags]).to include(:merge_request_pipeline)
2023-01-13 00:05:48 +05:30
expect(subject[:details][:event_type_name]).to eq('Merged result pipeline')
2020-10-24 23:57:45 +05:30
end
2022-01-26 12:08:38 +05:30
it 'returns presented coverage' do
expect(subject[:coverage]).to eq('35.00')
end
2020-10-24 23:57:45 +05:30
it 'excludes coverage data when disabled' do
entity = described_class
.represent(pipeline, request: request, disable_coverage: true)
expect(entity.as_json).not_to include(:coverage)
end
end
end