summaryrefslogtreecommitdiffstats
path: root/api/channel_test.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-09-30 11:08:36 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-10-01 08:31:11 -0400
commitc16b9de8dc4924cf2fb243579284e67f55cf3a47 (patch)
treed7780fae809cec0b021281638f25ed7920050b0a /api/channel_test.go
parent111fbb2495e88d69bec29971da8ddf086ac3f3b6 (diff)
downloadchat-c16b9de8dc4924cf2fb243579284e67f55cf3a47.tar.gz
chat-c16b9de8dc4924cf2fb243579284e67f55cf3a47.tar.bz2
chat-c16b9de8dc4924cf2fb243579284e67f55cf3a47.zip
Replaced ChannelMember.MarkUnreadLevel with ChannelMember.NotifyProps
Diffstat (limited to 'api/channel_test.go')
-rw-r--r--api/channel_test.go80
1 files changed, 60 insertions, 20 deletions
diff --git a/api/channel_test.go b/api/channel_test.go
index 3276022fa..0e9dbbd41 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -885,7 +885,7 @@ func TestUpdateNotifyLevel(t *testing.T) {
}
}
-func TestUpdateMarkUnreadLevel(t *testing.T) {
+func TestUpdateNotifyProps(t *testing.T) {
Setup()
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
@@ -903,55 +903,94 @@ func TestUpdateMarkUnreadLevel(t *testing.T) {
data := make(map[string]string)
data["channel_id"] = channel1.Id
data["user_id"] = user.Id
- data["mark_unread_level"] = model.CHANNEL_MARK_UNREAD_MENTION
+ data["desktop"] = model.CHANNEL_NOTIFY_MENTION
timeBeforeUpdate := model.GetMillis()
time.Sleep(100 * time.Millisecond)
- if _, err := Client.UpdateMarkUnreadLevel(data); err != nil {
+ // test updating desktop
+ if result, err := Client.UpdateNotifyProps(data); err != nil {
t.Fatal(err)
+ } else if notifyProps := result.Data.(map[string]string); notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
+ t.Fatal("NotifyProps[\"desktop\"] did not update properly")
+ } else if notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_ALL {
+ t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
}
rget := Client.Must(Client.GetChannels(""))
rdata := rget.Data.(*model.ChannelList)
- if len(rdata.Members) == 0 || rdata.Members[channel1.Id].MarkUnreadLevel != data["mark_unread_level"] {
- t.Fatal("MarkUnreadLevel did not update properly")
+ if len(rdata.Members) == 0 || rdata.Members[channel1.Id].NotifyProps["desktop"] != data["desktop"] {
+ t.Fatal("NotifyProps[\"desktop\"] did not update properly")
+ } else if rdata.Members[channel1.Id].LastUpdateAt <= timeBeforeUpdate {
+ t.Fatal("LastUpdateAt did not update")
}
- if rdata.Members[channel1.Id].LastUpdateAt <= timeBeforeUpdate {
- t.Fatal("LastUpdateAt did not update")
+ // test an empty update
+ delete(data, "desktop")
+
+ if result, err := Client.UpdateNotifyProps(data); err != nil {
+ t.Fatal(err)
+ } else if notifyProps := result.Data.(map[string]string); notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_ALL {
+ t.Fatalf("NotifyProps[\"mark_unread\"] changed to %v", notifyProps["mark_unread"])
+ } else if notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
+ t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps["desktop"])
+ }
+
+ // test updating mark unread
+ data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
+
+ if result, err := Client.UpdateNotifyProps(data); err != nil {
+ t.Fatal(err)
+ } else if notifyProps := result.Data.(map[string]string); notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
+ t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
+ } else if notifyProps["desktop"] != model.CHANNEL_NOTIFY_MENTION {
+ t.Fatalf("NotifyProps[\"desktop\"] changed to %v", notifyProps["desktop"])
}
+ // test updating both
+ data["desktop"] = model.CHANNEL_NOTIFY_NONE
+ data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
+
+ if result, err := Client.UpdateNotifyProps(data); err != nil {
+ t.Fatal(err)
+ } else if notifyProps := result.Data.(map[string]string); notifyProps["desktop"] != model.CHANNEL_NOTIFY_NONE {
+ t.Fatal("NotifyProps[\"desktop\"] did not update properly")
+ } else if notifyProps["mark_unread"] != model.CHANNEL_MARK_UNREAD_MENTION {
+ t.Fatal("NotifyProps[\"mark_unread\"] did not update properly")
+ }
+
+ // test error cases
data["user_id"] = "junk"
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
+ if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad user id")
}
data["user_id"] = "12345678901234567890123456"
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
+ if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad user id")
}
data["user_id"] = user.Id
data["channel_id"] = "junk"
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
+ if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad channel id")
}
data["channel_id"] = "12345678901234567890123456"
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
+ if _, err := Client.UpdateNotifyProps(data); err == nil {
t.Fatal("Should have errored - bad channel id")
}
- data["channel_id"] = channel1.Id
- data["mark_unread_level"] = ""
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
- t.Fatal("Should have errored - empty notify level")
+ data["desktop"] = "junk"
+ data["mark_unread"] = model.CHANNEL_MARK_UNREAD_ALL
+ if _, err := Client.UpdateNotifyProps(data); err == nil {
+ t.Fatal("Should have errored - bad desktop notify level")
}
- data["mark_unread_level"] = "junk"
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
- t.Fatal("Should have errored - bad notify level")
+ data["desktop"] = model.CHANNEL_NOTIFY_ALL
+ data["mark_unread"] = "junk"
+ if _, err := Client.UpdateNotifyProps(data); err == nil {
+ t.Fatal("Should have errored - bad mark unread level")
}
user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
@@ -961,8 +1000,9 @@ func TestUpdateMarkUnreadLevel(t *testing.T) {
data["channel_id"] = channel1.Id
data["user_id"] = user2.Id
- data["mark_unread_level"] = model.CHANNEL_MARK_UNREAD_MENTION
- if _, err := Client.UpdateMarkUnreadLevel(data); err == nil {
+ data["desktop"] = model.CHANNEL_NOTIFY_MENTION
+ data["mark_unread"] = model.CHANNEL_MARK_UNREAD_MENTION
+ if _, err := Client.UpdateNotifyLevel(data); err == nil {
t.Fatal("Should have errored - user not in channel")
}
}