Reimplement GetUserOrgsList to make it simple and clear (#32486)
Reimplement GetUserOrgsList and also move some functions and test to org_list file. --------- Co-authored-by: Zettat123 <zettat123@gmail.com> (cherry picked from commit b4abb6deff14b741c7666d7579e0eea68443306c) Conflicts: models/organization/org_test.go services/oauth2_provider/access_token.go trivial conflicts due to codeblocks moving to different files
This commit is contained in:
parent
7751bb64cb
commit
f6a46055aa
5 changed files with 201 additions and 171 deletions
|
@ -129,15 +129,6 @@ func TestGetOrgByName(t *testing.T) {
|
|||
assert.True(t, organization.IsErrOrgNotExist(err))
|
||||
}
|
||||
|
||||
func TestCountOrganizations(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
expected, err := db.GetEngine(db.DefaultContext).Where("type=?", user_model.UserTypeOrganization).Count(&organization.Organization{})
|
||||
require.NoError(t, err)
|
||||
cnt, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{IncludePrivate: true})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, cnt)
|
||||
}
|
||||
|
||||
func TestIsOrganizationOwner(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(orgID, userID int64, expected bool) {
|
||||
|
@ -182,33 +173,6 @@ func TestIsPublicMembership(t *testing.T) {
|
|||
test(unittest.NonexistentID, unittest.NonexistentID, false)
|
||||
}
|
||||
|
||||
func TestFindOrgs(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
orgs, err := db.Find[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
UserID: 4,
|
||||
IncludePrivate: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, orgs, 1) {
|
||||
assert.EqualValues(t, 3, orgs[0].ID)
|
||||
}
|
||||
|
||||
orgs, err = db.Find[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
UserID: 4,
|
||||
IncludePrivate: false,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, orgs)
|
||||
|
||||
total, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
UserID: 4,
|
||||
IncludePrivate: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, 1, total)
|
||||
}
|
||||
|
||||
func TestGetOrgUsersByOrgID(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue