summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-08-11 09:28:44 -0400
committerJoramWilander <jwawilander@gmail.com>2015-08-11 12:11:35 -0400
commit3d0133b5e85660b942773f7cc63e6e8bc357462c (patch)
tree55df252b0d5a6e34a6b1e45348a361ea27d8144a
parent9f57ed5bf12d2d3a4cb143985c80646b877a1706 (diff)
downloadchat-3d0133b5e85660b942773f7cc63e6e8bc357462c.tar.gz
chat-3d0133b5e85660b942773f7cc63e6e8bc357462c.tar.bz2
chat-3d0133b5e85660b942773f7cc63e6e8bc357462c.zip
added api unit test for GetChannelCounts
-rw-r--r--api/channel_test.go34
-rw-r--r--model/client.go9
2 files changed, 43 insertions, 0 deletions
diff --git a/api/channel_test.go b/api/channel_test.go
index a0c2a6467..5563c692e 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -387,6 +387,40 @@ func TestGetMoreChannel(t *testing.T) {
}
}
+func TestGetChannelCounts(t *testing.T) {
+ Setup()
+
+ team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
+
+ user := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(user.Id))
+
+ Client.LoginByEmail(team.Name, user.Email, "pwd")
+
+ channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
+
+ channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
+
+ if result, err := Client.GetChannelCounts(""); err != nil {
+ t.Fatal(err)
+ } else {
+ counts := result.Data.(*model.ChannelCounts)
+
+ if len(counts.Counts) != 4 {
+ t.Fatal("wrong number of channel counts")
+ }
+
+ if len(counts.UpdateTimes) != 4 {
+ t.Fatal("wrong number of channel update times")
+ }
+ }
+
+}
+
func TestJoinChannel(t *testing.T) {
Setup()
diff --git a/model/client.go b/model/client.go
index 9ae0a66e5..6fcfa5043 100644
--- a/model/client.go
+++ b/model/client.go
@@ -408,6 +408,15 @@ func (c *Client) GetMoreChannels(etag string) (*Result, *AppError) {
}
}
+func (c *Client) GetChannelCounts(etag string) (*Result, *AppError) {
+ if r, err := c.DoGet("/channels/counts", "", etag); err != nil {
+ return nil, err
+ } else {
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), ChannelCountsFromJson(r.Body)}, nil
+ }
+}
+
func (c *Client) JoinChannel(id string) (*Result, *AppError) {
if r, err := c.DoPost("/channels/"+id+"/join", ""); err != nil {
return nil, err