2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::DataBuilder::Note do
|
2017-01-24 18:42:12 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-03-05 13:38:23 -05:00
|
|
|
let(:user) { create(:user) }
|
2016-08-12 03:16:14 -04:00
|
|
|
let(:data) { described_class.build(note, user) }
|
2015-03-05 13:38:23 -05:00
|
|
|
let(:fixed_time) { Time.at(1425600000) } # Avoid time precision errors
|
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
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-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on commit' do
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
let(:note) { create(:note_on_commit, project: project) }
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
it 'returns the note and commit-specific data' do
|
|
|
|
expect(data).to have_key(:commit)
|
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on commit diff' do
|
2016-06-20 13:20:39 -04:00
|
|
|
let(:note) { create(:diff_note_on_commit, project: project) }
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
it 'returns the note and commit-specific data' do
|
|
|
|
expect(data).to have_key(:commit)
|
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on issue' do
|
2019-06-19 09:17:08 -04:00
|
|
|
let(:label) { create(:label, project: project) }
|
|
|
|
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:issue) do
|
2019-06-19 09:17:08 -04:00
|
|
|
create(:labeled_issue, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
project: project, labels: [label])
|
2016-04-26 07:52:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-05-18 13:38:52 -04:00
|
|
|
create(:note_on_issue, noteable: issue, project: project)
|
2016-04-26 07:52:18 -04:00
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
it 'returns the note and issue-specific data' do
|
2022-03-31 11:08:32 -04:00
|
|
|
expect_next_instance_of(Gitlab::HookData::IssueBuilder) do |issue_data_builder|
|
|
|
|
expect(issue_data_builder).to receive(:build).and_return('Issue data')
|
|
|
|
end
|
2019-06-19 09:17:08 -04:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
expect(data[:issue]).to eq('Issue data')
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
2018-04-03 07:00:33 -04:00
|
|
|
context 'with confidential issue' do
|
|
|
|
let(:issue) { create(:issue, project: project, confidential: true) }
|
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2018-04-03 07:00:33 -04:00
|
|
|
it 'sets event_type to confidential_note' do
|
|
|
|
expect(data[:event_type]).to eq('confidential_note')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request' do
|
2022-03-31 11:08:32 -04:00
|
|
|
let(:label) { create(:label, project: project) }
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:merge_request) do
|
2022-03-31 11:08:32 -04:00
|
|
|
create(:labeled_merge_request, created_at: fixed_time,
|
2016-04-26 07:52:18 -04:00
|
|
|
updated_at: fixed_time,
|
2022-03-31 11:08:32 -04:00
|
|
|
source_project: project,
|
|
|
|
labels: [label])
|
2016-04-26 07:52:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-05-18 13:38:52 -04:00
|
|
|
create(:note_on_merge_request, noteable: merge_request,
|
2016-04-26 07:52:18 -04:00
|
|
|
project: project)
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
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-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request diff' do
|
2022-03-31 11:08:32 -04:00
|
|
|
let(:label) { create(:label, project: project) }
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:merge_request) do
|
2022-03-31 11:08:32 -04:00
|
|
|
create(:labeled_merge_request, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
source_project: project,
|
|
|
|
labels: [label])
|
2016-04-26 07:52:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
2016-06-20 13:20:39 -04:00
|
|
|
create(:diff_note_on_merge_request, noteable: merge_request,
|
2016-04-26 07:52:18 -04:00
|
|
|
project: project)
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
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-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'When asking for a note on project snippet' do
|
2016-04-26 07:52:18 -04:00
|
|
|
let!(:snippet) do
|
|
|
|
create(:project_snippet, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:note) do
|
2016-05-18 13:38:52 -04:00
|
|
|
create(:note_on_project_snippet, noteable: snippet,
|
2016-04-26 07:52:18 -04:00
|
|
|
project: project)
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2022-03-31 11:08:32 -04:00
|
|
|
it_behaves_like 'includes general data'
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
it 'returns the note and project snippet data' do
|
|
|
|
expect(data).to have_key(:snippet)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:snippet].except('updated_at'))
|
2020-01-16 13:08:46 -05:00
|
|
|
.to eq(snippet.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:snippet]['updated_at'])
|
2018-06-27 12:25:25 -04:00
|
|
|
.to be >= snippet.hook_attrs['updated_at']
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
Add new data to project in push, issue, merge-request and note webhooks data
- Add `avatar_url`, `description`, `git_ssh_url`, `git_http_url`,
`path_with_namespace` and `default_branch` in `project` in push, issue,
merge-request and note webhooks data
- Deprecate the `ssh_url` in favor of `git_ssh_url` and `http_url` in
favor of `git_http_url` in `project` for push, issue, merge-request and
note webhooks data
- Deprecate the `repository` key in push, issue, merge-request and
note webhooks data, use `project` instead
2016-02-06 09:20:21 -05:00
|
|
|
|
|
|
|
include_examples 'project hook data'
|
|
|
|
include_examples 'deprecated repository hook data'
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
end
|