2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::DataBuilder::Note do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2015-04-26 12:48:37 +05:30
|
|
|
let(:user) { create(:user) }
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:data) { described_class.build(note, user) }
|
2015-04-26 12:48:37 +05:30
|
|
|
let(:fixed_time) { Time.at(1425600000) } # Avoid time precision errors
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
shared_examples 'includes general data' do
|
|
|
|
specify do
|
|
|
|
expect(data).to have_key(:object_attributes)
|
|
|
|
expect(data[:object_attributes]).to have_key(:url)
|
|
|
|
expect(data[:object_attributes][:url])
|
|
|
|
.to eq(Gitlab::UrlBuilder.build(note))
|
|
|
|
expect(data[:object_kind]).to eq('note')
|
|
|
|
expect(data[:user]).to eq(user.hook_attrs)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on commit' do
|
2016-04-02 18:10:28 +05:30
|
|
|
let(:note) { create(:note_on_commit, project: project) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'returns the note and commit-specific data' do
|
|
|
|
expect(data).to have_key(:commit)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on commit diff' do
|
2016-08-24 12:49:21 +05:30
|
|
|
let(:note) { create(:diff_note_on_commit, project: project) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'returns the note and commit-specific data' do
|
|
|
|
expect(data).to have_key(:commit)
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on issue' do
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:label) { create(:label, project: project) }
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
let(:issue) do
|
2019-09-04 21:01:54 +05:30
|
|
|
create(:labeled_issue, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
project: project, labels: [label])
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
|
|
|
create(:note_on_issue, noteable: issue, project: project)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'returns the note and issue-specific data' do
|
2022-06-21 17:19:12 +05:30
|
|
|
expect_next_instance_of(Gitlab::HookData::IssueBuilder) do |issue_data_builder|
|
|
|
|
expect(issue_data_builder).to receive(:build).and_return('Issue data')
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(data[:issue]).to eq('Issue data')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2018-04-05 14:03:07 +05:30
|
|
|
context 'with confidential issue' do
|
|
|
|
let(:issue) { create(:issue, project: project, confidential: true) }
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2018-04-05 14:03:07 +05:30
|
|
|
it 'sets event_type to confidential_note' do
|
|
|
|
expect(data[:event_type]).to eq('confidential_note')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request' do
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:label) { create(:label, project: project) }
|
2016-06-16 23:09:34 +05:30
|
|
|
let(:merge_request) do
|
2022-06-21 17:19:12 +05:30
|
|
|
create(:labeled_merge_request, created_at: fixed_time,
|
2016-06-16 23:09:34 +05:30
|
|
|
updated_at: fixed_time,
|
2022-06-21 17:19:12 +05:30
|
|
|
source_project: project,
|
|
|
|
labels: [label])
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
|
|
|
create(:note_on_merge_request, noteable: merge_request,
|
|
|
|
project: project)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
|
|
|
it 'returns the merge request data' do
|
|
|
|
expect_next_instance_of(Gitlab::HookData::MergeRequestBuilder) do |mr_data_builder|
|
|
|
|
expect(mr_data_builder).to receive(:build).and_return('MR data')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(data[:merge_request]).to eq('MR data')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request diff' do
|
2022-06-21 17:19:12 +05:30
|
|
|
let(:label) { create(:label, project: project) }
|
2016-06-16 23:09:34 +05:30
|
|
|
let(:merge_request) do
|
2022-06-21 17:19:12 +05:30
|
|
|
create(:labeled_merge_request, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
source_project: project,
|
|
|
|
labels: [label])
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-08-24 12:49:21 +05:30
|
|
|
create(:diff_note_on_merge_request, noteable: merge_request,
|
2016-06-16 23:09:34 +05:30
|
|
|
project: project)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
|
|
|
it 'returns the merge request data' do
|
|
|
|
expect_next_instance_of(Gitlab::HookData::MergeRequestBuilder) do |mr_data_builder|
|
|
|
|
expect(mr_data_builder).to receive(:build).and_return('MR data')
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(data[:merge_request]).to eq('MR data')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on project snippet' do
|
2016-06-16 23:09:34 +05:30
|
|
|
let!(:snippet) do
|
|
|
|
create(:project_snippet, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:note) do
|
|
|
|
create(:note_on_project_snippet, noteable: snippet,
|
|
|
|
project: project)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
it 'returns the note and project snippet data' do
|
|
|
|
expect(data).to have_key(:snippet)
|
2016-06-16 23:09:34 +05:30
|
|
|
expect(data[:snippet].except('updated_at'))
|
2020-03-13 15:44:24 +05:30
|
|
|
.to eq(snippet.hook_attrs.except('updated_at'))
|
2016-06-16 23:09:34 +05:30
|
|
|
expect(data[:snippet]['updated_at'])
|
2018-11-08 19:23:39 +05:30
|
|
|
.to be >= snippet.hook_attrs['updated_at']
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|