summaryrefslogtreecommitdiffstats
path: root/store/sql_user_store_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-04-03 13:32:58 -0400
committerCorey Hulen <corey@hulen.com>2017-04-03 10:32:58 -0700
commit6b61834ab14e9a4e51c29dd2904a1332c327aae6 (patch)
tree283122751e3e8c13cc058c4c575fd0e6d7a7549e /store/sql_user_store_test.go
parente49f5928c55ba57c39efa11c568c66342b962aae (diff)
downloadchat-6b61834ab14e9a4e51c29dd2904a1332c327aae6.tar.gz
chat-6b61834ab14e9a4e51c29dd2904a1332c327aae6.tar.bz2
chat-6b61834ab14e9a4e51c29dd2904a1332c327aae6.zip
Add store unit tests and add make target for testing store with postgres (#5925)
* Add store unit tests and add make target for testing store with postgres * Remove postgres target form test-server target * Fix audit test
Diffstat (limited to 'store/sql_user_store_test.go')
-rw-r--r--store/sql_user_store_test.go80
1 files changed, 76 insertions, 4 deletions
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index db1ade5f7..bfd74d55a 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -130,6 +130,10 @@ func TestUserStoreUpdate(t *testing.T) {
t.Fatal("Email should have been updated as the update is trusted")
}
}
+
+ if result := <-store.User().UpdateLastPictureUpdate(u1.Id); result.Err != nil {
+ t.Fatal("Update should not have failed")
+ }
}
func TestUserStoreUpdateUpdateAt(t *testing.T) {
@@ -217,20 +221,39 @@ func TestUserCount(t *testing.T) {
}
}
-func TestUserStoreGetAllProfiles(t *testing.T) {
+func TestGetAllUsingAuthService(t *testing.T) {
Setup()
- teamId := model.NewId()
+ u1 := &model.User{}
+ u1.Email = model.NewId()
+ u1.AuthService = "someservice"
+ Must(store.User().Save(u1))
+
+ u2 := &model.User{}
+ u2.Email = model.NewId()
+ u2.AuthService = "someservice"
+ Must(store.User().Save(u2))
+
+ if r1 := <-store.User().GetAllUsingAuthService(u1.AuthService); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ users := r1.Data.([]*model.User)
+ if len(users) < 2 {
+ t.Fatal("invalid returned users")
+ }
+ }
+}
+
+func TestUserStoreGetAllProfiles(t *testing.T) {
+ Setup()
u1 := &model.User{}
u1.Email = model.NewId()
Must(store.User().Save(u1))
- Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id}))
u2 := &model.User{}
u2.Email = model.NewId()
Must(store.User().Save(u2))
- Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u2.Id}))
if r1 := <-store.User().GetAllProfiles(0, 100); r1.Err != nil {
t.Fatal(r1.Err)
@@ -249,6 +272,34 @@ func TestUserStoreGetAllProfiles(t *testing.T) {
t.Fatal("invalid returned users, limit did not work")
}
}
+
+ if r2 := <-store.User().GetAll(); r2.Err != nil {
+ t.Fatal(r2.Err)
+ } else {
+ users := r2.Data.([]*model.User)
+ if len(users) < 2 {
+ t.Fatal("invalid returned users")
+ }
+ }
+
+ etag := ""
+ if r2 := <-store.User().GetEtagForAllProfiles(); r2.Err != nil {
+ t.Fatal(r2.Err)
+ } else {
+ etag = r2.Data.(string)
+ }
+
+ u3 := &model.User{}
+ u3.Email = model.NewId()
+ Must(store.User().Save(u3))
+
+ if r2 := <-store.User().GetEtagForAllProfiles(); r2.Err != nil {
+ t.Fatal(r2.Err)
+ } else {
+ if etag == r2.Data.(string) {
+ t.Fatal("etags should not match")
+ }
+ }
}
func TestUserStoreGetProfiles(t *testing.T) {
@@ -293,6 +344,26 @@ func TestUserStoreGetProfiles(t *testing.T) {
t.Fatal("should have returned empty map")
}
}
+
+ etag := ""
+ if r2 := <-store.User().GetEtagForProfiles(teamId); r2.Err != nil {
+ t.Fatal(r2.Err)
+ } else {
+ etag = r2.Data.(string)
+ }
+
+ u3 := &model.User{}
+ u3.Email = model.NewId()
+ Must(store.User().Save(u3))
+ Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u3.Id}))
+
+ if r2 := <-store.User().GetEtagForProfiles(teamId); r2.Err != nil {
+ t.Fatal(r2.Err)
+ } else {
+ if etag == r2.Data.(string) {
+ t.Fatal("etags should not match")
+ }
+ }
}
func TestUserStoreGetProfilesInChannel(t *testing.T) {
@@ -502,6 +573,7 @@ func TestUserStoreGetAllProfilesInChannel(t *testing.T) {
}
}
+ store.User().InvalidateProfilesInChannelCacheByUser(u1.Id)
store.User().InvalidateProfilesInChannelCache(c2.Id)
}