2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe MergeRequestSerializer do
|
2020-02-24 22:08:49 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:resource) { create(:merge_request, description: "Description") }
|
2019-09-06 11:49:13 -04:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
let(:json_entity) do
|
2017-05-09 00:15:34 -04:00
|
|
|
described_class.new(current_user: user)
|
2017-12-07 16:56:59 -05:00
|
|
|
.represent(resource, serializer: serializer)
|
|
|
|
.with_indifferent_access
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
context 'widget merge request serialization' do
|
|
|
|
let(:serializer) { 'widget' }
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
it 'matches issue json schema' do
|
|
|
|
expect(json_entity).to match_schema('entities/merge_request_widget')
|
|
|
|
end
|
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
context 'sidebar merge request serialization' do
|
2018-11-29 22:16:40 -05:00
|
|
|
let(:serializer) { 'sidebar' }
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2018-11-29 22:16:40 -05:00
|
|
|
it 'matches merge_request_sidebar json schema' do
|
2018-11-27 03:47:10 -05:00
|
|
|
expect(json_entity).to match_schema('entities/merge_request_sidebar')
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
2017-12-07 16:56:59 -05:00
|
|
|
end
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2018-11-29 22:16:40 -05:00
|
|
|
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')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
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-05-09 00:15:34 -04:00
|
|
|
|
2019-08-28 17:09:22 -04:00
|
|
|
context 'noteable merge request serialization' do
|
|
|
|
let(:serializer) { 'noteable' }
|
|
|
|
|
|
|
|
it 'matches noteable merge request json schema' do
|
2019-12-13 19:08:27 -05:00
|
|
|
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-08-28 17:09:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
context 'poll cached widget merge request serialization' do
|
|
|
|
let(:serializer) { 'poll_cached_widget' }
|
|
|
|
|
|
|
|
it 'matches basic merge request json schema' do
|
|
|
|
expect(json_entity).to match_schema('entities/merge_request_poll_cached_widget')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'poll widget merge request serialization' do
|
|
|
|
let(:serializer) { 'poll_widget' }
|
|
|
|
|
|
|
|
it 'matches basic merge request json schema' do
|
|
|
|
expect(json_entity).to match_schema('entities/merge_request_poll_widget')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-07 16:56:59 -05:00
|
|
|
context 'no serializer' do
|
|
|
|
let(:serializer) { nil }
|
2017-05-09 00:15:34 -04:00
|
|
|
|
2017-12-21 08:03:15 -05:00
|
|
|
it 'falls back to the widget entity' do
|
|
|
|
expect(json_entity).to match_schema('entities/merge_request_widget')
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|