diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 18:10:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 18:10:26 +0300 |
commit | c0b17cee8be646588b14db49ad6d91b8cc818f97 (patch) | |
tree | 97287971303bccd649da1718c1a3a1ba8f345df6 /spec/services | |
parent | 8ef107c43390ea9c9932afb55d1318e4716fbf3b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/projects/lfs_pointers/lfs_import_service_spec.rb | 14 | ||||
-rw-r--r-- | spec/services/quick_actions/interpret_service_spec.rb | 80 |
2 files changed, 88 insertions, 6 deletions
diff --git a/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb b/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb index f1e4db55962..363f871bb9d 100644 --- a/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb +++ b/spec/services/projects/lfs_pointers/lfs_import_service_spec.rb @@ -59,6 +59,20 @@ RSpec.describe Projects::LfsPointers::LfsImportService, feature_category: :sourc expect(result[:message]).to eq error_message end end + + context 'when an GRPC::Core::CallError exception raised' do + it 'returns error' do + error_message = "error message" + expect_next_instance_of(Projects::LfsPointers::LfsObjectDownloadListService) do |instance| + expect(instance).to receive(:each_list_item).and_raise(GRPC::Core::CallError, error_message) + end + + result = subject.execute + + expect(result[:status]).to eq :error + expect(result[:message]).to eq error_message + end + end end context 'when lfs is not enabled for the project' do diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 2f65441dd01..71bff37b956 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -2131,6 +2131,46 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning let(:user) { developer } end + context 'unlink command' do + let_it_be(:private_issue) { create(:issue, project: create(:project, :private)) } + let_it_be(:other_issue) { create(:issue, project: project) } + let(:content) { "/unlink #{other_issue.to_reference(issue)}" } + + subject(:unlink_issues) { service.execute(content, issue) } + + shared_examples 'command with failure' do + it 'does not destroy issues relation' do + expect { unlink_issues }.not_to change { IssueLink.count } + end + + it 'return correct execution message' do + expect(unlink_issues[2]).to eq('No linked issue matches the provided parameter.') + end + end + + context 'when command includes linked issue' do + let_it_be(:link1) { create(:issue_link, source: issue, target: other_issue) } + let_it_be(:link2) { create(:issue_link, source: issue, target: private_issue) } + + it 'executes command successfully' do + expect { unlink_issues }.to change { IssueLink.count }.by(-1) + expect(unlink_issues[2]).to eq("Removed link with #{other_issue.to_reference(issue)}.") + expect(issue.notes.last.note).to eq("removed the relation with #{other_issue.to_reference}") + expect(other_issue.notes.last.note).to eq("removed the relation with #{issue.to_reference}") + end + + context 'when user has no access' do + let(:content) { "/unlink #{private_issue.to_reference(issue)}" } + + it_behaves_like 'command with failure' + end + end + + context 'when provided issue is not linked' do + it_behaves_like 'command with failure' + end + end + context 'invite_email command' do let_it_be(:issuable) { issue } @@ -2877,14 +2917,42 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning end end - describe 'relate command' do - let_it_be(:other_issue) { create(:issue, project: project) } - let(:content) { "/relate #{other_issue.to_reference}" } + describe 'relate and unlink commands' do + let_it_be(:other_issue) { create(:issue, project: project).to_reference(issue) } + let(:relate_content) { "/relate #{other_issue}" } + let(:unlink_content) { "/unlink #{other_issue}" } - it 'includes explain message' do - _, explanations = service.explain(content, issue) + context 'when user has permissions' do + it '/relate command is available' do + _, explanations = service.explain(relate_content, issue) + + expect(explanations).to eq(["Marks this issue as related to #{other_issue}."]) + end + + it '/unlink command is available' do + _, explanations = service.explain(unlink_content, issue) + + expect(explanations).to eq(["Removes link with #{other_issue}."]) + end + end + + context 'when user has insufficient permissions' do + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?).with(current_user, :admin_issue_link, issue).and_return(false) + end + + it '/relate command is not available' do + _, explanations = service.explain(relate_content, issue) - expect(explanations).to eq(["Marks this issue as related to #{other_issue.to_reference}."]) + expect(explanations).to be_empty + end + + it '/unlink command is not available' do + _, explanations = service.explain(unlink_content, issue) + + expect(explanations).to be_empty + end end end end |