2019-11-24 07:06:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-05 13:02:50 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::HookData::IssueBuilder do
|
2020-02-20 13:08:51 -05:00
|
|
|
let_it_be(:label) { create(:label) }
|
|
|
|
let_it_be(:issue) { create(:labeled_issue, labels: [label], project: label.project) }
|
2021-04-12 08:09:15 -04:00
|
|
|
|
2017-10-05 13:02:50 -04:00
|
|
|
let(:builder) { described_class.new(issue) }
|
|
|
|
|
|
|
|
describe '#build' do
|
|
|
|
let(:data) { builder.build }
|
|
|
|
|
|
|
|
it 'includes safe attribute' do
|
|
|
|
%w[
|
|
|
|
assignee_id
|
|
|
|
author_id
|
|
|
|
closed_at
|
|
|
|
confidential
|
|
|
|
created_at
|
|
|
|
description
|
2020-03-30 05:07:58 -04:00
|
|
|
discussion_locked
|
2017-10-05 13:02:50 -04:00
|
|
|
due_date
|
|
|
|
id
|
|
|
|
iid
|
|
|
|
last_edited_at
|
|
|
|
last_edited_by_id
|
|
|
|
milestone_id
|
|
|
|
moved_to_id
|
2019-09-13 09:26:31 -04:00
|
|
|
duplicated_to_id
|
2017-10-05 13:02:50 -04:00
|
|
|
project_id
|
|
|
|
relative_position
|
2019-10-18 07:11:44 -04:00
|
|
|
state_id
|
2017-10-05 13:02:50 -04:00
|
|
|
time_estimate
|
|
|
|
title
|
|
|
|
updated_at
|
|
|
|
updated_by_id
|
|
|
|
].each do |key|
|
|
|
|
expect(data).to include(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes additional attrs' do
|
|
|
|
expect(data).to include(:total_time_spent)
|
2021-06-11 05:09:58 -04:00
|
|
|
expect(data).to include(:time_change)
|
2017-10-05 13:02:50 -04:00
|
|
|
expect(data).to include(:human_time_estimate)
|
|
|
|
expect(data).to include(:human_total_time_spent)
|
2021-06-11 05:09:58 -04:00
|
|
|
expect(data).to include(:human_time_change)
|
2017-10-05 13:02:50 -04:00
|
|
|
expect(data).to include(:assignee_ids)
|
2019-10-18 07:11:44 -04:00
|
|
|
expect(data).to include(:state)
|
2021-07-01 14:07:29 -04:00
|
|
|
expect(data).to include(:severity)
|
2019-06-19 09:17:08 -04:00
|
|
|
expect(data).to include('labels' => [label.hook_attrs])
|
2017-10-05 13:02:50 -04:00
|
|
|
end
|
2016-08-25 13:05:59 -04:00
|
|
|
|
|
|
|
context 'when the issue has an image in the description' do
|
|
|
|
let(:issue_with_description) { create(:issue, description: 'test![Issue_Image](/uploads/abc/Issue_Image.png)') }
|
|
|
|
let(:builder) { described_class.new(issue_with_description) }
|
|
|
|
|
2018-04-10 08:55:51 -04:00
|
|
|
it 'sets the image to use an absolute URL' do
|
2018-10-15 06:42:15 -04:00
|
|
|
expected_path = "#{issue_with_description.project.path_with_namespace}/uploads/abc/Issue_Image.png"
|
|
|
|
|
|
|
|
expect(data[:description])
|
|
|
|
.to eq("test![Issue_Image](#{Settings.gitlab.url}/#{expected_path})")
|
2016-08-25 13:05:59 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-05 13:02:50 -04:00
|
|
|
end
|
|
|
|
end
|