@ -7,6 +7,7 @@ package models
import (
import (
"testing"
"testing"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
@ -429,20 +430,28 @@ func TestChangeOrgUserStatus(t *testing.T) {
func TestAddOrgUser ( t * testing . T ) {
func TestAddOrgUser ( t * testing . T ) {
assert . NoError ( t , PrepareTestDatabase ( ) )
assert . NoError ( t , PrepareTestDatabase ( ) )
testSuccess := func ( orgID , userID int64 ) {
testSuccess := func ( orgID , userID int64 , isPublic bool ) {
org := AssertExistsAndLoadBean ( t , & User { ID : orgID } ) . ( * User )
org := AssertExistsAndLoadBean ( t , & User { ID : orgID } ) . ( * User )
expectedNumMembers := org . NumMembers
expectedNumMembers := org . NumMembers
if ! BeanExists ( t , & OrgUser { OrgID : orgID , UID : userID } ) {
if ! BeanExists ( t , & OrgUser { OrgID : orgID , UID : userID } ) {
expectedNumMembers ++
expectedNumMembers ++
}
}
assert . NoError ( t , AddOrgUser ( orgID , userID ) )
assert . NoError ( t , AddOrgUser ( orgID , userID ) )
AssertExistsAndLoadBean ( t , & OrgUser { OrgID : orgID , UID : userID } )
ou := & OrgUser { OrgID : orgID , UID : userID }
AssertExistsAndLoadBean ( t , ou )
assert . Equal ( t , ou . IsPublic , isPublic )
org = AssertExistsAndLoadBean ( t , & User { ID : orgID } ) . ( * User )
org = AssertExistsAndLoadBean ( t , & User { ID : orgID } ) . ( * User )
assert . EqualValues ( t , expectedNumMembers , org . NumMembers )
assert . EqualValues ( t , expectedNumMembers , org . NumMembers )
}
}
testSuccess ( 3 , 5 )
testSuccess ( 3 , 5 )
setting . Service . DefaultOrgMemberVisible = false
testSuccess ( 6 , 2 )
testSuccess ( 3 , 5 , false )
testSuccess ( 3 , 5 , false )
testSuccess ( 6 , 2 , false )
setting . Service . DefaultOrgMemberVisible = true
testSuccess ( 6 , 3 , true )
CheckConsistencyFor ( t , & User { } , & Team { } )
CheckConsistencyFor ( t , & User { } , & Team { } )
}
}