summaryrefslogtreecommitdiff
path: root/spec/serializers/analytics_build_entity_spec.rb
blob: c0b7e86b17cb3d0bf31cdf70fb21141bf4ff12a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'spec_helper'

describe AnalyticsBuildEntity do
  let(:entity) do
    described_class.new(build, request: double)
  end

  context 'build with an author' do
    let(:user) { create(:user) }
    let(:build) { create(:ci_build, author: user, started_at: 2.hours.ago, finished_at: 1.hour.ago) }

    subject { entity.as_json }

    it 'contains the URL' do
      expect(subject).to include(:url)
    end

    it 'contains the author' do
      expect(subject).to include(:author)
    end

    it 'does not contain sensitive information' do
      expect(subject).not_to include(/token/)
      expect(subject).not_to include(/variables/)
    end

    it 'contains the right started at' do
      expect(subject[:date]).to eq('about 2 hours ago')
    end

    it 'contains the duration' do
      expect(subject[:total_time]).to eq(hours: 1 )
    end
  end
end