2021-04-29 14:10:23 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Deployments::HooksWorker do
|
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
before do
|
2022-06-02 17:09:25 -04:00
|
|
|
allow(Integrations::ExecuteWorker).to receive(:perform_async)
|
2021-04-29 14:10:23 -04:00
|
|
|
end
|
|
|
|
|
2022-05-10 23:07:57 -04:00
|
|
|
it 'logs deployment and project IDs as metadata' do
|
|
|
|
deployment = create(:deployment, :running)
|
|
|
|
project = deployment.project
|
|
|
|
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:deployment_project_id, project.id)
|
|
|
|
expect(worker).to receive(:log_extra_metadata_on_done).with(:deployment_id, deployment.id)
|
|
|
|
|
|
|
|
worker.perform(deployment_id: deployment.id, status_changed_at: Time.current)
|
|
|
|
end
|
|
|
|
|
2021-04-29 14:10:23 -04:00
|
|
|
it 'executes project services for deployment_hooks' do
|
|
|
|
deployment = create(:deployment, :running)
|
|
|
|
project = deployment.project
|
2022-02-21 22:14:19 -05:00
|
|
|
service = create(:integrations_slack, project: project, deployment_events: true)
|
2021-04-29 14:10:23 -04:00
|
|
|
|
2022-06-02 17:09:25 -04:00
|
|
|
expect(Integrations::ExecuteWorker).to receive(:perform_async).with(service.id, an_instance_of(Hash))
|
2021-04-29 14:10:23 -04:00
|
|
|
|
|
|
|
worker.perform(deployment_id: deployment.id, status_changed_at: Time.current)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not execute an inactive service' do
|
|
|
|
deployment = create(:deployment, :running)
|
|
|
|
project = deployment.project
|
2022-02-21 22:14:19 -05:00
|
|
|
create(:integrations_slack, project: project, deployment_events: true, active: false)
|
2021-04-29 14:10:23 -04:00
|
|
|
|
2022-06-02 17:09:25 -04:00
|
|
|
expect(Integrations::ExecuteWorker).not_to receive(:perform_async)
|
2021-04-29 14:10:23 -04:00
|
|
|
|
|
|
|
worker.perform(deployment_id: deployment.id, status_changed_at: Time.current)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not execute if a deployment does not exist' do
|
2022-06-02 17:09:25 -04:00
|
|
|
expect(Integrations::ExecuteWorker).not_to receive(:perform_async)
|
2021-04-29 14:10:23 -04:00
|
|
|
|
|
|
|
worker.perform(deployment_id: non_existing_record_id, status_changed_at: Time.current)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'execute webhooks' do
|
|
|
|
deployment = create(:deployment, :running)
|
|
|
|
project = deployment.project
|
|
|
|
web_hook = create(:project_hook, deployment_events: true, project: project)
|
|
|
|
|
|
|
|
status_changed_at = Time.current
|
|
|
|
|
|
|
|
expect_next_instance_of(WebHookService, web_hook, hash_including(status_changed_at: status_changed_at), "deployment_hooks") do |service|
|
|
|
|
expect(service).to receive(:async_execute)
|
|
|
|
end
|
|
|
|
|
|
|
|
worker.perform(deployment_id: deployment.id, status_changed_at: status_changed_at)
|
|
|
|
end
|
2021-08-13 11:11:15 -04:00
|
|
|
|
|
|
|
it_behaves_like 'worker with data consistency',
|
|
|
|
described_class,
|
|
|
|
data_consistency: :delayed
|
2021-04-29 14:10:23 -04:00
|
|
|
end
|
|
|
|
end
|