2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe HooksHelper do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:project) { build_stubbed(:project) }
|
|
|
|
let(:project_hook) { build_stubbed(:project_hook, project: project) }
|
|
|
|
let(:service_hook) { build_stubbed(:service_hook, integration: build_stubbed(:drone_ci_integration)) }
|
|
|
|
let(:system_hook) { build_stubbed(:system_hook) }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
describe '#webhook_form_data' do
|
|
|
|
subject { helper.webhook_form_data(project_hook) }
|
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
context 'when there are no URL variables' do
|
|
|
|
it 'returns proper data' do
|
|
|
|
expect(subject).to match(
|
|
|
|
url: project_hook.url,
|
|
|
|
url_variables: "[]"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are URL variables' do
|
|
|
|
let(:project_hook) { build_stubbed(:project_hook, :url_variables, project: project) }
|
|
|
|
|
|
|
|
it 'returns proper data' do
|
|
|
|
expect(subject).to match(
|
|
|
|
url: project_hook.url,
|
2023-04-23 21:23:45 +05:30
|
|
|
url_variables: Gitlab::Json.dump([{ key: 'abc' }])
|
2023-01-13 00:05:48 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
describe '#webhook_test_items' do
|
|
|
|
let(:triggers) { [:push_events, :note_events] }
|
|
|
|
|
|
|
|
it 'returns test items for disclosure' do
|
|
|
|
expect(helper.webhook_test_items(project_hook, triggers)).to eq([
|
|
|
|
{
|
|
|
|
href: test_hook_path(project_hook, triggers[0]),
|
|
|
|
text: 'Push events'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
href: test_hook_path(project_hook, triggers[1]),
|
|
|
|
text: 'Comments'
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#test_hook_path' do
|
2021-11-18 22:05:49 +05:30
|
|
|
let(:trigger) { 'push_events' }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'returns project namespaced link' do
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(helper.test_hook_path(project_hook, trigger))
|
|
|
|
.to eq(test_project_hook_path(project, project_hook, trigger: trigger))
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns admin namespaced link' do
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(helper.test_hook_path(system_hook, trigger))
|
|
|
|
.to eq(test_admin_hook_path(system_hook, trigger: trigger))
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
describe '#hook_log_path' do
|
|
|
|
context 'with a project hook' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:web_hook_log) { build_stubbed(:web_hook_log, web_hook: project_hook) }
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
it 'returns project-namespaced link' do
|
|
|
|
expect(helper.hook_log_path(project_hook, web_hook_log))
|
|
|
|
.to eq(web_hook_log.present.details_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
context 'with a service hook' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:web_hook_log) { build_stubbed(:web_hook_log, web_hook: service_hook) }
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
it 'returns project-namespaced link' do
|
|
|
|
expect(helper.hook_log_path(project_hook, web_hook_log))
|
|
|
|
.to eq(web_hook_log.present.details_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
context 'with a system hook' do
|
2023-01-13 00:05:48 +05:30
|
|
|
let(:web_hook_log) { build_stubbed(:web_hook_log, web_hook: system_hook) }
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
it 'returns admin-namespaced link' do
|
|
|
|
expect(helper.hook_log_path(system_hook, web_hook_log))
|
|
|
|
.to eq(admin_hook_hook_log_path(system_hook, web_hook_log))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|