summaryrefslogtreecommitdiffstats
path: root/store/sql_webhook_store_test.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-10-01 14:40:50 -0400
committerJoramWilander <jwawilander@gmail.com>2015-10-19 09:00:30 -0400
commit7bf23409b2730ac73e1a4809c03681e03dbce0d2 (patch)
tree1924bd0f7f80f80e076ecb22366b6b73910def77 /store/sql_webhook_store_test.go
parent8c8f1bdd633f3afe158dd8c02130a36a5ca9be9d (diff)
downloadchat-7bf23409b2730ac73e1a4809c03681e03dbce0d2.tar.gz
chat-7bf23409b2730ac73e1a4809c03681e03dbce0d2.tar.bz2
chat-7bf23409b2730ac73e1a4809c03681e03dbce0d2.zip
Added store tests for outgoing webhooks.
Diffstat (limited to 'store/sql_webhook_store_test.go')
-rw-r--r--store/sql_webhook_store_test.go223
1 files changed, 220 insertions, 3 deletions
diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go
index 6f4ef4354..6098b2131 100644
--- a/store/sql_webhook_store_test.go
+++ b/store/sql_webhook_store_test.go
@@ -8,7 +8,7 @@ import (
"testing"
)
-func TestIncomingWebhookStoreSaveIncoming(t *testing.T) {
+func TestWebhookStoreSaveIncoming(t *testing.T) {
Setup()
o1 := model.IncomingWebhook{}
@@ -25,7 +25,7 @@ func TestIncomingWebhookStoreSaveIncoming(t *testing.T) {
}
}
-func TestIncomingWebhookStoreGetIncoming(t *testing.T) {
+func TestWebhookStoreGetIncoming(t *testing.T) {
Setup()
o1 := &model.IncomingWebhook{}
@@ -48,7 +48,34 @@ func TestIncomingWebhookStoreGetIncoming(t *testing.T) {
}
}
-func TestIncomingWebhookStoreDelete(t *testing.T) {
+func TestWebhookStoreGetIncomingByUser(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().GetIncomingByUser(o1.UserId); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.([]*model.IncomingWebhook)[0].CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned webhook")
+ }
+ }
+
+ if result := <-store.Webhook().GetIncomingByUser("123"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ if len(result.Data.([]*model.IncomingWebhook)) != 0 {
+ t.Fatal("no webhooks should have returned")
+ }
+ }
+}
+
+func TestWebhookStoreDeleteIncoming(t *testing.T) {
Setup()
o1 := &model.IncomingWebhook{}
@@ -75,3 +102,193 @@ func TestIncomingWebhookStoreDelete(t *testing.T) {
t.Fatal("Missing id should have failed")
}
}
+
+func TestWebhookStoreSaveOutgoing(t *testing.T) {
+ Setup()
+
+ o1 := model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err != nil {
+ t.Fatal("couldn't save item", err)
+ }
+
+ if err := (<-store.Webhook().SaveOutgoing(&o1)).Err; err == nil {
+ t.Fatal("shouldn't be able to update from save")
+ }
+}
+
+func TestWebhookStoreGetOutgoing(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned webhook")
+ }
+ }
+
+ if err := (<-store.Webhook().GetOutgoing("123")).Err; err == nil {
+ t.Fatal("Missing id should have failed")
+ }
+}
+
+func TestWebhookStoreGetOutgoingByChannel(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ if r1 := <-store.Webhook().GetOutgoingByChannel(o1.ChannelId); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned webhook")
+ }
+ }
+
+ if result := <-store.Webhook().GetOutgoingByChannel("123"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
+ t.Fatal("no webhooks should have returned")
+ }
+ }
+}
+
+func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ if r1 := <-store.Webhook().GetOutgoingByCreator(o1.CreatorId); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned webhook")
+ }
+ }
+
+ if result := <-store.Webhook().GetOutgoingByCreator("123"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
+ t.Fatal("no webhooks should have returned")
+ }
+ }
+}
+
+func TestWebhookStoreGetOutgoingByTriggerWord(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.TriggerWords = []string{"trigger"}
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ o2 := &model.OutgoingWebhook{}
+ o2.CreatorId = model.NewId()
+ o2.TeamId = o1.TeamId
+ o2.ChannelId = model.NewId()
+ o2.TriggerWords = []string{"trigger"}
+ o2.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o2 = (<-store.Webhook().SaveOutgoing(o2)).Data.(*model.OutgoingWebhook)
+
+ if r1 := <-store.Webhook().GetOutgoingByTriggerWord(o1.TeamId, "", "trigger"); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned webhook")
+ }
+ }
+
+ if r1 := <-store.Webhook().GetOutgoingByTriggerWord(o2.TeamId, o2.ChannelId, "trigger"); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if len(r1.Data.([]*model.OutgoingWebhook)) != 2 {
+ t.Fatal("wrong number of webhooks returned")
+ }
+ }
+
+ if result := <-store.Webhook().GetOutgoingByTriggerWord(o1.TeamId, "", "blargh"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
+ t.Fatal("no webhooks should have returned")
+ }
+ }
+}
+
+func TestWebhookStoreDeleteOutgoing(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ if r1 := <-store.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
+ t.Fatal(r1.Err)
+ } else {
+ if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
+ t.Fatal("invalid returned webhook")
+ }
+ }
+
+ if r2 := <-store.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil {
+ t.Fatal(r2.Err)
+ }
+
+ if r3 := (<-store.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
+ t.Log(r3.Data)
+ t.Fatal("Missing id should have failed")
+ }
+}
+
+func TestWebhookStoreUpdateOutgoing(t *testing.T) {
+ Setup()
+
+ o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
+ o1.CreatorId = model.NewId()
+ o1.TeamId = model.NewId()
+ o1.CallbackURLs = []string{"http://nowhere.com/"}
+
+ o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
+
+ o1.Token = model.NewId()
+
+ if r2 := <-store.Webhook().UpdateOutgoing(o1); r2.Err != nil {
+ t.Fatal(r2.Err)
+ }
+}