debian-mirror-gitlab/spec/services/merge_requests/remove_approval_service_spec.rb

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

91 lines
2.9 KiB
Ruby
Raw Permalink Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-04-23 21:23:45 +05:30
RSpec.describe MergeRequests::RemoveApprovalService, feature_category: :code_review_workflow do
2020-07-28 23:09:34 +05:30
describe '#execute' do
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:merge_request) { create(:merge_request, source_project: project) }
let!(:existing_approval) { create(:approval, merge_request: merge_request) }
2021-06-08 01:23:25 +05:30
subject(:service) { described_class.new(project: project, current_user: user) }
2020-07-28 23:09:34 +05:30
def execute!
service.execute(merge_request)
end
before do
project.add_developer(user)
end
context 'with a user who has approved' do
let!(:approval) { create(:approval, user: user, merge_request: merge_request) }
2022-07-16 23:28:13 +05:30
let(:notification_service) { NotificationService.new }
before do
allow(service).to receive(:notification_service).and_return(notification_service)
end
2020-07-28 23:09:34 +05:30
it 'removes the approval' do
expect { execute! }.to change { merge_request.approvals.size }.from(2).to(1)
end
2022-07-16 23:28:13 +05:30
it 'creates an unapproval note, triggers a web hook, and sends a notification' do
2020-07-28 23:09:34 +05:30
expect(service).to receive(:execute_hooks).with(merge_request, 'unapproved')
expect(SystemNoteService).to receive(:unapprove_mr)
2022-07-16 23:28:13 +05:30
expect(notification_service).to receive_message_chain(:async, :unapprove_mr).with(merge_request, user)
2020-07-28 23:09:34 +05:30
execute!
end
2021-03-11 19:13:27 +05:30
it 'tracks merge request unapprove action' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_unapprove_mr_action).with(user: user)
execute!
end
2023-01-13 00:05:48 +05:30
it_behaves_like 'triggers GraphQL subscription mergeRequestMergeStatusUpdated' do
let(:action) { execute! }
end
it_behaves_like 'triggers GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { execute! }
end
2023-03-04 22:38:38 +05:30
it_behaves_like 'triggers GraphQL subscription mergeRequestApprovalStateUpdated' do
let(:action) { execute! }
end
2020-07-28 23:09:34 +05:30
end
context 'with a user who has not approved' do
it 'does not create an unapproval note and triggers web hook' do
expect(service).not_to receive(:execute_hooks)
expect(SystemNoteService).not_to receive(:unapprove_mr)
execute!
end
2021-03-11 19:13:27 +05:30
it 'does not track merge request unapprove action' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.not_to receive(:track_unapprove_mr_action).with(user: user)
execute!
end
2023-01-13 00:05:48 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestMergeStatusUpdated' do
let(:action) { execute! }
end
it_behaves_like 'does not trigger GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { execute! }
end
2023-03-04 22:38:38 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestApprovalStateUpdated' do
let(:action) { execute! }
end
2020-07-28 23:09:34 +05:30
end
end
end