Commit 0582b70a authored by Albert Salim's avatar Albert Salim

Present pipeline coverage in pipeline API entity as string

Also fixed existing test gap that should have
failed when `Pipeline#coverage` method changed.

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/76299
parent 46b80182
......@@ -10,7 +10,9 @@ module API
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration
expose :queued_duration
expose :coverage
expose :coverage do |pipeline|
pipeline.present.coverage
end
expose :detailed_status, using: DetailedStatusEntity do |pipeline, options|
pipeline.detailed_status(options[:current_user])
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::Ci::Pipeline do
let_it_be(:pipeline) { create(:ci_empty_pipeline) }
let_it_be(:job) { create(:ci_build, name: "rspec", coverage: 30.212, pipeline: pipeline) }
let(:entity) { described_class.new(pipeline) }
subject { entity.as_json }
it 'returns the coverage as a string' do
expect(subject[:coverage]).to eq '30.21'
end
end
......@@ -840,7 +840,7 @@ RSpec.describe API::Ci::Pipelines do
it 'exposes the coverage' do
get api("/projects/#{project.id}/pipelines/#{pipeline.id}", user)
expect(json_response["coverage"].to_i).to eq(30)
expect(json_response["coverage"]).to eq('30.00')
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment