2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::HookData::MergeRequestBuilder do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:merge_request) { create(:merge_request) }
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:builder) { described_class.new(merge_request) }
|
|
|
|
|
|
|
|
describe '#build' do
|
|
|
|
let(:data) { builder.build }
|
|
|
|
|
|
|
|
it 'includes safe attribute' do
|
|
|
|
%w[
|
|
|
|
assignee_id
|
2019-07-31 22:56:46 +05:30
|
|
|
assignee_ids
|
2018-03-17 18:26:18 +05:30
|
|
|
author_id
|
|
|
|
created_at
|
|
|
|
description
|
|
|
|
head_pipeline_id
|
|
|
|
id
|
|
|
|
iid
|
|
|
|
last_edited_at
|
|
|
|
last_edited_by_id
|
|
|
|
merge_commit_sha
|
|
|
|
merge_error
|
|
|
|
merge_params
|
|
|
|
merge_status
|
|
|
|
merge_user_id
|
|
|
|
merge_when_pipeline_succeeds
|
|
|
|
milestone_id
|
|
|
|
source_branch
|
|
|
|
source_project_id
|
|
|
|
state
|
|
|
|
target_branch
|
|
|
|
target_project_id
|
|
|
|
time_estimate
|
|
|
|
title
|
|
|
|
updated_at
|
|
|
|
updated_by_id
|
|
|
|
].each do |key|
|
|
|
|
expect(data).to include(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%i[source target].each do |key|
|
|
|
|
describe "#{key} key" do
|
|
|
|
include_examples 'project hook data', project_key: key do
|
|
|
|
let(:project) { merge_request.public_send("#{key}_project") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes additional attrs' do
|
|
|
|
expect(data).to include(:source)
|
|
|
|
expect(data).to include(:target)
|
|
|
|
expect(data).to include(:last_commit)
|
|
|
|
expect(data).to include(:work_in_progress)
|
|
|
|
expect(data).to include(:total_time_spent)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(data).to include(:time_change)
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(data).to include(:human_time_estimate)
|
|
|
|
expect(data).to include(:human_total_time_spent)
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(data).to include(:human_time_change)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
context 'when the MR has an image in the description' do
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:mr_with_description) { create(:merge_request, description: 'test![MR_Image](/uploads/abc/MR_Image.png)') }
|
2018-11-18 11:00:15 +05:30
|
|
|
let(:builder) { described_class.new(mr_with_description) }
|
|
|
|
|
|
|
|
it 'sets the image to use an absolute URL' do
|
2018-12-13 13:39:08 +05:30
|
|
|
expected_path = "#{mr_with_description.project.path_with_namespace}/uploads/abc/MR_Image.png"
|
|
|
|
|
|
|
|
expect(data[:description])
|
|
|
|
.to eq("test![MR_Image](#{Settings.gitlab.url}/#{expected_path})")
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|