2021-11-18 18:42:27 +01:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-11-18 18:42:27 +01:00
|
|
|
|
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-10-15 17:46:06 +02:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-03-29 08:29:02 +02:00
|
|
|
"code.gitea.io/gitea/models/organization"
|
2024-12-20 19:05:29 +01:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-18 18:42:27 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 10:49:20 +01:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-18 18:42:27 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-28 03:38:53 +02:00
|
|
|
unittest.MainTest(m)
|
2021-11-18 18:42:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteOrganization(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 04:22:25 +02:00
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 6})
|
2023-10-19 15:16:11 +02:00
|
|
|
assert.NoError(t, DeleteOrganization(db.DefaultContext, org, false))
|
2022-03-29 08:29:02 +02:00
|
|
|
unittest.AssertNotExistsBean(t, &organization.Organization{ID: 6})
|
|
|
|
unittest.AssertNotExistsBean(t, &organization.OrgUser{OrgID: 6})
|
|
|
|
unittest.AssertNotExistsBean(t, &organization.Team{OrgID: 6})
|
2021-11-18 18:42:27 +01:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
2023-10-19 15:16:11 +02:00
|
|
|
err := DeleteOrganization(db.DefaultContext, org, false)
|
2021-11-18 18:42:27 +01:00
|
|
|
assert.Error(t, err)
|
2024-12-20 19:05:29 +01:00
|
|
|
assert.True(t, repo_model.IsErrUserOwnRepos(err))
|
2021-11-18 18:42:27 +01:00
|
|
|
|
2022-08-16 04:22:25 +02:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 5})
|
2023-10-19 15:16:11 +02:00
|
|
|
assert.Error(t, DeleteOrganization(db.DefaultContext, user, false))
|
2022-03-29 08:29:02 +02:00
|
|
|
unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
|
2021-11-18 18:42:27 +01:00
|
|
|
}
|