diff options
author | Rémy Boulanouar <rboulanouar@gmail.com> | 2019-02-18 17:00:27 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-02-18 18:00:27 +0200 |
commit | 64ce159a6eacc81962d07a8f5ef7f69c17365363 (patch) | |
tree | d6b94d035de14df8b1a773d97ab35937cce1d00a /models/org_test.go | |
parent | ae3a913122d3430ccf14da22f09daf6f636a00f8 (diff) | |
download | gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.tar.gz gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.zip |
Allow to set organization visibility (public, internal, private) (#1763)
Diffstat (limited to 'models/org_test.go')
-rw-r--r-- | models/org_test.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/models/org_test.go b/models/org_test.go index 4790f69971..b484208be1 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -7,6 +7,8 @@ package models import ( "testing" + "code.gitea.io/gitea/modules/structs" + "github.com/stretchr/testify/assert" ) @@ -545,3 +547,72 @@ func TestAccessibleReposEnv_MirrorRepos(t *testing.T) { testSuccess(2, []int64{5}) testSuccess(4, []int64{}) } + +func TestHasOrgVisibleTypePublic(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) + + const newOrgName = "test-org-public" + org := &User{ + Name: newOrgName, + Visibility: structs.VisibleTypePublic, + } + + AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization}) + assert.NoError(t, CreateOrganization(org, owner)) + org = AssertExistsAndLoadBean(t, + &User{Name: org.Name, Type: UserTypeOrganization}).(*User) + test1 := HasOrgVisible(org, owner) + test2 := HasOrgVisible(org, user3) + test3 := HasOrgVisible(org, nil) + assert.Equal(t, test1, true) // owner of org + assert.Equal(t, test2, true) // user not a part of org + assert.Equal(t, test3, true) // logged out user +} + +func TestHasOrgVisibleTypeLimited(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) + + const newOrgName = "test-org-limited" + org := &User{ + Name: newOrgName, + Visibility: structs.VisibleTypeLimited, + } + + AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization}) + assert.NoError(t, CreateOrganization(org, owner)) + org = AssertExistsAndLoadBean(t, + &User{Name: org.Name, Type: UserTypeOrganization}).(*User) + test1 := HasOrgVisible(org, owner) + test2 := HasOrgVisible(org, user3) + test3 := HasOrgVisible(org, nil) + assert.Equal(t, test1, true) // owner of org + assert.Equal(t, test2, true) // user not a part of org + assert.Equal(t, test3, false) // logged out user +} + +func TestHasOrgVisibleTypePrivate(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) + + const newOrgName = "test-org-private" + org := &User{ + Name: newOrgName, + Visibility: structs.VisibleTypePrivate, + } + + AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization}) + assert.NoError(t, CreateOrganization(org, owner)) + org = AssertExistsAndLoadBean(t, + &User{Name: org.Name, Type: UserTypeOrganization}).(*User) + test1 := HasOrgVisible(org, owner) + test2 := HasOrgVisible(org, user3) + test3 := HasOrgVisible(org, nil) + assert.Equal(t, test1, true) // owner of org + assert.Equal(t, test2, false) // user not a part of org + assert.Equal(t, test3, false) // logged out user +} |