diff options
Diffstat (limited to 'store/sqlstore/user_store_test.go')
-rw-r--r-- | store/sqlstore/user_store_test.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/store/sqlstore/user_store_test.go b/store/sqlstore/user_store_test.go index d46513ccc..646d785f7 100644 --- a/store/sqlstore/user_store_test.go +++ b/store/sqlstore/user_store_test.go @@ -1334,10 +1334,28 @@ func TestUserStoreSearch(t *testing.T) { u3.DeleteAt = 1 store.Must(ss.User().Save(u3)) + u5 := &model.User{} + u5.Username = "yu" + model.NewId() + u5.FirstName = "En" + u5.LastName = "Yu" + u5.Nickname = "enyu" + u5.Email = model.NewId() + "@simulator.amazonses.com" + store.Must(ss.User().Save(u5)) + + u6 := &model.User{} + u6.Username = "underscore" + model.NewId() + u6.FirstName = "Du_" + u6.LastName = "_DE" + u6.Nickname = "lodash" + u6.Email = model.NewId() + "@simulator.amazonses.com" + store.Must(ss.User().Save(u6)) + tid := model.NewId() store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u1.Id})) store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u2.Id})) store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u3.Id})) + store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u5.Id})) + store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u6.Id})) searchOptions := map[string]bool{} searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true @@ -1367,6 +1385,22 @@ func TestUserStoreSearch(t *testing.T) { } } + if r1 := <-ss.User().Search(tid, "en", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found1 := false + for _, profile := range profiles { + if profile.Id == u5.Id { + found1 = true + } + } + + if !found1 { + t.Fatal("should have found user") + } + } + searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = false if r1 := <-ss.User().Search(tid, u1.Email, searchOptions); r1.Err != nil { @@ -1429,6 +1463,56 @@ func TestUserStoreSearch(t *testing.T) { } } + // % should be escaped and searched for. + if r1 := <-ss.User().Search(tid, "h%", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + if len(profiles) != 0 { + t.Fatal("shouldn't have found anything") + } + } + + // "_" should be properly escaped and searched for. + if r1 := <-ss.User().Search(tid, "h_", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + if len(profiles) != 0 { + t.Fatal("shouldn't have found anything") + } + } + if r1 := <-ss.User().Search(tid, "Du_", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found6 := false + for _, profile := range profiles { + if profile.Id == u6.Id { + found6 = true + } + } + + if !found6 { + t.Fatal("should have found user") + } + } + if r1 := <-ss.User().Search(tid, "_dE", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found6 := false + for _, profile := range profiles { + if profile.Id == u6.Id { + found6 = true + } + } + + if !found6 { + t.Fatal("should have found user") + } + } + searchOptions[store.USER_SEARCH_OPTION_ALLOW_INACTIVE] = true if r1 := <-ss.User().Search(tid, "jimb", searchOptions); r1.Err != nil { |