diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-11-02 14:38:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-02 14:38:34 -0400 |
commit | 137ade29d061e158543da814ecd0d06d7e992c1f (patch) | |
tree | cb528f2db486f78a4e9fe5a75a693ce6d3968cca /store/sql_user_store_test.go | |
parent | b45cc443c9e9fdf8147d354b95b6fecb31b2e7b2 (diff) | |
download | chat-137ade29d061e158543da814ecd0d06d7e992c1f.tar.gz chat-137ade29d061e158543da814ecd0d06d7e992c1f.tar.bz2 chat-137ade29d061e158543da814ecd0d06d7e992c1f.zip |
PLT-4535/PLT-4503 Fix inactive users in searches and add option functionality to DB user search (#4413)
* Add options to user database search
* Fix inactive users showing up incorrectly in some user searches
* Read JSON for searchUsers API into anonymous struct
* Move anonymous struct to be a normal struct in model directory and upadte client to use it
* Added clarification comment about slightly odd query condition in search
Diffstat (limited to 'store/sql_user_store_test.go')
-rw-r--r-- | store/sql_user_store_test.go | 90 |
1 files changed, 78 insertions, 12 deletions
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index 23c124cb7..bc7cc69c5 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -942,11 +942,75 @@ func TestUserStoreSearch(t *testing.T) { u2.Email = model.NewId() Must(store.User().Save(u2)) + u3 := &model.User{} + u3.Username = "jimbo" + model.NewId() + u3.Email = model.NewId() + u3.DeleteAt = 1 + Must(store.User().Save(u3)) + tid := model.NewId() Must(store.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u1.Id})) Must(store.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u2.Id})) + Must(store.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u3.Id})) + + searchOptions := map[string]bool{} + searchOptions[USER_SEARCH_OPTION_USERNAME_ONLY] = true + + if r1 := <-store.User().Search(tid, "jimb", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found1 := false + found2 := false + for _, profile := range profiles { + if profile.Id == u1.Id { + found1 = true + } + + if profile.Id == u3.Id { + found2 = true + } + } + + if !found1 { + t.Fatal("should have found user") + } + + if found2 { + t.Fatal("should not have found inactive user") + } + } - if r1 := <-store.User().Search(tid, "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + searchOptions[USER_SEARCH_OPTION_ALLOW_INACTIVE] = true + + if r1 := <-store.User().Search(tid, "jimb", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found1 := false + found2 := false + for _, profile := range profiles { + if profile.Id == u1.Id { + found1 = true + } + + if profile.Id == u3.Id { + found2 = true + } + } + + if !found1 { + t.Fatal("should have found user") + } + + if !found2 { + t.Fatal("should have found inactive user") + } + } + + searchOptions[USER_SEARCH_OPTION_ALLOW_INACTIVE] = false + + if r1 := <-store.User().Search(tid, "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -963,7 +1027,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().Search("", "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().Search("", "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -980,7 +1044,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().Search("", "jim-bobb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().Search("", "jim-bobb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -998,7 +1062,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().Search(tid, "", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().Search(tid, "", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } @@ -1009,7 +1073,7 @@ func TestUserStoreSearch(t *testing.T) { c1.Type = model.CHANNEL_OPEN c1 = *Must(store.Channel().Save(&c1)).(*model.Channel) - if r1 := <-store.User().SearchNotInChannel(tid, c1.Id, "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().SearchNotInChannel(tid, c1.Id, "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1026,7 +1090,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().SearchNotInChannel("", c1.Id, "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().SearchNotInChannel("", c1.Id, "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1043,7 +1107,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().SearchNotInChannel("junk", c1.Id, "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().SearchNotInChannel("junk", c1.Id, "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1060,7 +1124,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().SearchInChannel(c1.Id, "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().SearchInChannel(c1.Id, "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1079,7 +1143,7 @@ func TestUserStoreSearch(t *testing.T) { Must(store.Channel().SaveMember(&model.ChannelMember{ChannelId: c1.Id, UserId: u1.Id, NotifyProps: model.GetDefaultChannelNotifyProps()})) - if r1 := <-store.User().SearchInChannel(c1.Id, "jimb", USER_SEARCH_TYPE_USERNAME); r1.Err != nil { + if r1 := <-store.User().SearchInChannel(c1.Id, "jimb", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1096,7 +1160,9 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().Search(tid, "Tim", USER_SEARCH_TYPE_ALL); r1.Err != nil { + searchOptions = map[string]bool{} + + if r1 := <-store.User().Search(tid, "Tim", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1113,7 +1179,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().Search(tid, "Bill", USER_SEARCH_TYPE_ALL); r1.Err != nil { + if r1 := <-store.User().Search(tid, "Bill", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) @@ -1130,7 +1196,7 @@ func TestUserStoreSearch(t *testing.T) { } } - if r1 := <-store.User().Search(tid, "Rob", USER_SEARCH_TYPE_ALL); r1.Err != nil { + if r1 := <-store.User().Search(tid, "Rob", searchOptions); r1.Err != nil { t.Fatal(r1.Err) } else { profiles := r1.Data.([]*model.User) |