diff options
Diffstat (limited to 'store/sql_webhook_store_test.go')
-rw-r--r-- | store/sql_webhook_store_test.go | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go index e1aaad1b7..6cfe36450 100644 --- a/store/sql_webhook_store_test.go +++ b/store/sql_webhook_store_test.go @@ -6,6 +6,8 @@ package store import ( "testing" + "net/http" + "github.com/mattermost/platform/model" ) @@ -72,6 +74,10 @@ func TestWebhookStoreGetIncoming(t *testing.T) { if err := (<-store.Webhook().GetIncoming("123", true)).Err; err == nil { t.Fatal("Missing id should have failed") } + + if err := (<-store.Webhook().GetIncoming("123", true)).Err; err.StatusCode != http.StatusNotFound { + t.Fatal("Should have set the status as not found for missing id") + } } func TestWebhookStoreGetIncomingList(t *testing.T) { @@ -234,6 +240,59 @@ func TestWebhookStoreGetOutgoing(t *testing.T) { } } +func TestWebhookStoreGetOutgoingList(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) + + o2 := &model.OutgoingWebhook{} + o2.ChannelId = model.NewId() + o2.CreatorId = model.NewId() + o2.TeamId = model.NewId() + o2.CallbackURLs = []string{"http://nowhere.com/"} + + o2 = (<-store.Webhook().SaveOutgoing(o2)).Data.(*model.OutgoingWebhook) + + if r1 := <-store.Webhook().GetOutgoingList(0, 1000); r1.Err != nil { + t.Fatal(r1.Err) + } else { + hooks := r1.Data.([]*model.OutgoingWebhook) + found1 := false + found2 := false + + for _, hook := range hooks { + if hook.CreateAt != o1.CreateAt { + found1 = true + } + + if hook.CreateAt != o2.CreateAt { + found2 = true + } + } + + if !found1 { + t.Fatal("missing hook1") + } + if !found2 { + t.Fatal("missing hook2") + } + } + + if result := <-store.Webhook().GetOutgoingList(0, 2); result.Err != nil { + t.Fatal(result.Err) + } else { + if len(result.Data.([]*model.OutgoingWebhook)) != 2 { + t.Fatal("wrong number of hooks returned") + } + } +} + func TestWebhookStoreGetOutgoingByChannel(t *testing.T) { Setup() @@ -245,7 +304,7 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) { o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoingByChannel(o1.ChannelId); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoingByChannel(o1.ChannelId, 0, 100); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { @@ -253,7 +312,7 @@ func TestWebhookStoreGetOutgoingByChannel(t *testing.T) { } } - if result := <-store.Webhook().GetOutgoingByChannel("123"); result.Err != nil { + if result := <-store.Webhook().GetOutgoingByChannel("123", -1, -1); result.Err != nil { t.Fatal(result.Err) } else { if len(result.Data.([]*model.OutgoingWebhook)) != 0 { @@ -273,7 +332,7 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) { o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook) - if r1 := <-store.Webhook().GetOutgoingByTeam(o1.TeamId); r1.Err != nil { + if r1 := <-store.Webhook().GetOutgoingByTeam(o1.TeamId, 0, 100); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt { @@ -281,7 +340,7 @@ func TestWebhookStoreGetOutgoingByTeam(t *testing.T) { } } - if result := <-store.Webhook().GetOutgoingByTeam("123"); result.Err != nil { + if result := <-store.Webhook().GetOutgoingByTeam("123", -1, -1); result.Err != nil { t.Fatal(result.Err) } else { if len(result.Data.([]*model.OutgoingWebhook)) != 0 { |