2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe DiscussionEntity do
|
2018-03-27 19:54:05 +05:30
|
|
|
include RepoHelpers
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
let(:note) { create(:discussion_note_on_merge_request, project: project) }
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:discussion) { note.discussion }
|
2018-05-09 12:01:36 +05:30
|
|
|
let(:request) { double('request', note_entity: ProjectNoteEntity) }
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:controller) { double('controller') }
|
|
|
|
let(:entity) { described_class.new(discussion, request: request, context: controller) }
|
|
|
|
|
|
|
|
subject { entity.as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:render_to_string)
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
allow(request).to receive(:noteable).and_return(note.noteable)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes correct attributes' do
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(subject.keys.sort).to include(
|
|
|
|
:diff_discussion,
|
|
|
|
:expanded,
|
|
|
|
:id,
|
|
|
|
:individual_note,
|
|
|
|
:notes,
|
|
|
|
:resolvable,
|
|
|
|
:resolve_path,
|
|
|
|
:resolve_with_issue_path,
|
|
|
|
:resolved,
|
|
|
|
:discussion_path,
|
|
|
|
:resolved_at,
|
|
|
|
:for_commit,
|
2020-04-22 19:07:51 +05:30
|
|
|
:commit_id,
|
|
|
|
:confidential
|
2018-03-27 19:54:05 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'does not include base discussion in the notes' do
|
|
|
|
expect(subject[:notes].first.keys).not_to include(:base_discussion)
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'resolved_by matches note_user_entity schema' do
|
|
|
|
Notes::ResolveService.new(note.project, user).execute(note)
|
|
|
|
|
|
|
|
expect(subject[:resolved_by].with_indifferent_access)
|
|
|
|
.to match_schema('entities/note_user_entity')
|
|
|
|
end
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
it 'exposes the url for custom award emoji' do
|
|
|
|
custom_emoji = create(:custom_emoji, group: group)
|
|
|
|
create(:award_emoji, awardable: note, name: custom_emoji.name)
|
|
|
|
|
|
|
|
expect(subject[:notes].last[:award_emoji].first.keys).to include(:url)
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
context 'when is LegacyDiffDiscussion' do
|
2022-07-16 23:28:13 +05:30
|
|
|
let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: note.noteable, project: project).to_discussion }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
it 'exposes correct attributes' do
|
|
|
|
expect(subject.keys.sort).to include(
|
|
|
|
:diff_discussion,
|
|
|
|
:expanded,
|
|
|
|
:id,
|
|
|
|
:individual_note,
|
|
|
|
:notes,
|
|
|
|
:discussion_path,
|
|
|
|
:for_commit,
|
|
|
|
:commit_id
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when diff file is present' do
|
|
|
|
let(:note) { create(:diff_note_on_merge_request) }
|
|
|
|
|
|
|
|
it 'exposes diff file attributes' do
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(subject.keys.sort).to include(
|
|
|
|
:diff_file,
|
|
|
|
:truncated_diff_lines,
|
|
|
|
:position,
|
2020-04-22 19:07:51 +05:30
|
|
|
:positions,
|
|
|
|
:line_codes,
|
2018-11-08 19:23:39 +05:30
|
|
|
:line_code,
|
|
|
|
:active
|
|
|
|
)
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|