2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
RSpec.describe Ci::JobSerializer do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:serializer) do
|
|
|
|
described_class.new(current_user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { serializer.represent(resource) }
|
|
|
|
|
|
|
|
describe '#represent' do
|
|
|
|
context 'when a single object is being serialized' do
|
|
|
|
let(:resource) { create(:ci_build) }
|
|
|
|
|
|
|
|
it 'serializers the pipeline object' do
|
|
|
|
expect(subject[:id]).to eq resource.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when multiple objects are being serialized' do
|
|
|
|
let(:resource) { create_list(:ci_build, 2) }
|
|
|
|
|
|
|
|
it 'serializers the array of pipelines' do
|
|
|
|
expect(subject).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#represent_status' do
|
2018-05-09 12:01:36 +05:30
|
|
|
context 'for a failed build' do
|
|
|
|
let(:resource) { create(:ci_build, :failed) }
|
|
|
|
let(:status) { resource.detailed_status(double('user')) }
|
|
|
|
|
|
|
|
subject { serializer.represent_status(resource) }
|
|
|
|
|
|
|
|
it 'serializes only status' do
|
|
|
|
expect(subject[:text]).to eq(status.text)
|
|
|
|
expect(subject[:label]).to eq('failed')
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(subject[:tooltip]).to eq('failed - (unknown failure)')
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(subject[:icon]).to eq(status.icon)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(subject[:favicon]).to match_asset_path("/assets/ci_favicons/#{status.favicon}.png")
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for any other type of build' do
|
|
|
|
let(:resource) { create(:ci_build, :success) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:status) { resource.detailed_status(double('user')) }
|
|
|
|
|
|
|
|
subject { serializer.represent_status(resource) }
|
|
|
|
|
|
|
|
it 'serializes only status' do
|
|
|
|
expect(subject[:text]).to eq(status.text)
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(subject[:label]).to eq('passed')
|
|
|
|
expect(subject[:tooltip]).to eq('passed')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(subject[:icon]).to eq(status.icon)
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(subject[:favicon]).to match_asset_path("/assets/ci_favicons/#{status.favicon}.png")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|