2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-14 05:52:29 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe AnalyticsBuildEntity do
|
2016-11-14 05:52:29 -05:00
|
|
|
let(:entity) do
|
|
|
|
described_class.new(build, request: double)
|
|
|
|
end
|
|
|
|
|
2016-11-15 03:39:45 -05:00
|
|
|
context 'build with an author' do
|
2016-11-14 08:53:06 -05:00
|
|
|
let(:user) { create(:user) }
|
2016-11-24 06:38:54 -05:00
|
|
|
let(:started_at) { 2.hours.ago }
|
|
|
|
let(:finished_at) { 1.hour.ago }
|
|
|
|
let(:build) { create(:ci_build, author: user, started_at: started_at, finished_at: finished_at) }
|
2016-11-14 05:52:29 -05:00
|
|
|
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
2017-08-11 06:36:03 -04:00
|
|
|
around do |example|
|
2020-08-31 11:10:41 -04:00
|
|
|
freeze_time { example.run }
|
2016-12-14 02:49:32 -05:00
|
|
|
end
|
|
|
|
|
2016-11-15 03:39:45 -05:00
|
|
|
it 'contains the URL' do
|
|
|
|
expect(subject).to include(:url)
|
2016-11-14 05:52:29 -05:00
|
|
|
end
|
|
|
|
|
2016-11-14 08:53:06 -05:00
|
|
|
it 'contains the author' do
|
|
|
|
expect(subject).to include(:author)
|
|
|
|
end
|
|
|
|
|
2016-11-14 05:52:29 -05:00
|
|
|
it 'does not contain sensitive information' do
|
|
|
|
expect(subject).not_to include(/token/)
|
|
|
|
expect(subject).not_to include(/variables/)
|
|
|
|
end
|
2016-11-22 09:05:37 -05:00
|
|
|
|
|
|
|
it 'contains the right started at' do
|
|
|
|
expect(subject[:date]).to eq('about 2 hours ago')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains the duration' do
|
2016-11-22 10:30:27 -05:00
|
|
|
expect(subject[:total_time]).to eq(hours: 1 )
|
2016-11-22 09:05:37 -05:00
|
|
|
end
|
2016-11-24 06:38:54 -05:00
|
|
|
|
|
|
|
context 'no started at or finished at date' do
|
|
|
|
let(:started_at) { nil }
|
|
|
|
let(:finished_at) { nil }
|
|
|
|
|
|
|
|
it 'does not blow up' do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { subject[:date] }.not_to raise_error
|
2016-11-24 06:38:54 -05:00
|
|
|
end
|
|
|
|
|
2016-11-25 05:22:44 -05:00
|
|
|
it 'shows the right message' do
|
|
|
|
expect(subject[:date]).to eq('Not started')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the right total time' do
|
|
|
|
expect(subject[:total_time]).to eq({})
|
|
|
|
end
|
2016-11-24 06:38:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no started at date' do
|
|
|
|
let(:started_at) { nil }
|
|
|
|
|
|
|
|
it 'does not blow up' do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { subject[:date] }.not_to raise_error
|
2016-11-24 06:38:54 -05:00
|
|
|
end
|
2016-11-25 05:22:44 -05:00
|
|
|
|
|
|
|
it 'shows the right message' do
|
|
|
|
expect(subject[:date]).to eq('Not started')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the right total time' do
|
|
|
|
expect(subject[:total_time]).to eq({})
|
|
|
|
end
|
2016-11-24 06:38:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no finished at date' do
|
|
|
|
let(:finished_at) { nil }
|
|
|
|
|
|
|
|
it 'does not blow up' do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { subject[:date] }.not_to raise_error
|
2016-11-24 06:38:54 -05:00
|
|
|
end
|
2016-11-25 05:22:44 -05:00
|
|
|
|
|
|
|
it 'shows the right message' do
|
|
|
|
expect(subject[:date]).to eq('about 2 hours ago')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the right total time' do
|
2016-11-25 05:46:13 -05:00
|
|
|
expect(subject[:total_time]).to eq({ hours: 2 })
|
2016-11-25 05:22:44 -05:00
|
|
|
end
|
2016-11-24 06:38:54 -05:00
|
|
|
end
|
2016-11-14 05:52:29 -05:00
|
|
|
end
|
|
|
|
end
|