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

80 lines
2.3 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 MergeRequestSerializer do
2020-04-08 14:13:33 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:resource) { create(:merge_request, description: "Description") }
2019-12-04 20:38:33 +05:30
2018-03-17 18:26:18 +05:30
let(:json_entity) do
2017-08-17 22:00:37 +05:30
described_class.new(current_user: user)
2018-03-17 18:26:18 +05:30
.represent(resource, serializer: serializer)
.with_indifferent_access
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
context 'widget merge request serialization' do
let(:serializer) { 'widget' }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'matches issue json schema' do
expect(json_entity).to match_schema('entities/merge_request_widget')
end
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
context 'sidebar merge request serialization' do
let(:serializer) { 'sidebar' }
2017-08-17 22:00:37 +05:30
2019-02-15 15:39:39 +05:30
it 'matches merge_request_sidebar json schema' do
expect(json_entity).to match_schema('entities/merge_request_sidebar')
end
end
context 'sidebar_extras merge request serialization' do
let(:serializer) { 'sidebar_extras' }
it 'matches merge_request_sidebar_extras json schema' do
expect(json_entity).to match_schema('entities/merge_request_sidebar_extras')
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
context 'basic merge request serialization' do
let(:serializer) { 'basic' }
it 'matches basic merge request json schema' do
expect(json_entity).to match_schema('entities/merge_request_basic')
end
end
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
context 'noteable merge request serialization' do
let(:serializer) { 'noteable' }
it 'matches noteable merge request json schema' do
2020-01-01 13:55:28 +05:30
expect(json_entity).to match_schema('entities/merge_request_noteable')
end
context 'when merge_request is locked' do
let(:resource) { create(:merge_request, :locked, description: "Description") }
it 'matches noteable merge request json schema' do
expect(json_entity).to match_schema('entities/merge_request_noteable')
end
end
context 'when project is archived' do
let(:project) { create(:project, :archived, :repository) }
let(:resource) { create(:merge_request, source_project: project, target_project: project, description: "Description") }
it 'matches noteable merge request json schema' do
expect(json_entity).to match_schema('entities/merge_request_noteable')
end
2019-12-04 20:38:33 +05:30
end
end
2018-03-17 18:26:18 +05:30
context 'no serializer' do
let(:serializer) { nil }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'falls back to the widget entity' do
expect(json_entity).to match_schema('entities/merge_request_widget')
2017-08-17 22:00:37 +05:30
end
end
end