Commit 61729204 authored by Shinya Maeda's avatar Shinya Maeda

Add spec for entity and serializer

parent 01914554
require 'spec_helper' require 'spec_helper'
describe BuildEntity do describe BuildEntity do
let(:user) { create(:user) }
let(:build) { create(:ci_build) } let(:build) { create(:ci_build) }
let(:request) { double('request') }
before do
allow(request).to receive(:user).and_return(user)
end
let(:entity) do let(:entity) do
described_class.new(build, request: double) described_class.new(build, request: request)
end end
subject { entity.as_json } subject { entity.as_json }
...@@ -22,6 +28,11 @@ describe BuildEntity do ...@@ -22,6 +28,11 @@ describe BuildEntity do
expect(subject).to include(:created_at, :updated_at) expect(subject).to include(:created_at, :updated_at)
end end
it 'contains details' do
expect(subject).to include :details
expect(subject[:details][:status]).to include :icon, :favicon, :text, :label
end
context 'when build is a regular job' do context 'when build is a regular job' do
it 'does not contain path to play action' do it 'does not contain path to play action' do
expect(subject).not_to include(:play_path) expect(subject).not_to include(:play_path)
......
require 'spec_helper'
describe BuildSerializer do
let(:user) { create(:user) }
let(:serializer) do
described_class.new(user: user)
end
subject { serializer.represent(resource) }
describe '#represent' do
context 'when used with status' do
let(:serializer) do
described_class.new(user: user)
.with_status
end
let(:resource) { create(:ci_build) }
it 'serializes only status' do
expect(subject[:details][:status]).not_to be_empty
expect(subject[:details].keys.count).to eq 1
end
end
end
end
...@@ -30,7 +30,7 @@ describe PipelineEntity do ...@@ -30,7 +30,7 @@ describe PipelineEntity do
.to include :duration, :finished_at .to include :duration, :finished_at
expect(subject[:details]) expect(subject[:details])
.to include :stages, :artifacts, :manual_actions .to include :stages, :artifacts, :manual_actions
expect(subject[:details][:status]).to include :icon, :text, :label expect(subject[:details][:status]).to include :icon, :favicon, :text, :label
end end
it 'contains flags' do it 'contains flags' do
......
...@@ -93,5 +93,18 @@ describe PipelineSerializer do ...@@ -93,5 +93,18 @@ describe PipelineSerializer do
end end
end end
end end
context 'when used with status' do
let(:serializer) do
described_class.new(user: user)
.with_status
end
let(:resource) { create(:ci_empty_pipeline) }
it 'serializes only status' do
expect(subject[:details][:status]).not_to be_empty
expect(subject[:details].keys.count).to eq 1
end
end
end end
end end
...@@ -16,7 +16,7 @@ describe StatusEntity do ...@@ -16,7 +16,7 @@ describe StatusEntity do
subject { entity.as_json } subject { entity.as_json }
it 'contains status details' do it 'contains status details' do
expect(subject).to include :text, :icon, :label, :group expect(subject).to include :text, :icon, :favicon, :label, :group
expect(subject).to include :has_details, :details_path expect(subject).to include :has_details, :details_path
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment