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