debian-mirror-gitlab/spec/models/hooks/service_hook_spec.rb

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

66 lines
1.6 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2014-09-02 18:07:02 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe ServiceHook do
2017-09-10 17:25:29 +05:30
describe 'associations' do
2021-06-08 01:23:25 +05:30
it { is_expected.to belong_to :integration }
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
2017-09-10 17:25:29 +05:30
describe 'validations' do
2021-06-08 01:23:25 +05:30
it { is_expected.to validate_presence_of(:integration) }
2017-09-10 17:25:29 +05:30
end
2015-09-11 14:41:01 +05:30
2017-09-10 17:25:29 +05:30
describe 'execute' do
let(:hook) { build(:service_hook) }
let(:data) { { key: 'value' } }
2015-09-11 14:41:01 +05:30
2017-09-10 17:25:29 +05:30
it '#execute' do
2022-04-04 11:22:00 +05:30
expect(WebHookService).to receive(:new).with(hook, data, 'service_hook', force: false).and_call_original
2017-09-10 17:25:29 +05:30
expect_any_instance_of(WebHookService).to receive(:execute)
2015-09-11 14:41:01 +05:30
2017-09-10 17:25:29 +05:30
hook.execute(data)
2015-09-11 14:41:01 +05:30
end
end
2021-06-08 01:23:25 +05:30
2022-03-02 08:16:31 +05:30
describe '#parent' do
let(:hook) { build(:service_hook, integration: integration) }
context 'with a project-level integration' do
let(:project) { build(:project) }
let(:integration) { build(:integration, project: project) }
it 'returns the associated project' do
expect(hook.parent).to eq(project)
end
end
context 'with a group-level integration' do
let(:group) { build(:group) }
let(:integration) { build(:integration, :group, group: group) }
it 'returns the associated group' do
expect(hook.parent).to eq(group)
end
end
context 'with an instance-level integration' do
let(:integration) { build(:integration, :instance) }
it 'returns nil' do
expect(hook.parent).to be_nil
end
end
end
2021-09-04 01:27:46 +05:30
describe '#application_context' do
let(:hook) { build(:service_hook) }
it 'includes the type' do
expect(hook.application_context).to eq(
related_class: 'ServiceHook'
)
end
end
2014-09-02 18:07:02 +05:30
end