blob: 39443d48ff6cf74b14b46914a54a3aa5737ff629 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MergeRequests::ResolveTodosAfterApprovalWorker, feature_category: :code_review_workflow do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:merge_request) { create(:merge_request, source_project: project) }
let(:data) { { current_user_id: user.id, merge_request_id: merge_request.id } }
let(:approved_event) { MergeRequests::ApprovedEvent.new(data: data) }
it_behaves_like 'subscribes to event' do
let(:event) { approved_event }
end
it 'calls TodoService#resolve_todos_for_target' do
expect_next_instance_of(TodoService) do |todo_service|
expect(todo_service)
.to receive(:resolve_todos_for_target)
.with(merge_request, user)
end
consume_event(subscriber: described_class, event: approved_event)
end
shared_examples 'when object does not exist' do
it 'logs and does not call TodoService#resolve_todos_for_target' do
expect(Sidekiq.logger).to receive(:info).with(hash_including(log_payload))
expect(TodoService).not_to receive(:new)
expect { consume_event(subscriber: described_class, event: approved_event) }
.not_to raise_exception
end
end
context 'when the user does not exist' do
before do
user.destroy!
end
it_behaves_like 'when object does not exist' do
let(:log_payload) { { 'message' => 'Current user not found.', 'current_user_id' => user.id } }
end
end
context 'when the merge request does not exist' do
before do
merge_request.destroy!
end
it_behaves_like 'when object does not exist' do
let(:log_payload) { { 'message' => 'Merge request not found.', 'merge_request_id' => merge_request.id } }
end
end
end
|