aboutsummaryrefslogtreecommitdiffstats
path: root/models/user_test.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-08-02 18:06:28 +0200
committertechknowlogick <techknowlogick@gitea.io>2019-08-02 12:06:27 -0400
commit76408d50fb338e9239ee06bb26eec28453167300 (patch)
tree552f49cb095e9744c11f71dba9a3910a7d0ceb18 /models/user_test.go
parent3566d2c860b0ad3ab7d6d5fb1490eb9a5b5f5974 (diff)
downloadgitea-76408d50fb338e9239ee06bb26eec28453167300.tar.gz
gitea-76408d50fb338e9239ee06bb26eec28453167300.zip
org/members: display 2FA members states + optimize sql requests (#7621)
* org/members: display 2FA state * fix comment typo * lay down UserList bases * add basic test for previous methods * add comment for UserList type * add valid two-fa account * test new UserList methods * optimize MembersIsPublic by side loading info on GetMembers + fix integrations tests * respect fmt rules * use map for data * Optimize GetTwoFaStatus * rewrite by using existing sub func * Optimize IsUserOrgOwner * remove un-used code * tests: cover empty org + fix import order * tests: add ErrTeamNotExist path * tests: fix wrong expected result
Diffstat (limited to 'models/user_test.go')
-rw-r--r--models/user_test.go59
1 files changed, 56 insertions, 3 deletions
diff --git a/models/user_test.go b/models/user_test.go
index 10420a143f..290253c4b1 100644
--- a/models/user_test.go
+++ b/models/user_test.go
@@ -5,6 +5,7 @@
package models
import (
+ "fmt"
"math/rand"
"strings"
"testing"
@@ -15,6 +16,58 @@ import (
"github.com/stretchr/testify/assert"
)
+func TestUserIsPublicMember(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ tt := []struct {
+ uid int64
+ orgid int64
+ expected bool
+ }{
+ {2, 3, true},
+ {4, 3, false},
+ {5, 6, true},
+ {5, 7, false},
+ }
+ for _, v := range tt {
+ t.Run(fmt.Sprintf("UserId%dIsPublicMemberOf%d", v.uid, v.orgid), func(t *testing.T) {
+ testUserIsPublicMember(t, v.uid, v.orgid, v.expected)
+ })
+ }
+}
+
+func testUserIsPublicMember(t *testing.T, uid int64, orgID int64, expected bool) {
+ user, err := GetUserByID(uid)
+ assert.NoError(t, err)
+ assert.Equal(t, expected, user.IsPublicMember(orgID))
+}
+
+func TestIsUserOrgOwner(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ tt := []struct {
+ uid int64
+ orgid int64
+ expected bool
+ }{
+ {2, 3, true},
+ {4, 3, false},
+ {5, 6, true},
+ {5, 7, true},
+ }
+ for _, v := range tt {
+ t.Run(fmt.Sprintf("UserId%dIsOrgOwnerOf%d", v.uid, v.orgid), func(t *testing.T) {
+ testIsUserOrgOwner(t, v.uid, v.orgid, v.expected)
+ })
+ }
+}
+
+func testIsUserOrgOwner(t *testing.T, uid int64, orgID int64, expected bool) {
+ user, err := GetUserByID(uid)
+ assert.NoError(t, err)
+ assert.Equal(t, expected, user.IsUserOrgOwner(orgID))
+}
+
func TestGetUserEmailsByNames(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
@@ -83,7 +136,7 @@ func TestSearchUsers(t *testing.T) {
[]int64{7, 17})
testOrgSuccess(&SearchUserOptions{OrderBy: "id ASC", Page: 3, PageSize: 2},
- []int64{19})
+ []int64{19, 25})
testOrgSuccess(&SearchUserOptions{Page: 4, PageSize: 2},
[]int64{})
@@ -95,13 +148,13 @@ func TestSearchUsers(t *testing.T) {
}
testUserSuccess(&SearchUserOptions{OrderBy: "id ASC", Page: 1},
- []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21})
+ []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24})
testUserSuccess(&SearchUserOptions{Page: 1, IsActive: util.OptionalBoolFalse},
[]int64{9})
testUserSuccess(&SearchUserOptions{OrderBy: "id ASC", Page: 1, IsActive: util.OptionalBoolTrue},
- []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21})
+ []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24})
testUserSuccess(&SearchUserOptions{Keyword: "user1", OrderBy: "id ASC", Page: 1, IsActive: util.OptionalBoolTrue},
[]int64{1, 10, 11, 12, 13, 14, 15, 16, 18})