diff options
author | JoramWilander <jwawilander@gmail.com> | 2015-09-21 14:22:23 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2015-09-21 14:22:23 -0400 |
commit | 98186e5018bbc604796d4f9762c93f4f75e2913f (patch) | |
tree | b0a2c8309399b472fb846c5cec7aa46f9162b0f9 /store/sql_webhook_store_test.go | |
parent | 86429c7bd5bc16e3e7c868650e350f6469efeea1 (diff) | |
download | chat-98186e5018bbc604796d4f9762c93f4f75e2913f.tar.gz chat-98186e5018bbc604796d4f9762c93f4f75e2913f.tar.bz2 chat-98186e5018bbc604796d4f9762c93f4f75e2913f.zip |
Implement incoming webhooks.
Diffstat (limited to 'store/sql_webhook_store_test.go')
-rw-r--r-- | store/sql_webhook_store_test.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go new file mode 100644 index 000000000..0a015eaf9 --- /dev/null +++ b/store/sql_webhook_store_test.go @@ -0,0 +1,77 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package store + +import ( + "github.com/mattermost/platform/model" + "testing" +) + +func TestIncomingWebhookStoreSaveIncoming(t *testing.T) { + Setup() + + o1 := model.IncomingWebhook{} + o1.ChannelId = model.NewId() + o1.UserId = model.NewId() + o1.TeamId = model.NewId() + + if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err != nil { + t.Fatal("couldn't save item", err) + } + + if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err == nil { + t.Fatal("shouldn't be able to update from save") + } +} + +func TestIncomingWebhookStoreGetIncoming(t *testing.T) { + Setup() + + o1 := &model.IncomingWebhook{} + o1.ChannelId = model.NewId() + o1.UserId = model.NewId() + o1.TeamId = model.NewId() + + o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + + if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { + t.Fatal(r1.Err) + } else { + if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { + t.Fatal("invalid returned webhook") + } + } + + if err := (<-store.Webhook().GetIncoming("123")).Err; err == nil { + t.Fatal("Missing id should have failed") + } +} + +func TestIncomingWebhookStoreDelete(t *testing.T) { + Setup() + + o1 := &model.IncomingWebhook{} + o1.ChannelId = model.NewId() + o1.UserId = model.NewId() + o1.TeamId = model.NewId() + + o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + + if r1 := <-store.Webhook().GetIncoming(o1.Id); r1.Err != nil { + t.Fatal(r1.Err) + } else { + if r1.Data.(*model.IncomingWebhook).CreateAt != o1.CreateAt { + t.Fatal("invalid returned webhook") + } + } + + if r2 := <-store.Webhook().DeleteIncoming(o1.Id, model.GetMillis()); r2.Err != nil { + t.Fatal(r2.Err) + } + + if r3 := (<-store.Webhook().GetIncoming(o1.Id)); r3.Err == nil { + t.Log(r3.Data) + t.Fatal("Missing id should have failed") + } +} |