@ -4,6 +4,7 @@
package organization_test
import (
"sort"
"testing"
"code.gitea.io/gitea/models/db"
@ -103,7 +104,7 @@ func TestUser_GetTeams(t *testing.T) {
func TestUser_GetMembers ( t * testing . T ) {
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
org := unittest . AssertExistsAndLoadBean ( t , & organization . Organization { ID : 3 } )
members , _ , err := org . GetMembers ( db . DefaultContext )
members , _ , err := org . GetMembers ( db . DefaultContext , & user_model . User { IsAdmin : true } )
assert . NoError ( t , err )
if assert . Len ( t , members , 3 ) {
assert . Equal ( t , int64 ( 2 ) , members [ 0 ] . ID )
@ -210,37 +211,42 @@ func TestFindOrgs(t *testing.T) {
func TestGetOrgUsersByOrgID ( t * testing . T ) {
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
orgUsers , err := organization . GetOrgUsersByOrgID ( db . DefaultContext , & organization . FindOrgMembersOpts {
ListOptions : db . ListOptions { } ,
opts := & organization . FindOrgMembersOpts {
Doer : & user_model . User { IsAdmin : true } ,
OrgID : 3 ,
PublicOnly : false ,
} )
}
assert . False ( t , opts . PublicOnly ( ) )
orgUsers , err := organization . GetOrgUsersByOrgID ( db . DefaultContext , opts )
assert . NoError ( t , err )
if assert . Len ( t , orgUsers , 3 ) {
assert . Equal ( t , organization . OrgUser {
ID : orgUsers [ 0 ] . ID ,
sort . Slice ( orgUsers , func ( i , j int ) bool {
return orgUsers [ i ] . ID < orgUsers [ j ] . ID
} )
assert . EqualValues ( t , [ ] * organization . OrgUser { {
ID : 1 ,
OrgID : 3 ,
UID : 2 ,
IsPublic : true ,
} , * orgUsers [ 0 ] )
assert . Equal ( t , organization . OrgUser {
ID : orgUsers [ 1 ] . ID ,
} , {
ID : 2 ,
OrgID : 3 ,
UID : 4 ,
IsPublic : false ,
} , * orgUsers [ 1 ] )
assert . Equal ( t , organization . OrgUser {
ID : orgUsers [ 2 ] . ID ,
} , {
ID : 9 ,
OrgID : 3 ,
UID : 28 ,
IsPublic : true ,
} , * orgUsers [ 2 ] )
}
} } , orgUsers )
opts = & organization . FindOrgMembersOpts { OrgID : 3 }
assert . True ( t , opts . PublicOnly ( ) )
orgUsers , err = organization . GetOrgUsersByOrgID ( db . DefaultContext , opts )
assert . NoError ( t , err )
assert . Len ( t , orgUsers , 2 )
orgUsers , err = organization . GetOrgUsersByOrgID ( db . DefaultContext , & organization . FindOrgMembersOpts {
ListOptions : db . ListOptions { } ,
OrgID : unittest . NonexistentID ,
PublicOnly : false ,
} )
assert . NoError ( t , err )
assert . Len ( t , orgUsers , 0 )