2019-09-30 09:06:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-22 10:46:02 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 06:09:01 +00:00
|
|
|
RSpec.describe AnalyticsSummarySerializer do
|
2017-01-27 12:02:59 +00:00
|
|
|
subject do
|
|
|
|
described_class.new.represent(resource)
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
|
|
|
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-12-01 14:40:46 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-01-27 12:02:59 +00:00
|
|
|
|
2016-12-01 14:40:46 +00:00
|
|
|
let(:resource) do
|
2017-01-27 12:02:59 +00:00
|
|
|
Gitlab::CycleAnalytics::Summary::Issue
|
2021-06-14 12:10:13 +00:00
|
|
|
.new(project: double, options: { from: 1.day.ago }, current_user: user)
|
2016-12-01 14:40:46 +00:00
|
|
|
end
|
2016-11-22 10:46:02 +00:00
|
|
|
|
|
|
|
before do
|
2019-12-16 12:07:43 +00:00
|
|
|
allow_next_instance_of(Gitlab::CycleAnalytics::Summary::Issue) do |instance|
|
|
|
|
allow(instance).to receive(:value).and_return(1.12)
|
|
|
|
end
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
|
|
|
|
2019-04-05 08:43:27 +00:00
|
|
|
it 'generates payload for single object' do
|
2017-01-27 12:02:59 +00:00
|
|
|
expect(subject).to be_kind_of Hash
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains important elements of AnalyticsStage' do
|
2017-01-27 12:02:59 +00:00
|
|
|
expect(subject).to include(:title, :value)
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
2020-04-08 12:09:42 +00:00
|
|
|
|
|
|
|
it 'does not include unit' do
|
|
|
|
expect(subject).not_to include(:unit)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when representing with unit' do
|
2020-04-21 15:21:10 +00:00
|
|
|
let(:resource) do
|
|
|
|
Gitlab::CycleAnalytics::Summary::DeploymentFrequency
|
2021-10-29 12:14:45 +00:00
|
|
|
.new(deployments: 10, options: { from: 1.day.ago }, project: project)
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
2020-04-08 12:09:42 +00:00
|
|
|
|
|
|
|
subject { described_class.new.represent(resource, with_unit: true) }
|
|
|
|
|
|
|
|
it 'contains unit' do
|
|
|
|
expect(subject).to include(:unit)
|
|
|
|
end
|
|
|
|
end
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|