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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Issues::CloseWorker, feature_category: :team_planning do
describe "#perform" do
let_it_be(:developer) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository, developers: [developer]) }
let_it_be_with_reload(:issue) { create(:issue, project: project, author: author) }
let(:project_id) { project.id }
let(:issue_id) { issue.id }
let(:current_user_id) { developer&.id }
let(:current_author_id) { author&.id }
let(:commit) { project.commit }
let(:opts) do
{ "closed_by" => current_author_id, "user_id" => current_user_id, "commit_hash" => commit.to_hash }
end
subject(:perform_job) { described_class.new.perform(project_id, issue_id, issue.class.to_s, opts) }
describe "#perform" do
context "when the user can update the issues" do
it "closes the issues" do
perform_job
issue.reload
expect(issue).to be_closed
end
it "closes external issues" do
external_issue = ExternalIssue.new("foo", project)
closer = instance_double(Issues::CloseService, execute: true)
expect(Issues::CloseService).to receive(:new).with(container: project, current_user: author)
.and_return(closer)
expect(closer).to receive(:execute).with(external_issue, commit: commit)
described_class.new.perform(project.id, external_issue.id, external_issue.class.to_s, opts)
end
end
context "when the user can not update the issues" do
let(:current_user_id) { create(:user).id }
it 'does not close the issues' do
perform_job
issue.reload
expect(issue).not_to be_closed
end
end
# TODO: Remove with https://gitlab.com/gitlab-org/gitlab/-/work_items/509422
context "when user is not provided to the worker (backwards compatibility)" do
let(:current_user_id) { nil }
it 'does closes the issue' do
perform_job
issue.reload
expect(issue).to be_closed
end
end
end
shared_examples "when object does not exist" do
it "does not call the close issue service" do
expect(Issues::CloseService).not_to receive(:new)
expect { perform_job }.not_to raise_exception
end
end
context "when the project does not exist" do
let(:project_id) { non_existing_record_id }
it_behaves_like "when object does not exist"
end
context "when the author does not exist" do
let(:current_author_id) { non_existing_record_id }
it_behaves_like "when object does not exist"
end
context "when the issue does not exist" do
let(:issue_id) { non_existing_record_id }
it_behaves_like "when object does not exist"
end
end
end
|