summaryrefslogtreecommitdiffstats
path: root/store/sql_team_store_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-13 09:46:28 -0400
committerChristopher Speller <crspeller@gmail.com>2017-03-13 09:46:28 -0400
commita284cd8c1817bb5419cb9eae118c85cd7e99c039 (patch)
tree71fd6ace54692477acea746f47b3266514ae9292 /store/sql_team_store_test.go
parent5ec49c0db03d4ec6fd36619055f99c9a3bb34148 (diff)
downloadchat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.tar.gz
chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.tar.bz2
chat-a284cd8c1817bb5419cb9eae118c85cd7e99c039.zip
Implement some team endpoints for APIv4 (#5745)
* Implement PUT /teams/{team_id} endpoint for APIv4 * Implement GET /users/{user_id}/teams/{team_id}/unread endpoint for APIv4 * Implement POST /teams/{team_id}/members/ids endpoint for APIv4 * Remove debug statement
Diffstat (limited to 'store/sql_team_store_test.go')
-rw-r--r--store/sql_team_store_test.go55
1 files changed, 48 insertions, 7 deletions
diff --git a/store/sql_team_store_test.go b/store/sql_team_store_test.go
index 58ac74fc0..3aeb14c9c 100644
--- a/store/sql_team_store_test.go
+++ b/store/sql_team_store_test.go
@@ -554,7 +554,7 @@ func TestTeamStoreMemberCount(t *testing.T) {
}
}
-func TestMyTeamMembersUnread(t *testing.T) {
+func TestGetChannelUnreadsForAllTeams(t *testing.T) {
Setup()
teamId1 := model.NewId()
@@ -566,17 +566,17 @@ func TestMyTeamMembersUnread(t *testing.T) {
Must(store.Team().SaveMember(m1))
Must(store.Team().SaveMember(m2))
- c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN}
+ c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
Must(store.Channel().Save(c1))
- c2 := &model.Channel{TeamId: m2.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN}
+ c2 := &model.Channel{TeamId: m2.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
Must(store.Channel().Save(c2))
- cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps()}
+ cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
Must(store.Channel().SaveMember(cm1))
- cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m2.UserId, NotifyProps: model.GetDefaultChannelNotifyProps()}
+ cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m2.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
Must(store.Channel().SaveMember(cm2))
- if r1 := <-store.Team().GetTeamsUnreadForUser("", uid); r1.Err != nil {
+ if r1 := <-store.Team().GetChannelUnreadsForAllTeams("", uid); r1.Err != nil {
t.Fatal(r1.Err)
} else {
ms := r1.Data.([]*model.ChannelUnread)
@@ -590,9 +590,13 @@ func TestMyTeamMembersUnread(t *testing.T) {
if len(membersMap) != 2 {
t.Fatal("Should be the unreads for all the teams")
}
+
+ if ms[0].MsgCount != 10 {
+ t.Fatal("subtraction failed")
+ }
}
- if r2 := <-store.Team().GetTeamsUnreadForUser(teamId1, uid); r2.Err != nil {
+ if r2 := <-store.Team().GetChannelUnreadsForAllTeams(teamId1, uid); r2.Err != nil {
t.Fatal(r2.Err)
} else {
ms := r2.Data.([]*model.ChannelUnread)
@@ -607,9 +611,46 @@ func TestMyTeamMembersUnread(t *testing.T) {
if len(membersMap) != 1 {
t.Fatal("Should be the unreads for just one team")
}
+
+ if ms[0].MsgCount != 10 {
+ t.Fatal("subtraction failed")
+ }
}
if r1 := <-store.Team().RemoveAllMembersByUser(uid); r1.Err != nil {
t.Fatal(r1.Err)
}
}
+
+func TestGetChannelUnreadsForTeam(t *testing.T) {
+ Setup()
+
+ teamId1 := model.NewId()
+
+ uid := model.NewId()
+ m1 := &model.TeamMember{TeamId: teamId1, UserId: uid}
+ Must(store.Team().SaveMember(m1))
+
+ c1 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
+ Must(store.Channel().Save(c1))
+ c2 := &model.Channel{TeamId: m1.TeamId, Name: model.NewId(), DisplayName: "Town Square", Type: model.CHANNEL_OPEN, TotalMsgCount: 100}
+ Must(store.Channel().Save(c2))
+
+ cm1 := &model.ChannelMember{ChannelId: c1.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
+ Must(store.Channel().SaveMember(cm1))
+ cm2 := &model.ChannelMember{ChannelId: c2.Id, UserId: m1.UserId, NotifyProps: model.GetDefaultChannelNotifyProps(), MsgCount: 90}
+ Must(store.Channel().SaveMember(cm2))
+
+ if r1 := <-store.Team().GetChannelUnreadsForTeam(m1.TeamId, m1.UserId); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ ms := r1.Data.([]*model.ChannelUnread)
+ if len(ms) != 2 {
+ t.Fatal("wrong length")
+ }
+
+ if ms[0].MsgCount != 10 {
+ t.Fatal("subtraction failed")
+ }
+ }
+}