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

66 lines
1.8 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe PaginatedDiffEntity do
2019-12-21 20:55:43 +05:30
let(:user) { create(:user) }
let(:request) { double('request', current_user: user) }
2021-03-11 19:13:27 +05:30
let(:merge_request) { create(:merge_request) }
2019-12-21 20:55:43 +05:30
let(:diff_batch) { merge_request.merge_request_diff.diffs_in_batch(2, 3, diff_options: nil) }
let(:options) do
{
request: request,
merge_request: merge_request,
2023-03-17 16:20:25 +05:30
pagination_data: diff_batch.pagination_data
2019-12-21 20:55:43 +05:30
}
end
2020-10-24 23:57:45 +05:30
2019-12-21 20:55:43 +05:30
let(:entity) { described_class.new(diff_batch, options) }
subject { entity.as_json }
it 'exposes diff_files' do
expect(subject[:diff_files]).to be_present
end
it 'exposes pagination data' do
2021-09-30 23:02:18 +05:30
expect(subject[:pagination]).to eq(total_pages: 20)
2019-12-21 20:55:43 +05:30
end
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
describe 'diff_files' do
let(:diff_files) { diff_batch.diff_files(sorted: true) }
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
it 'serializes diff files using DiffFileEntity' do
expect(DiffFileEntity)
.to receive(:represent)
.with(
diff_files,
hash_including(options.merge(conflicts: nil))
)
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
subject[:diff_files]
2021-01-29 00:20:46 +05:30
end
2023-03-17 16:20:25 +05:30
context 'when there are conflicts' do
2023-01-13 00:05:48 +05:30
let(:conflict_file) { double(path: diff_files.first.new_path, conflict_type: :both_modified) }
let(:conflicts) { double(conflicts: double(files: [conflict_file]), can_be_resolved_in_ui?: false) }
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
before do
allow(merge_request).to receive(:cannot_be_merged?).and_return(true)
allow(MergeRequests::Conflicts::ListService).to receive(:new).and_return(conflicts)
2021-01-29 00:20:46 +05:30
end
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
it 'serializes diff files with conflicts' do
expect(DiffFileEntity)
.to receive(:represent)
.with(
diff_files,
hash_including(options.merge(conflicts: { conflict_file.path => conflict_file }))
)
2021-10-27 15:23:28 +05:30
2023-01-13 00:05:48 +05:30
subject[:diff_files]
2021-10-27 15:23:28 +05:30
end
2021-01-29 00:20:46 +05:30
end
end
2019-12-21 20:55:43 +05:30
end