diff --git a/models/fixtures/hook_task.yml b/models/fixtures/hook_task.yml index d573406b3..fc0e03bca 100644 --- a/models/fixtures/hook_task.yml +++ b/models/fixtures/hook_task.yml @@ -35,3 +35,9 @@ "X-Head": "42" } } + +- + id: 4 + hook_id: 3 + uuid: uuid4 + is_delivered: false diff --git a/services/repository/delete_test.go b/tests/integration/repo_delete_test.go similarity index 73% rename from services/repository/delete_test.go rename to tests/integration/repo_delete_test.go index 869b8af11..10e99db44 100644 --- a/services/repository/delete_test.go +++ b/tests/integration/repo_delete_test.go @@ -1,7 +1,7 @@ // Copyright 2017 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package repository_test +package integration import ( "testing" @@ -11,6 +11,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + webhook_model "code.gitea.io/gitea/models/webhook" repo_service "code.gitea.io/gitea/services/repository" "github.com/stretchr/testify/assert" @@ -51,5 +52,22 @@ func TestDeleteOwnerRepositoriesDirectly(t *testing.T) { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + deletedHookID := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{RepoID: 1}).ID + unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{ + HookID: deletedHookID, + }) + + preservedHookID := unittest.AssertExistsAndLoadBean(t, &webhook_model.Webhook{RepoID: 3}).ID + unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{ + HookID: preservedHookID, + }) + assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(db.DefaultContext, user)) + + unittest.AssertNotExistsBean(t, &webhook_model.HookTask{ + HookID: deletedHookID, + }) + unittest.AssertExistsAndLoadBean(t, &webhook_model.HookTask{ + HookID: preservedHookID, + }) }