2021-11-18 12:42:27 -05:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2022-03-29 02:29:02 -04:00
|
|
|
"code.gitea.io/gitea/models/organization"
|
2021-11-18 12:42:27 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 04:49:20 -05:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-18 12:42:27 -05:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2022-04-14 09:58:21 -04:00
|
|
|
unittest.MainTest(m, &unittest.TestOptions{
|
|
|
|
GiteaRootPath: filepath.Join("..", ".."),
|
|
|
|
})
|
2021-11-18 12:42:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteOrganization(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-03-29 02:29:02 -04:00
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 6}).(*organization.Organization)
|
2021-11-18 12:42:27 -05:00
|
|
|
assert.NoError(t, DeleteOrganization(org))
|
2022-03-29 02:29:02 -04: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 12:42:27 -05:00
|
|
|
|
2022-03-29 02:29:02 -04:00
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}).(*organization.Organization)
|
2021-11-18 12:42:27 -05:00
|
|
|
err := DeleteOrganization(org)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, models.IsErrUserOwnRepos(err))
|
|
|
|
|
2022-03-29 02:29:02 -04:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 5}).(*organization.Organization)
|
2021-11-18 12:42:27 -05:00
|
|
|
assert.Error(t, DeleteOrganization(user))
|
2022-03-29 02:29:02 -04:00
|
|
|
unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
|
2021-11-18 12:42:27 -05:00
|
|
|
}
|