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.rb34
1 files changed, 28 insertions, 6 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 4a0501bddbd..7fb45e93474 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
@@ -17,6 +17,7 @@ RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject, feature_category: :c
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,39 @@ RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject, feature_category: :c
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)
+ context 'with no direction specified' do
+ it 'defaults to removing an outbound link to the target project' 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)
+
+ expect(links_relation.outbound.reload).to be_empty
+ end
+ end
+
+ context 'with direction specified' do
+ let(:service) { instance_double('Ci::JobTokenScope::RemoveProjectService') }
+
+ 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, direction: '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, direction: :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")