summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store_test.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-04-25 11:00:41 -0400
committerCorey Hulen <corey@hulen.com>2017-04-25 08:00:41 -0700
commitdb68e598a10d36013b7ff0994eca86e0464355e1 (patch)
treeec0f5e42c42d43afd4476f7e6b5ba9d3484577cc /store/sql_user_store_test.go
parentcb668b92832193df7549c5a16543dcdfed44be56 (diff)
downloadchat-db68e598a10d36013b7ff0994eca86e0464355e1.tar.gz
chat-db68e598a10d36013b7ff0994eca86e0464355e1.tar.bz2
chat-db68e598a10d36013b7ff0994eca86e0464355e1.zip
PLT-4457 Added API to get multiple users by their usernames (#6218)
* Allow getting profiles by username without a team * Changed UserStore.GetProfilesByUsernames to return an array * PLT-4457 Added API to get multiple users by their usernames * Changed users/names route to users/usernames
Diffstat (limited to 'store/sql_user_store_test.go')
-rw-r--r--store/sql_user_store_test.go52
1 files changed, 47 insertions, 5 deletions
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index 7d7379668..367dc46dc 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -836,25 +836,67 @@ func TestUserStoreGetProfilesByUsernames(t *testing.T) {
if r1 := <-store.User().GetProfilesByUsernames([]string{u1.Username, u2.Username}, teamId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 2 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
- t.Fatal("invalid returned user")
+ if users[0].Id != u1.Id && users[1].Id != u1.Id {
+ t.Fatal("invalid returned user 1")
+ }
+
+ if users[0].Id != u2.Id && users[1].Id != u2.Id {
+ t.Fatal("invalid returned user 2")
}
}
if r1 := <-store.User().GetProfilesByUsernames([]string{u1.Username}, teamId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- users := r1.Data.(map[string]*model.User)
+ users := r1.Data.([]*model.User)
if len(users) != 1 {
t.Fatal("invalid returned users")
}
- if users[u1.Id].Id != u1.Id {
+ if users[0].Id != u1.Id {
+ t.Fatal("invalid returned user")
+ }
+ }
+
+ team2Id := model.NewId()
+
+ u3 := &model.User{}
+ u3.Email = model.NewId()
+ u3.Username = "username3" + model.NewId()
+ Must(store.User().Save(u3))
+ Must(store.Team().SaveMember(&model.TeamMember{TeamId: team2Id, UserId: u3.Id}))
+
+ if r1 := <-store.User().GetProfilesByUsernames([]string{u1.Username, u3.Username}, ""); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ users := r1.Data.([]*model.User)
+ if len(users) != 2 {
+ t.Fatal("invalid returned users")
+ }
+
+ if users[0].Id != u1.Id && users[1].Id != u1.Id {
+ t.Fatal("invalid returned user 1")
+ }
+
+ if users[0].Id != u3.Id && users[1].Id != u3.Id {
+ t.Fatal("invalid returned user 3")
+ }
+ }
+
+ if r1 := <-store.User().GetProfilesByUsernames([]string{u1.Username, u3.Username}, teamId); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ users := r1.Data.([]*model.User)
+ if len(users) != 1 {
+ t.Fatal("invalid returned users")
+ }
+
+ if users[0].Id != u1.Id {
t.Fatal("invalid returned user")
}
}