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

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

123 lines
4.1 KiB
Ruby
Raw Permalink Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe MergeRequests::ApprovalService, feature_category: :code_review_workflow do
2020-07-28 23:09:34 +05:30
describe '#execute' do
let(:user) { create(:user) }
2022-01-26 12:08:38 +05:30
let(:merge_request) { create(:merge_request, reviewers: [user]) }
2020-07-28 23:09:34 +05:30
let(:project) { merge_request.project }
let!(:todo) { create(:todo, user: user, project: project, target: 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
before do
project.add_developer(user)
end
context 'with invalid approval' do
before do
allow(merge_request.approvals).to receive(:new).and_return(double(save: false))
end
2022-08-27 11:52:29 +05:30
it 'does not reset approvals' do
expect(merge_request.approvals).not_to receive(:reset)
2020-07-28 23:09:34 +05:30
service.execute(merge_request)
end
2021-03-11 19:13:27 +05:30
it 'does not track merge request approve action' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.not_to receive(:track_approve_mr_action).with(user: user)
service.execute(merge_request)
end
2022-07-16 23:28:13 +05:30
2023-01-13 00:05:48 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestMergeStatusUpdated' do
let(:action) { service.execute(merge_request) }
end
2022-08-27 11:52:29 +05:30
it 'does not publish MergeRequests::ApprovedEvent' do
expect { service.execute(merge_request) }.not_to publish_event(MergeRequests::ApprovedEvent)
2022-07-16 23:28:13 +05:30
end
2023-01-13 00:05:48 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { service.execute(merge_request) }
end
2022-10-11 01:57:18 +05:30
end
2022-07-16 23:28:13 +05:30
2022-10-11 01:57:18 +05:30
context 'with an already approved MR' do
before do
merge_request.approvals.create!(user: user)
end
2022-08-27 11:52:29 +05:30
2022-10-11 01:57:18 +05:30
it 'does not create an approval' do
expect { service.execute(merge_request) }.not_to change { merge_request.approvals.size }
2020-07-28 23:09:34 +05:30
end
2023-01-13 00:05:48 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestMergeStatusUpdated' do
let(:action) { service.execute(merge_request) }
end
it_behaves_like 'does not trigger GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { service.execute(merge_request) }
end
2022-08-27 11:52:29 +05:30
end
2020-07-28 23:09:34 +05:30
2022-08-27 11:52:29 +05:30
context 'with valid approval' do
it 'resets approvals' do
expect(merge_request.approvals).to receive(:reset)
2022-07-16 23:28:13 +05:30
service.execute(merge_request)
end
2022-08-27 11:52:29 +05:30
it 'tracks merge request approve action' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_approve_mr_action).with(user: user, merge_request: merge_request)
2022-01-26 12:08:38 +05:30
service.execute(merge_request)
end
2022-08-27 11:52:29 +05:30
it 'publishes MergeRequests::ApprovedEvent' do
expect { service.execute(merge_request) }
.to publish_event(MergeRequests::ApprovedEvent)
.with(current_user_id: user.id, merge_request_id: merge_request.id)
end
2023-01-13 00:05:48 +05:30
it_behaves_like 'triggers GraphQL subscription mergeRequestMergeStatusUpdated' do
let(:action) { service.execute(merge_request) }
end
it_behaves_like 'triggers GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { service.execute(merge_request) }
end
2023-03-04 22:38:38 +05:30
it_behaves_like 'triggers GraphQL subscription mergeRequestApprovalStateUpdated' do
let(:action) { service.execute(merge_request) }
end
2020-07-28 23:09:34 +05:30
end
context 'user cannot update the merge request' do
before do
project.add_guest(user)
end
it 'does not update approvals' do
expect { service.execute(merge_request) }.not_to change { merge_request.approvals.size }
end
2023-01-13 00:05:48 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestMergeStatusUpdated' do
let(:action) { service.execute(merge_request) }
end
it_behaves_like 'does not trigger GraphQL subscription mergeRequestReviewersUpdated' do
let(:action) { service.execute(merge_request) }
end
2023-03-04 22:38:38 +05:30
it_behaves_like 'does not trigger GraphQL subscription mergeRequestApprovalStateUpdated' do
let(:action) { service.execute(merge_request) }
end
2020-07-28 23:09:34 +05:30
end
end
end