summaryrefslogtreecommitdiff
path: root/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb')
-rw-r--r--spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb37
1 files changed, 30 insertions, 7 deletions
diff --git a/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb b/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb
index d399e73f394..5385b6ca1cf 100644
--- a/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb
+++ b/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject do
+RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject, feature_category: :continuous_integration do
let(:mutation) do
described_class.new(object: nil, context: { current_user: current_user }, field: nil)
end
@@ -17,6 +17,7 @@ RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject do
end
let(:target_project_path) { target_project.full_path }
+ let(:links_relation) { Ci::JobToken::ProjectScopeLink.with_source(project).with_target(target_project) }
subject do
mutation.resolve(project_path: project.full_path, target_project_path: target_project_path)
@@ -45,18 +46,40 @@ RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject do
target_project.add_guest(current_user)
end
- it 'removes target project from the job token scope' do
- expect do
- expect(subject).to include(ci_job_token_scope: be_present, errors: be_empty)
- end.to change { Ci::JobToken::ProjectScopeLink.count }.by(-1)
+ let(:service) { instance_double('Ci::JobTokenScope::RemoveProjectService') }
+
+ context 'with no direction specified' do
+ it 'defaults to asking the RemoveProjectService to remove the outbound link' do
+ expect(::Ci::JobTokenScope::RemoveProjectService)
+ .to receive(:new).with(project, current_user).and_return(service)
+ expect(service).to receive(:execute).with(target_project, :outbound)
+ .and_return(instance_double('ServiceResponse', "success?": true))
+
+ subject
+ end
+ end
+
+ context 'with direction specified' do
+ subject do
+ mutation.resolve(project_path: project.full_path, target_project_path: target_project_path, direction: 'inbound')
+ end
+
+ it 'executes project removal for the correct direction' do
+ expect(::Ci::JobTokenScope::RemoveProjectService)
+ .to receive(:new).with(project, current_user).and_return(service)
+ expect(service).to receive(:execute).with(target_project, 'inbound')
+ .and_return(instance_double('ServiceResponse', "success?": true))
+
+ subject
+ end
end
context 'when the service returns an error' do
- let(:service) { double(:service) }
+ let(:service) { instance_double('Ci::JobTokenScope::RemoveProjectService') }
it 'returns an error response' do
expect(::Ci::JobTokenScope::RemoveProjectService).to receive(:new).with(project, current_user).and_return(service)
- expect(service).to receive(:execute).with(target_project).and_return(ServiceResponse.error(message: 'The error message'))
+ expect(service).to receive(:execute).with(target_project, :outbound).and_return(ServiceResponse.error(message: 'The error message'))
expect(subject.fetch(:ci_job_token_scope)).to be_nil
expect(subject.fetch(:errors)).to include("The error message")