debian-mirror-gitlab/spec/serializers/analytics_stage_serializer_spec.rb

57 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe AnalyticsStageSerializer do
subject do
described_class.new.represent(resource)
end
let(:resource) do
2019-10-12 21:52:04 +05:30
Gitlab::CycleAnalytics::CodeStage.new(options: { project: double })
2017-08-17 22:00:37 +05:30
end
before do
2019-10-12 21:52:04 +05:30
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:project_median).and_return(1.12)
2017-08-17 22:00:37 +05:30
allow_any_instance_of(Gitlab::CycleAnalytics::BaseEventFetcher).to receive(:event_result).and_return({})
end
2019-07-07 11:18:12 +05:30
it 'generates payload for single object' do
2017-08-17 22:00:37 +05:30
expect(subject).to be_kind_of Hash
end
it 'contains important elements of AnalyticsStage' do
expect(subject).to include(:title, :description, :value)
end
2019-09-04 21:01:54 +05:30
context 'when median is equal 0' do
before do
2019-10-12 21:52:04 +05:30
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:project_median).and_return(0)
2019-09-04 21:01:54 +05:30
end
it 'sets the value to nil' do
expect(subject.fetch(:value)).to be_nil
end
end
context 'when median is below 1' do
before do
2019-10-12 21:52:04 +05:30
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:project_median).and_return(0.12)
2019-09-04 21:01:54 +05:30
end
it 'sets the value to equal to median' do
expect(subject.fetch(:value)).to eq('less than a minute')
end
end
context 'when median is above 1' do
before do
2019-10-12 21:52:04 +05:30
allow_any_instance_of(Gitlab::CycleAnalytics::BaseStage).to receive(:project_median).and_return(60.12)
2019-09-04 21:01:54 +05:30
end
it 'sets the value to equal to median' do
expect(subject.fetch(:value)).to eq('1 minute')
end
end
2017-08-17 22:00:37 +05:30
end