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