debian-mirror-gitlab/spec/lib/gitlab/data_builder/note_spec.rb

149 lines
4.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
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
2018-03-17 18:26:18 +05:30
before do
2015-04-26 12:48:37 +05:30
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))
2015-04-26 12:48:37 +05:30
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
2016-04-02 18:10:28 +05:30
let(:note) { create(:note_on_commit, project: project) }
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
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) }
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])
end
let(:note) do
create(:note_on_issue, noteable: issue, project: project)
end
2015-04-26 12:48:37 +05:30
it 'returns the note and issue-specific data' do
2019-09-04 21:01:54 +05:30
without_timestamps = lambda { |label| label.except('created_at', 'updated_at') }
hook_attrs = issue.reload.hook_attrs
2015-04-26 12:48:37 +05:30
expect(data).to have_key(:issue)
2019-09-04 21:01:54 +05:30
expect(data[:issue].except('updated_at', 'labels'))
.to eq(hook_attrs.except('updated_at', 'labels'))
expect(data[:issue]['updated_at'])
2019-09-04 21:01:54 +05:30
.to be >= hook_attrs['updated_at']
expect(data[:issue]['labels'].map(&without_timestamps))
.to eq(hook_attrs['labels'].map(&without_timestamps))
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) }
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
let(:merge_request) do
create(:merge_request, created_at: fixed_time,
updated_at: fixed_time,
source_project: project)
end
let(:note) do
create(:note_on_merge_request, noteable: merge_request,
project: project)
end
2015-04-26 12:48:37 +05:30
it 'returns the note and merge request data' do
expect(data).to have_key(:merge_request)
expect(data[:merge_request].except('updated_at'))
.to eq(merge_request.reload.hook_attrs.except('updated_at'))
expect(data[:merge_request]['updated_at'])
2018-11-08 19:23:39 +05:30
.to be >= merge_request.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
describe 'When asking for a note on merge request diff' do
let(:merge_request) do
create(:merge_request, created_at: fixed_time, updated_at: fixed_time,
source_project: project)
end
let(:note) do
2016-08-24 12:49:21 +05:30
create(:diff_note_on_merge_request, noteable: merge_request,
project: project)
end
2015-04-26 12:48:37 +05:30
it 'returns the note and merge request diff data' do
expect(data).to have_key(:merge_request)
expect(data[:merge_request].except('updated_at'))
.to eq(merge_request.reload.hook_attrs.except('updated_at'))
expect(data[:merge_request]['updated_at'])
2018-11-08 19:23:39 +05:30
.to be >= merge_request.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
describe 'When asking for a note on project snippet' do
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
it 'returns the note and project snippet data' do
expect(data).to have_key(:snippet)
expect(data[:snippet].except('updated_at'))
2020-03-13 15:44:24 +05:30
.to eq(snippet.hook_attrs.except('updated_at'))
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