2017-01-24 21:46:36 +05:30
|
|
|
// Copyright 2017 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 models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2019-08-24 17:58:59 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-02-18 21:30:27 +05:30
|
|
|
"code.gitea.io/gitea/modules/structs"
|
|
|
|
|
2017-01-24 21:46:36 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUser_IsOwnedBy(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-12-21 13:13:26 +05:30
|
|
|
for _, testCase := range []struct {
|
|
|
|
OrgID int64
|
|
|
|
UserID int64
|
|
|
|
ExpectedOwner bool
|
|
|
|
}{
|
|
|
|
{3, 2, true},
|
|
|
|
{3, 1, false},
|
|
|
|
{3, 3, false},
|
|
|
|
{3, 4, false},
|
|
|
|
{2, 2, false}, // user2 is not an organization
|
|
|
|
{2, 3, false},
|
|
|
|
} {
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User)
|
2017-12-21 13:13:26 +05:30
|
|
|
isOwner, err := org.IsOwnedBy(testCase.UserID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, testCase.ExpectedOwner, isOwner)
|
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_IsOrgMember(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-12-21 13:13:26 +05:30
|
|
|
for _, testCase := range []struct {
|
|
|
|
OrgID int64
|
|
|
|
UserID int64
|
|
|
|
ExpectedMember bool
|
|
|
|
}{
|
|
|
|
{3, 2, true},
|
|
|
|
{3, 4, true},
|
|
|
|
{3, 1, false},
|
|
|
|
{3, 3, false},
|
|
|
|
{2, 2, false}, // user2 is not an organization
|
|
|
|
{2, 3, false},
|
|
|
|
} {
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User)
|
2017-12-21 13:13:26 +05:30
|
|
|
isMember, err := org.IsOrgMember(testCase.UserID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, testCase.ExpectedMember, isMember)
|
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_GetTeam(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
team, err := org.GetTeam("team1")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, org.ID, team.OrgID)
|
|
|
|
assert.Equal(t, "team1", team.LowerName)
|
|
|
|
|
|
|
|
_, err = org.GetTeam("does not exist")
|
2019-09-24 01:38:03 +05:30
|
|
|
assert.True(t, IsErrTeamNotExist(err))
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
nonOrg := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
_, err = nonOrg.GetTeam("team")
|
2019-09-24 01:38:03 +05:30
|
|
|
assert.True(t, IsErrTeamNotExist(err))
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_GetOwnerTeam(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
team, err := org.GetOwnerTeam()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, org.ID, team.OrgID)
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
nonOrg := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
_, err = nonOrg.GetOwnerTeam()
|
2019-09-24 01:38:03 +05:30
|
|
|
assert.True(t, IsErrTeamNotExist(err))
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_GetTeams(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2021-08-12 18:13:08 +05:30
|
|
|
assert.NoError(t, org.LoadTeams())
|
2019-11-20 16:57:49 +05:30
|
|
|
if assert.Len(t, org.Teams, 4) {
|
2017-08-28 14:47:45 +05:30
|
|
|
assert.Equal(t, int64(1), org.Teams[0].ID)
|
|
|
|
assert.Equal(t, int64(2), org.Teams[1].ID)
|
2019-11-20 16:57:49 +05:30
|
|
|
assert.Equal(t, int64(12), org.Teams[2].ID)
|
|
|
|
assert.Equal(t, int64(7), org.Teams[3].ID)
|
2017-08-28 14:47:45 +05:30
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_GetMembers(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, org.GetMembers())
|
2019-11-20 16:57:49 +05:30
|
|
|
if assert.Len(t, org.Members, 3) {
|
2017-08-28 14:47:45 +05:30
|
|
|
assert.Equal(t, int64(2), org.Members[0].ID)
|
2019-11-20 16:57:49 +05:30
|
|
|
assert.Equal(t, int64(28), org.Members[1].ID)
|
|
|
|
assert.Equal(t, int64(4), org.Members[2].ID)
|
2017-08-28 14:47:45 +05:30
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_AddMember(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
// add a user that is not a member
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
|
2017-01-24 21:46:36 +05:30
|
|
|
prevNumMembers := org.NumMembers
|
|
|
|
assert.NoError(t, org.AddMember(5))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &OrgUser{UID: 5, OrgID: 3})
|
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.Equal(t, prevNumMembers+1, org.NumMembers)
|
|
|
|
|
|
|
|
// add a user that is already a member
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
|
2017-01-24 21:46:36 +05:30
|
|
|
prevNumMembers = org.NumMembers
|
|
|
|
assert.NoError(t, org.AddMember(4))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
|
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.Equal(t, prevNumMembers, org.NumMembers)
|
2017-02-07 17:17:55 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, &User{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_RemoveMember(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
// remove a user that is a member
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
|
2017-01-24 21:46:36 +05:30
|
|
|
prevNumMembers := org.NumMembers
|
|
|
|
assert.NoError(t, org.RemoveMember(4))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &OrgUser{UID: 4, OrgID: 3})
|
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.Equal(t, prevNumMembers-1, org.NumMembers)
|
|
|
|
|
|
|
|
// remove a user that is not a member
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
|
2017-01-24 21:46:36 +05:30
|
|
|
prevNumMembers = org.NumMembers
|
|
|
|
assert.NoError(t, org.RemoveMember(5))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
|
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.Equal(t, prevNumMembers, org.NumMembers)
|
2017-02-07 17:17:55 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_RemoveOrgRepo(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &Repository{OwnerID: org.ID}).(*Repository)
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
// remove a repo that does belong to org
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, org.RemoveOrgRepo(repo.ID))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &Repository{ID: repo.ID}) // repo should still exist
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
// remove a repo that does not belong to org
|
|
|
|
assert.NoError(t, org.RemoveOrgRepo(repo.ID))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
assert.NoError(t, org.RemoveOrgRepo(unittest.NonexistentID))
|
2017-02-07 17:17:55 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t,
|
2017-02-07 17:17:55 +05:30
|
|
|
&User{ID: org.ID},
|
|
|
|
&Team{OrgID: org.ID},
|
|
|
|
&Repository{ID: repo.ID})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateOrganization(t *testing.T) {
|
|
|
|
// successful creation of org
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
const newOrgName = "neworg"
|
|
|
|
org := &User{
|
|
|
|
Name: newOrgName,
|
|
|
|
}
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, CreateOrganization(org, owner))
|
2021-11-16 14:23:21 +05:30
|
|
|
org = unittest.AssertExistsAndLoadBean(t,
|
2017-01-24 21:46:36 +05:30
|
|
|
&User{Name: newOrgName, Type: UserTypeOrganization}).(*User)
|
2021-11-16 14:23:21 +05:30
|
|
|
ownerTeam := unittest.AssertExistsAndLoadBean(t,
|
2017-01-24 21:46:36 +05:30
|
|
|
&Team{Name: ownerTeamName, OrgID: org.ID}).(*Team)
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: owner.ID, TeamID: ownerTeam.ID})
|
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateOrganization2(t *testing.T) {
|
|
|
|
// unauthorized creation of org
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
const newOrgName = "neworg"
|
|
|
|
org := &User{
|
|
|
|
Name: newOrgName,
|
|
|
|
}
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
|
2017-01-24 21:46:36 +05:30
|
|
|
err := CreateOrganization(org, owner)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrUserNotAllowedCreateOrg(err))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
|
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateOrganization3(t *testing.T) {
|
|
|
|
// create org with same name as existent org
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
|
|
|
org := &User{Name: "user3"} // should already exist
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &User{Name: org.Name}) // sanity check
|
2017-01-24 21:46:36 +05:30
|
|
|
err := CreateOrganization(org, owner)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrUserAlreadyExist(err))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateOrganization4(t *testing.T) {
|
|
|
|
// create org with unusable name
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
err := CreateOrganization(&User{Name: "assets"}, owner)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrNameReserved(err))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOrgByName(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
org, err := GetOrgByName("user3")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 3, org.ID)
|
|
|
|
assert.Equal(t, "user3", org.Name)
|
|
|
|
|
2019-06-13 01:11:28 +05:30
|
|
|
_, err = GetOrgByName("user2") // user2 is an individual
|
2017-07-06 19:00:19 +05:30
|
|
|
assert.True(t, IsErrOrgNotExist(err))
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2019-06-13 01:11:28 +05:30
|
|
|
_, err = GetOrgByName("") // corner case
|
2017-07-06 19:00:19 +05:30
|
|
|
assert.True(t, IsErrOrgNotExist(err))
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestCountOrganizations(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-09-23 21:15:36 +05:30
|
|
|
expected, err := db.GetEngine(db.DefaultContext).Where("type=?", UserTypeOrganization).Count(&User{})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, CountOrganizations())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsOrganizationOwner(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-12-21 13:13:26 +05:30
|
|
|
test := func(orgID, userID int64, expected bool) {
|
|
|
|
isOwner, err := IsOrganizationOwner(orgID, userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expected, isOwner)
|
|
|
|
}
|
|
|
|
test(3, 2, true)
|
|
|
|
test(3, 3, false)
|
|
|
|
test(6, 5, true)
|
|
|
|
test(6, 4, false)
|
2021-11-16 14:23:21 +05:30
|
|
|
test(unittest.NonexistentID, unittest.NonexistentID, false)
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsOrganizationMember(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-12-21 13:13:26 +05:30
|
|
|
test := func(orgID, userID int64, expected bool) {
|
|
|
|
isMember, err := IsOrganizationMember(orgID, userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expected, isMember)
|
|
|
|
}
|
|
|
|
test(3, 2, true)
|
|
|
|
test(3, 3, false)
|
|
|
|
test(3, 4, true)
|
|
|
|
test(6, 5, true)
|
|
|
|
test(6, 4, false)
|
2021-11-16 14:23:21 +05:30
|
|
|
test(unittest.NonexistentID, unittest.NonexistentID, false)
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestIsPublicMembership(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-12-21 13:13:26 +05:30
|
|
|
test := func(orgID, userID int64, expected bool) {
|
|
|
|
isMember, err := IsPublicMembership(orgID, userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expected, isMember)
|
|
|
|
}
|
|
|
|
test(3, 2, true)
|
|
|
|
test(3, 3, false)
|
|
|
|
test(3, 4, false)
|
|
|
|
test(6, 5, true)
|
|
|
|
test(6, 4, false)
|
2021-11-16 14:23:21 +05:30
|
|
|
test(unittest.NonexistentID, unittest.NonexistentID, false)
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOrgsByUserID(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
orgs, err := GetOrgsByUserID(4, true)
|
|
|
|
assert.NoError(t, err)
|
2017-08-28 14:47:45 +05:30
|
|
|
if assert.Len(t, orgs, 1) {
|
|
|
|
assert.EqualValues(t, 3, orgs[0].ID)
|
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
orgs, err = GetOrgsByUserID(4, false)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, orgs, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOwnedOrgsByUserID(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
orgs, err := GetOwnedOrgsByUserID(2)
|
|
|
|
assert.NoError(t, err)
|
2017-08-28 14:47:45 +05:30
|
|
|
if assert.Len(t, orgs, 1) {
|
|
|
|
assert.EqualValues(t, 3, orgs[0].ID)
|
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
orgs, err = GetOwnedOrgsByUserID(4)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, orgs, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOwnedOrgsByUserIDDesc(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
orgs, err := GetOwnedOrgsByUserIDDesc(5, "id")
|
|
|
|
assert.NoError(t, err)
|
2017-08-28 14:47:45 +05:30
|
|
|
if assert.Len(t, orgs, 2) {
|
|
|
|
assert.EqualValues(t, 7, orgs[0].ID)
|
|
|
|
assert.EqualValues(t, 6, orgs[1].ID)
|
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
orgs, err = GetOwnedOrgsByUserIDDesc(4, "id")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, orgs, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOrgUsersByUserID(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2020-01-25 00:30:29 +05:30
|
|
|
orgUsers, err := GetOrgUsersByUserID(5, &SearchOrganizationsOptions{All: true})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, err)
|
2017-08-28 14:47:45 +05:30
|
|
|
if assert.Len(t, orgUsers, 2) {
|
|
|
|
assert.Equal(t, OrgUser{
|
|
|
|
ID: orgUsers[0].ID,
|
|
|
|
OrgID: 6,
|
|
|
|
UID: 5,
|
2021-03-15 00:22:12 +05:30
|
|
|
IsPublic: true,
|
|
|
|
}, *orgUsers[0])
|
2017-08-28 14:47:45 +05:30
|
|
|
assert.Equal(t, OrgUser{
|
|
|
|
ID: orgUsers[1].ID,
|
|
|
|
OrgID: 7,
|
|
|
|
UID: 5,
|
2021-03-15 00:22:12 +05:30
|
|
|
IsPublic: false,
|
|
|
|
}, *orgUsers[1])
|
2017-08-28 14:47:45 +05:30
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2020-01-25 00:30:29 +05:30
|
|
|
publicOrgUsers, err := GetOrgUsersByUserID(5, &SearchOrganizationsOptions{All: false})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, publicOrgUsers, 1)
|
|
|
|
assert.Equal(t, *orgUsers[0], *publicOrgUsers[0])
|
|
|
|
|
2020-01-25 00:30:29 +05:30
|
|
|
orgUsers, err = GetOrgUsersByUserID(1, &SearchOrganizationsOptions{All: true})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, orgUsers, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOrgUsersByOrgID(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2020-01-25 00:30:29 +05:30
|
|
|
orgUsers, err := GetOrgUsersByOrgID(&FindOrgMembersOpts{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{},
|
2020-01-25 00:30:29 +05:30
|
|
|
OrgID: 3,
|
|
|
|
PublicOnly: false,
|
|
|
|
})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, err)
|
2019-11-20 16:57:49 +05:30
|
|
|
if assert.Len(t, orgUsers, 3) {
|
2017-08-28 14:47:45 +05:30
|
|
|
assert.Equal(t, OrgUser{
|
|
|
|
ID: orgUsers[0].ID,
|
|
|
|
OrgID: 3,
|
|
|
|
UID: 2,
|
2021-03-15 00:22:12 +05:30
|
|
|
IsPublic: true,
|
|
|
|
}, *orgUsers[0])
|
2017-08-28 14:47:45 +05:30
|
|
|
assert.Equal(t, OrgUser{
|
|
|
|
ID: orgUsers[1].ID,
|
|
|
|
OrgID: 3,
|
|
|
|
UID: 4,
|
2021-03-15 00:22:12 +05:30
|
|
|
IsPublic: false,
|
|
|
|
}, *orgUsers[1])
|
2017-08-28 14:47:45 +05:30
|
|
|
}
|
2017-01-24 21:46:36 +05:30
|
|
|
|
2020-01-25 00:30:29 +05:30
|
|
|
orgUsers, err = GetOrgUsersByOrgID(&FindOrgMembersOpts{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{},
|
2021-11-16 14:23:21 +05:30
|
|
|
OrgID: unittest.NonexistentID,
|
2020-01-25 00:30:29 +05:30
|
|
|
PublicOnly: false,
|
|
|
|
})
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, orgUsers, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangeOrgUserStatus(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
|
|
|
|
testSuccess := func(orgID, userID int64, public bool) {
|
|
|
|
assert.NoError(t, ChangeOrgUserStatus(orgID, userID, public))
|
2021-11-16 14:23:21 +05:30
|
|
|
orgUser := unittest.AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID}).(*OrgUser)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.Equal(t, public, orgUser.IsPublic)
|
|
|
|
}
|
|
|
|
|
|
|
|
testSuccess(3, 2, false)
|
|
|
|
testSuccess(3, 2, false)
|
|
|
|
testSuccess(3, 4, true)
|
2021-11-16 14:23:21 +05:30
|
|
|
assert.NoError(t, ChangeOrgUserStatus(unittest.NonexistentID, unittest.NonexistentID, true))
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddOrgUser(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-08-24 17:58:59 +05:30
|
|
|
testSuccess := func(orgID, userID int64, isPublic bool) {
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
expectedNumMembers := org.NumMembers
|
2021-11-16 14:23:21 +05:30
|
|
|
if !unittest.BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
|
2017-01-24 21:46:36 +05:30
|
|
|
expectedNumMembers++
|
|
|
|
}
|
|
|
|
assert.NoError(t, AddOrgUser(orgID, userID))
|
2019-08-24 17:58:59 +05:30
|
|
|
ou := &OrgUser{OrgID: orgID, UID: userID}
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, ou)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.Equal(t, isPublic, ou.IsPublic)
|
2021-11-16 14:23:21 +05:30
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.EqualValues(t, expectedNumMembers, org.NumMembers)
|
|
|
|
}
|
2019-08-24 17:58:59 +05:30
|
|
|
|
|
|
|
setting.Service.DefaultOrgMemberVisible = false
|
|
|
|
testSuccess(3, 5, false)
|
|
|
|
testSuccess(3, 5, false)
|
|
|
|
testSuccess(6, 2, false)
|
|
|
|
|
|
|
|
setting.Service.DefaultOrgMemberVisible = true
|
|
|
|
testSuccess(6, 3, true)
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveOrgUser(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-24 21:46:36 +05:30
|
|
|
testSuccess := func(orgID, userID int64) {
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
expectedNumMembers := org.NumMembers
|
2021-11-16 14:23:21 +05:30
|
|
|
if unittest.BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
|
2017-01-24 21:46:36 +05:30
|
|
|
expectedNumMembers--
|
|
|
|
}
|
|
|
|
assert.NoError(t, RemoveOrgUser(orgID, userID))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &OrgUser{OrgID: orgID, UID: userID})
|
|
|
|
org = unittest.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
assert.EqualValues(t, expectedNumMembers, org.NumMembers)
|
|
|
|
}
|
|
|
|
testSuccess(3, 4)
|
|
|
|
testSuccess(3, 4)
|
|
|
|
|
|
|
|
err := RemoveOrgUser(7, 5)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.True(t, IsErrLastOrgOwner(err))
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &OrgUser{OrgID: 7, UID: 5})
|
|
|
|
unittest.CheckConsistencyFor(t, &User{}, &Team{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_GetUserTeamIDs(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
testSuccess := func(userID int64, expected []int64) {
|
|
|
|
teamIDs, err := org.GetUserTeamIDs(userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, teamIDs)
|
|
|
|
}
|
|
|
|
testSuccess(2, []int64{1, 2})
|
|
|
|
testSuccess(4, []int64{2})
|
2021-11-16 14:23:21 +05:30
|
|
|
testSuccess(unittest.NonexistentID, []int64{})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccessibleReposEnv_CountRepos(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
testSuccess := func(userID, expectedCount int64) {
|
|
|
|
env, err := org.AccessibleReposEnv(userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
count, err := env.CountRepos()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, expectedCount, count)
|
|
|
|
}
|
2018-06-21 21:30:13 +05:30
|
|
|
testSuccess(2, 3)
|
|
|
|
testSuccess(4, 2)
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2019-06-13 01:11:28 +05:30
|
|
|
testSuccess := func(userID, _, pageSize int64, expectedRepoIDs []int64) {
|
2017-01-24 21:46:36 +05:30
|
|
|
env, err := org.AccessibleReposEnv(userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
repoIDs, err := env.RepoIDs(1, 100)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expectedRepoIDs, repoIDs)
|
|
|
|
}
|
2018-06-21 21:30:13 +05:30
|
|
|
testSuccess(2, 1, 100, []int64{3, 5, 32})
|
|
|
|
testSuccess(4, 0, 100, []int64{3, 32})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccessibleReposEnv_Repos(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
testSuccess := func(userID int64, expectedRepoIDs []int64) {
|
|
|
|
env, err := org.AccessibleReposEnv(userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
repos, err := env.Repos(1, 100)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
expectedRepos := make([]*Repository, len(expectedRepoIDs))
|
|
|
|
for i, repoID := range expectedRepoIDs {
|
2021-11-16 14:23:21 +05:30
|
|
|
expectedRepos[i] = unittest.AssertExistsAndLoadBean(t,
|
2017-01-24 21:46:36 +05:30
|
|
|
&Repository{ID: repoID}).(*Repository)
|
|
|
|
}
|
|
|
|
assert.Equal(t, expectedRepos, repos)
|
|
|
|
}
|
2018-06-21 21:30:13 +05:30
|
|
|
testSuccess(2, []int64{3, 5, 32})
|
|
|
|
testSuccess(4, []int64{3, 32})
|
2017-01-24 21:46:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2017-01-24 21:46:36 +05:30
|
|
|
testSuccess := func(userID int64, expectedRepoIDs []int64) {
|
|
|
|
env, err := org.AccessibleReposEnv(userID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
repos, err := env.MirrorRepos()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
expectedRepos := make([]*Repository, len(expectedRepoIDs))
|
|
|
|
for i, repoID := range expectedRepoIDs {
|
2021-11-16 14:23:21 +05:30
|
|
|
expectedRepos[i] = unittest.AssertExistsAndLoadBean(t,
|
2017-01-24 21:46:36 +05:30
|
|
|
&Repository{ID: repoID}).(*Repository)
|
|
|
|
}
|
|
|
|
assert.Equal(t, expectedRepos, repos)
|
|
|
|
}
|
|
|
|
testSuccess(2, []int64{5})
|
|
|
|
testSuccess(4, []int64{})
|
|
|
|
}
|
2019-02-18 21:30:27 +05:30
|
|
|
|
|
|
|
func TestHasOrgVisibleTypePublic(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
|
|
|
user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2019-02-18 21:30:27 +05:30
|
|
|
|
|
|
|
const newOrgName = "test-org-public"
|
|
|
|
org := &User{
|
|
|
|
Name: newOrgName,
|
|
|
|
Visibility: structs.VisibleTypePublic,
|
|
|
|
}
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
|
2019-02-18 21:30:27 +05:30
|
|
|
assert.NoError(t, CreateOrganization(org, owner))
|
2021-11-16 14:23:21 +05:30
|
|
|
org = unittest.AssertExistsAndLoadBean(t,
|
2019-02-18 21:30:27 +05:30
|
|
|
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
|
2021-06-27 01:23:14 +05:30
|
|
|
test1 := HasOrgOrUserVisible(org, owner)
|
|
|
|
test2 := HasOrgOrUserVisible(org, user3)
|
|
|
|
test3 := HasOrgOrUserVisible(org, nil)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.True(t, test1) // owner of org
|
|
|
|
assert.True(t, test2) // user not a part of org
|
|
|
|
assert.True(t, test3) // logged out user
|
2019-02-18 21:30:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasOrgVisibleTypeLimited(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
|
|
|
user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2019-02-18 21:30:27 +05:30
|
|
|
|
|
|
|
const newOrgName = "test-org-limited"
|
|
|
|
org := &User{
|
|
|
|
Name: newOrgName,
|
|
|
|
Visibility: structs.VisibleTypeLimited,
|
|
|
|
}
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
|
2019-02-18 21:30:27 +05:30
|
|
|
assert.NoError(t, CreateOrganization(org, owner))
|
2021-11-16 14:23:21 +05:30
|
|
|
org = unittest.AssertExistsAndLoadBean(t,
|
2019-02-18 21:30:27 +05:30
|
|
|
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
|
2021-06-27 01:23:14 +05:30
|
|
|
test1 := HasOrgOrUserVisible(org, owner)
|
|
|
|
test2 := HasOrgOrUserVisible(org, user3)
|
|
|
|
test3 := HasOrgOrUserVisible(org, nil)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.True(t, test1) // owner of org
|
|
|
|
assert.True(t, test2) // user not a part of org
|
|
|
|
assert.False(t, test3) // logged out user
|
2019-02-18 21:30:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestHasOrgVisibleTypePrivate(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 14:23:21 +05:30
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
|
|
|
user3 := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
2019-02-18 21:30:27 +05:30
|
|
|
|
|
|
|
const newOrgName = "test-org-private"
|
|
|
|
org := &User{
|
|
|
|
Name: newOrgName,
|
|
|
|
Visibility: structs.VisibleTypePrivate,
|
|
|
|
}
|
|
|
|
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
|
2019-02-18 21:30:27 +05:30
|
|
|
assert.NoError(t, CreateOrganization(org, owner))
|
2021-11-16 14:23:21 +05:30
|
|
|
org = unittest.AssertExistsAndLoadBean(t,
|
2019-02-18 21:30:27 +05:30
|
|
|
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
|
2021-06-27 01:23:14 +05:30
|
|
|
test1 := HasOrgOrUserVisible(org, owner)
|
|
|
|
test2 := HasOrgOrUserVisible(org, user3)
|
|
|
|
test3 := HasOrgOrUserVisible(org, nil)
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.True(t, test1) // owner of org
|
|
|
|
assert.False(t, test2) // user not a part of org
|
|
|
|
assert.False(t, test3) // logged out user
|
2019-02-18 21:30:27 +05:30
|
|
|
}
|
2021-03-01 06:17:30 +05:30
|
|
|
|
|
|
|
func TestGetUsersWhoCanCreateOrgRepo(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-03-01 06:17:30 +05:30
|
|
|
|
|
|
|
users, err := GetUsersWhoCanCreateOrgRepo(3)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, users, 2)
|
|
|
|
var ids []int64
|
|
|
|
for i := range users {
|
|
|
|
ids = append(ids, users[i].ID)
|
|
|
|
}
|
|
|
|
assert.ElementsMatch(t, ids, []int64{2, 28})
|
|
|
|
|
|
|
|
users, err = GetUsersWhoCanCreateOrgRepo(7)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, users, 1)
|
|
|
|
assert.EqualValues(t, 5, users[0].ID)
|
|
|
|
}
|