|
|
@ -12,28 +12,44 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
func TestUser_IsOwnedBy(t *testing.T) { |
|
|
|
func TestUser_IsOwnedBy(t *testing.T) { |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) |
|
|
|
for _, testCase := range []struct { |
|
|
|
assert.True(t, org.IsOwnedBy(2)) |
|
|
|
OrgID int64 |
|
|
|
assert.False(t, org.IsOwnedBy(1)) |
|
|
|
UserID int64 |
|
|
|
assert.False(t, org.IsOwnedBy(3)) |
|
|
|
ExpectedOwner bool |
|
|
|
assert.False(t, org.IsOwnedBy(4)) |
|
|
|
}{ |
|
|
|
|
|
|
|
{3, 2, true}, |
|
|
|
nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) |
|
|
|
{3, 1, false}, |
|
|
|
assert.False(t, nonOrg.IsOwnedBy(2)) |
|
|
|
{3, 3, false}, |
|
|
|
assert.False(t, nonOrg.IsOwnedBy(3)) |
|
|
|
{3, 4, false}, |
|
|
|
|
|
|
|
{2, 2, false}, // user2 is not an organization
|
|
|
|
|
|
|
|
{2, 3, false}, |
|
|
|
|
|
|
|
} { |
|
|
|
|
|
|
|
org := AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User) |
|
|
|
|
|
|
|
isOwner, err := org.IsOwnedBy(testCase.UserID) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
assert.Equal(t, testCase.ExpectedOwner, isOwner) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestUser_IsOrgMember(t *testing.T) { |
|
|
|
func TestUser_IsOrgMember(t *testing.T) { |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) |
|
|
|
for _, testCase := range []struct { |
|
|
|
assert.True(t, org.IsOrgMember(2)) |
|
|
|
OrgID int64 |
|
|
|
assert.True(t, org.IsOrgMember(4)) |
|
|
|
UserID int64 |
|
|
|
assert.False(t, org.IsOrgMember(1)) |
|
|
|
ExpectedMember bool |
|
|
|
assert.False(t, org.IsOrgMember(3)) |
|
|
|
}{ |
|
|
|
|
|
|
|
{3, 2, true}, |
|
|
|
nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) |
|
|
|
{3, 4, true}, |
|
|
|
assert.False(t, nonOrg.IsOrgMember(2)) |
|
|
|
{3, 1, false}, |
|
|
|
assert.False(t, nonOrg.IsOrgMember(3)) |
|
|
|
{3, 3, false}, |
|
|
|
|
|
|
|
{2, 2, false}, // user2 is not an organization
|
|
|
|
|
|
|
|
{2, 3, false}, |
|
|
|
|
|
|
|
} { |
|
|
|
|
|
|
|
org := AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User) |
|
|
|
|
|
|
|
isMember, err := org.IsOrgMember(testCase.UserID) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
assert.Equal(t, testCase.ExpectedMember, isMember) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestUser_GetTeam(t *testing.T) { |
|
|
|
func TestUser_GetTeam(t *testing.T) { |
|
|
@ -257,31 +273,46 @@ func TestDeleteOrganization(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestIsOrganizationOwner(t *testing.T) { |
|
|
|
func TestIsOrganizationOwner(t *testing.T) { |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.True(t, IsOrganizationOwner(3, 2)) |
|
|
|
test := func(orgID, userID int64, expected bool) { |
|
|
|
assert.False(t, IsOrganizationOwner(3, 3)) |
|
|
|
isOwner, err := IsOrganizationOwner(orgID, userID) |
|
|
|
assert.True(t, IsOrganizationOwner(6, 5)) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.False(t, IsOrganizationOwner(6, 4)) |
|
|
|
assert.EqualValues(t, expected, isOwner) |
|
|
|
assert.False(t, IsOrganizationOwner(NonexistentID, NonexistentID)) |
|
|
|
} |
|
|
|
|
|
|
|
test(3, 2, true) |
|
|
|
|
|
|
|
test(3, 3, false) |
|
|
|
|
|
|
|
test(6, 5, true) |
|
|
|
|
|
|
|
test(6, 4, false) |
|
|
|
|
|
|
|
test(NonexistentID, NonexistentID, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestIsOrganizationMember(t *testing.T) { |
|
|
|
func TestIsOrganizationMember(t *testing.T) { |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.True(t, IsOrganizationMember(3, 2)) |
|
|
|
test := func(orgID, userID int64, expected bool) { |
|
|
|
assert.False(t, IsOrganizationMember(3, 3)) |
|
|
|
isMember, err := IsOrganizationMember(orgID, userID) |
|
|
|
assert.True(t, IsOrganizationMember(3, 4)) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.True(t, IsOrganizationMember(6, 5)) |
|
|
|
assert.EqualValues(t, expected, isMember) |
|
|
|
assert.False(t, IsOrganizationMember(6, 4)) |
|
|
|
} |
|
|
|
assert.False(t, IsOrganizationMember(NonexistentID, NonexistentID)) |
|
|
|
test(3, 2, true) |
|
|
|
|
|
|
|
test(3, 3, false) |
|
|
|
|
|
|
|
test(3, 4, true) |
|
|
|
|
|
|
|
test(6, 5, true) |
|
|
|
|
|
|
|
test(6, 4, false) |
|
|
|
|
|
|
|
test(NonexistentID, NonexistentID, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestIsPublicMembership(t *testing.T) { |
|
|
|
func TestIsPublicMembership(t *testing.T) { |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.NoError(t, PrepareTestDatabase()) |
|
|
|
assert.True(t, IsPublicMembership(3, 2)) |
|
|
|
test := func(orgID, userID int64, expected bool) { |
|
|
|
assert.False(t, IsPublicMembership(3, 3)) |
|
|
|
isMember, err := IsPublicMembership(orgID, userID) |
|
|
|
assert.False(t, IsPublicMembership(3, 4)) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.True(t, IsPublicMembership(6, 5)) |
|
|
|
assert.EqualValues(t, expected, isMember) |
|
|
|
assert.False(t, IsPublicMembership(6, 4)) |
|
|
|
} |
|
|
|
assert.False(t, IsPublicMembership(NonexistentID, NonexistentID)) |
|
|
|
test(3, 2, true) |
|
|
|
|
|
|
|
test(3, 3, false) |
|
|
|
|
|
|
|
test(3, 4, false) |
|
|
|
|
|
|
|
test(6, 5, true) |
|
|
|
|
|
|
|
test(6, 4, false) |
|
|
|
|
|
|
|
test(NonexistentID, NonexistentID, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestGetOrgsByUserID(t *testing.T) { |
|
|
|
func TestGetOrgsByUserID(t *testing.T) { |
|
|
|