Commit 9dd8f87a authored by Rubén Dávila's avatar Rubén Dávila

Delete test cases when migrating project to a free group

CI test cases are only available for ultimate hosted
plans hence we should delete them when the project is transferred
to a lower plan.

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67374
EE: true
parent 36c5d718
......@@ -362,6 +362,14 @@ NOTE:
GitLab administrators can use the administration interface to move any project to any
namespace if needed.
##### Transferring a GitLab.com project to a different subscription tier
When you transfer a project from a namespace that's licensed for GitLab SaaS Premium or Ultimate to Free, some data related to the paid features is deleted.
For example, [project access tokens](../../../user/project/settings/project_access_tokens.md) are revoked, and
[pipeline subscriptions](../../../ci/pipelines/multi_project_pipelines.md#trigger-a-pipeline-when-an-upstream-project-is-rebuilt)
and [test cases](../../../ci/test_cases/index.md) are deleted.
#### Delete a project
You can mark a project to be deleted.
......
......@@ -50,6 +50,7 @@ module EE
def remove_paid_features
revoke_project_access_tokens
delete_pipeline_subscriptions
delete_test_cases
end
def revoke_project_access_tokens
......@@ -66,6 +67,12 @@ module EE
project.upstream_project_subscriptions.destroy_all # rubocop: disable Cop/DestroyAll
end
def delete_test_cases
return if new_namespace.licensed_feature_available?(:quality_management)
project.issues.with_issue_type(:test_case).delete_all
end
end
end
end
......@@ -204,5 +204,26 @@ RSpec.describe Projects::TransferService do
end
end
end
describe 'test cases' do
before do
create(:quality_test_case, project: project, author: user)
stub_ee_application_setting(should_check_namespace_plan: true)
end
context 'when target namespace has a premium plan' do
it 'does not delete the test cases' do
subject.execute(premium_group)
expect { subject.execute(premium_group) }.not_to change { project.issues.with_issue_type(:test_case).count }
end
end
context 'when target namespace has a free plan' do
it 'deletes the test cases' do
expect { subject.execute(free_group) }.to change { project.issues.with_issue_type(:test_case).count }.from(1).to(0)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment