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
|
|
|
|
|
2017-08-10 18:31:42 -04:00
|
|
|
before do
|
2015-03-05 13:38:23 -05:00
|
|
|
expect(data).to have_key(:object_attributes)
|
|
|
|
expect(data[:object_attributes]).to have_key(:url)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:object_attributes][:url])
|
|
|
|
.to eq(Gitlab::UrlBuilder.build(note))
|
2015-03-05 13:38:23 -05:00
|
|
|
expect(data[:object_kind]).to eq('note')
|
|
|
|
expect(data[:user]).to eq(user.hook_attrs)
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
it 'returns the note and issue-specific data' do
|
2019-06-19 09:17:08 -04:00
|
|
|
without_timestamps = lambda { |label| label.except('created_at', 'updated_at') }
|
|
|
|
hook_attrs = issue.reload.hook_attrs
|
|
|
|
|
2015-03-05 13:38:23 -05:00
|
|
|
expect(data).to have_key(:issue)
|
2019-06-19 09:17:08 -04:00
|
|
|
expect(data[:issue].except('updated_at', 'labels'))
|
|
|
|
.to eq(hook_attrs.except('updated_at', 'labels'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:issue]['updated_at'])
|
2019-06-19 09:17:08 -04:00
|
|
|
.to be >= hook_attrs['updated_at']
|
|
|
|
expect(data[:issue]['labels'].map(&without_timestamps))
|
|
|
|
.to eq(hook_attrs['labels'].map(&without_timestamps))
|
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) }
|
|
|
|
|
|
|
|
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
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, created_at: fixed_time,
|
|
|
|
updated_at: fixed_time,
|
|
|
|
source_project: project)
|
|
|
|
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
|
|
|
|
|
|
|
it 'returns the note and merge request data' do
|
|
|
|
expect(data).to have_key(:merge_request)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request].except('updated_at'))
|
2016-05-18 13:38:52 -04:00
|
|
|
.to eq(merge_request.reload.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request]['updated_at'])
|
2018-06-27 12:25:25 -04:00
|
|
|
.to be >= merge_request.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
|
|
|
|
|
|
|
|
describe 'When asking for a note on merge request diff' do
|
2016-04-26 07:52:18 -04:00
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, created_at: fixed_time, updated_at: fixed_time,
|
|
|
|
source_project: project)
|
|
|
|
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
|
|
|
|
|
|
|
it 'returns the note and merge request diff data' do
|
|
|
|
expect(data).to have_key(:merge_request)
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request].except('updated_at'))
|
2016-05-18 13:38:52 -04:00
|
|
|
.to eq(merge_request.reload.hook_attrs.except('updated_at'))
|
2016-04-26 07:52:18 -04:00
|
|
|
expect(data[:merge_request]['updated_at'])
|
2018-06-27 12:25:25 -04:00
|
|
|
.to be >= merge_request.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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|