2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Discussions::CaptureDiffNotePositionService do
|
2020-05-05 14:28:15 +05:30
|
|
|
subject { described_class.new(note.noteable, paths) }
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'image note on diff' do
|
|
|
|
let!(:note) { create(:image_diff_note_on_merge_request) }
|
2020-05-05 14:28:15 +05:30
|
|
|
let(:paths) { ['files/images/any_image.png'] }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
it 'is note affected by the service' do
|
|
|
|
expect(Gitlab::Diff::PositionTracer).not_to receive(:new)
|
|
|
|
|
|
|
|
expect(subject.execute(note.discussion)).to eq(nil)
|
|
|
|
expect(note.diff_note_positions).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when empty paths are passed as a param' do
|
|
|
|
let!(:note) { create(:diff_note_on_merge_request) }
|
2020-05-05 14:28:15 +05:30
|
|
|
let(:paths) { [] }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
it 'does not calculate positons' do
|
|
|
|
expect(Gitlab::Diff::PositionTracer).not_to receive(:new)
|
|
|
|
|
|
|
|
expect(subject.execute(note.discussion)).to eq(nil)
|
|
|
|
expect(note.diff_note_positions).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2020-05-05 14:28:15 +05:30
|
|
|
|
|
|
|
context 'when position tracer returned nil position' do
|
|
|
|
let!(:note) { create(:diff_note_on_merge_request) }
|
|
|
|
let(:paths) { ['files/any_file.txt'] }
|
|
|
|
|
|
|
|
it 'does not create diff note position' do
|
|
|
|
expect(note.noteable).to receive(:merge_ref_head).and_return(double.as_null_object)
|
|
|
|
expect_next_instance_of(Gitlab::Diff::PositionTracer) do |tracer|
|
|
|
|
expect(tracer).to receive(:trace).and_return({ position: nil })
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(subject.execute(note.discussion)).to eq(nil)
|
|
|
|
expect(note.diff_note_positions).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|