debian-mirror-gitlab/spec/services/test_hooks/system_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
3.1 KiB
Ruby
Raw Permalink Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe TestHooks::SystemService, feature_category: :code_testing do
2021-03-11 19:13:27 +05:30
include AfterNextHelpers
2017-09-10 17:25:29 +05:30
describe '#execute' do
2021-03-11 19:13:27 +05:30
let_it_be(:project) { create(:project, :repository) }
2021-09-30 23:02:18 +05:30
2017-09-10 17:25:29 +05:30
let(:hook) { create(:system_hook) }
2022-03-02 08:16:31 +05:30
let(:service) { described_class.new(hook, project.first_owner, trigger) }
2017-09-10 17:25:29 +05:30
let(:success_result) { { status: :success, http_status: 200, message: 'ok' } }
before do
allow(Project).to receive(:first).and_return(project)
end
context 'hook with not implemented test' do
let(:trigger) { 'not_implemented_events' }
it 'returns error message' do
expect(hook).not_to receive(:execute)
2023-03-17 16:20:25 +05:30
expect(service.execute).to have_attributes(status: :error, message: 'Testing not available for this hook')
2017-09-10 17:25:29 +05:30
end
end
context 'push_events' do
let(:trigger) { 'push_events' }
2018-03-17 18:26:18 +05:30
let(:trigger_key) { :push_hooks }
2017-09-10 17:25:29 +05:30
it 'executes hook' do
expect(Gitlab::DataBuilder::Push).to receive(:sample_data).and_call_original
2022-04-04 11:22:00 +05:30
expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger_key, force: true).and_return(success_result)
2017-09-10 17:25:29 +05:30
expect(service.execute).to include(success_result)
end
end
context 'tag_push_events' do
let(:trigger) { 'tag_push_events' }
2018-03-17 18:26:18 +05:30
let(:trigger_key) { :tag_push_hooks }
2017-09-10 17:25:29 +05:30
it 'executes hook' do
allow(project.repository).to receive(:tags).and_return(['tag'])
expect(Gitlab::DataBuilder::Push).to receive(:sample_data).and_call_original
2022-04-04 11:22:00 +05:30
expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Push::SAMPLE_DATA, trigger_key, force: true).and_return(success_result)
2017-09-10 17:25:29 +05:30
expect(service.execute).to include(success_result)
end
end
context 'repository_update_events' do
let(:trigger) { 'repository_update_events' }
2018-03-17 18:26:18 +05:30
let(:trigger_key) { :repository_update_hooks }
2017-09-10 17:25:29 +05:30
it 'executes hook' do
expect(Gitlab::DataBuilder::Repository).to receive(:sample_data).and_call_original
2022-04-04 11:22:00 +05:30
expect(hook).to receive(:execute).with(Gitlab::DataBuilder::Repository::SAMPLE_DATA, trigger_key, force: true).and_return(success_result)
2018-03-17 18:26:18 +05:30
expect(service.execute).to include(success_result)
end
end
context 'merge_requests_events' do
let(:trigger) { 'merge_requests_events' }
2021-03-11 19:13:27 +05:30
let(:trigger_key) { :merge_request_hooks }
let(:merge_request) { build(:merge_request) }
let(:sample_data) { { data: 'sample' } }
2018-03-17 18:26:18 +05:30
it 'returns error message if the user does not have any repository with a merge request' do
expect(hook).not_to receive(:execute)
2023-03-17 16:20:25 +05:30
expect(service.execute).to have_attributes(status: :error, message: 'Ensure one of your projects has merge requests.')
2018-03-17 18:26:18 +05:30
end
it 'executes hook' do
2021-03-11 19:13:27 +05:30
expect(MergeRequest).to receive(:of_projects).and_return([merge_request])
expect(merge_request).to receive(:to_hook_data).and_return(sample_data)
2022-04-04 11:22:00 +05:30
expect(hook).to receive(:execute).with(sample_data, trigger_key, force: true).and_return(success_result)
2017-09-10 17:25:29 +05:30
expect(service.execute).to include(success_result)
end
end
end
end