blob: 2b700b944d26a86498718bbfbd2098735be579b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe RepositoryCleanupWorker do
let(:project) { create(:project) }
let(:user) { create(:user) }
subject(:worker) { described_class.new }
describe '#perform' do
it 'executes the cleanup service and sends a success notification' do
expect_next_instance_of(Projects::CleanupService) do |service|
expect(service.project).to eq(project)
expect(service.current_user).to eq(user)
expect(service).to receive(:execute)
end
expect_next_instance_of(NotificationService) do |service|
expect(service).to receive(:repository_cleanup_success).with(project, user)
end
worker.perform(project.id, user.id)
end
it 'raises an error if the project cannot be found' do
project.destroy!
expect { worker.perform(project.id, user.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
it 'raises an error if the user cannot be found' do
user.destroy!
expect { worker.perform(project.id, user.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
end
describe '#sidekiq_retries_exhausted' do
let(:job) { { 'args' => [project.id, user.id], 'error_message' => 'Error' } }
subject(:sidekiq_retries_exhausted) { described_class.sidekiq_retries_exhausted_block.call(job, StandardError.new) }
it 'does not send a failure notification for a RecordNotFound error' do
expect(NotificationService).not_to receive(:new)
described_class.sidekiq_retries_exhausted_block.call(job, ActiveRecord::RecordNotFound.new)
end
it 'sends a failure notification' do
expect_next_instance_of(NotificationService) do |service|
expect(service).to receive(:repository_cleanup_failure).with(project, user, 'Error')
end
sidekiq_retries_exhausted
end
it 'cleans up the attempt' do
expect(Projects::CleanupService).to receive(:cleanup_after).with(project)
sidekiq_retries_exhausted
end
end
end
|