From 19b753467d37209f2227567637e60138d05dd405 Mon Sep 17 00:00:00 2001 From: Poornima Date: Mon, 27 Feb 2017 00:18:20 +0530 Subject: Adding edit of incoming webhook (#5272) Adding edit of outgoing webhook Fixing spelling of error Fixing style Changing from PUT to POST for updates Fixing test failures due to merge --- store/sql_webhook_store_test.go | 67 ++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 28 deletions(-) (limited to 'store/sql_webhook_store_test.go') diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go index 3d79d9ad3..e1aaad1b7 100644 --- a/store/sql_webhook_store_test.go +++ b/store/sql_webhook_store_test.go @@ -4,35 +4,49 @@ package store import ( - "github.com/mattermost/platform/model" "testing" + + "github.com/mattermost/platform/model" ) func TestWebhookStoreSaveIncoming(t *testing.T) { Setup() + o1 := buildIncomingWebhook() - o1 := model.IncomingWebhook{} - o1.ChannelId = model.NewId() - o1.UserId = model.NewId() - o1.TeamId = model.NewId() - - if err := (<-store.Webhook().SaveIncoming(&o1)).Err; err != nil { + 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 { + if err := (<-store.Webhook().SaveIncoming(o1)).Err; err == nil { t.Fatal("shouldn't be able to update from save") } } -func TestWebhookStoreGetIncoming(t *testing.T) { +func TestWebhookStoreUpdateIncoming(t *testing.T) { Setup() + o1 := buildIncomingWebhook() + o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) + previousUpdatedAt := o1.UpdateAt - o1 := &model.IncomingWebhook{} - o1.ChannelId = model.NewId() - o1.UserId = model.NewId() - o1.TeamId = model.NewId() + o1.DisplayName = "TestHook" + + if result := (<-store.Webhook().UpdateIncoming(o1)); result.Err != nil { + t.Fatal("updation of incoming hook failed", result.Err) + } else { + if result.Data.(*model.IncomingWebhook).UpdateAt == previousUpdatedAt { + t.Fatal("should have updated the UpdatedAt of the hook") + } + + if result.Data.(*model.IncomingWebhook).DisplayName != "TestHook" { + t.Fatal("display name is not updated") + } + } +} + +func TestWebhookStoreGetIncoming(t *testing.T) { + Setup() + o1 := buildIncomingWebhook() o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) if r1 := <-store.Webhook().GetIncoming(o1.Id, false); r1.Err != nil { @@ -96,11 +110,7 @@ func TestWebhookStoreGetIncomingList(t *testing.T) { func TestWebhookStoreGetIncomingByTeam(t *testing.T) { Setup() - - o1 := &model.IncomingWebhook{} - o1.ChannelId = model.NewId() - o1.UserId = model.NewId() - o1.TeamId = model.NewId() + o1 := buildIncomingWebhook() o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) @@ -123,11 +133,7 @@ func TestWebhookStoreGetIncomingByTeam(t *testing.T) { func TestWebhookStoreDeleteIncoming(t *testing.T) { Setup() - - o1 := &model.IncomingWebhook{} - o1.ChannelId = model.NewId() - o1.UserId = model.NewId() - o1.TeamId = model.NewId() + o1 := buildIncomingWebhook() o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) @@ -153,11 +159,7 @@ func TestWebhookStoreDeleteIncoming(t *testing.T) { func TestWebhookStoreDeleteIncomingByUser(t *testing.T) { Setup() - - o1 := &model.IncomingWebhook{} - o1.ChannelId = model.NewId() - o1.UserId = model.NewId() - o1.TeamId = model.NewId() + o1 := buildIncomingWebhook() o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook) @@ -181,6 +183,15 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) { } } +func buildIncomingWebhook() *model.IncomingWebhook { + o1 := &model.IncomingWebhook{} + o1.ChannelId = model.NewId() + o1.UserId = model.NewId() + o1.TeamId = model.NewId() + + return o1 +} + func TestWebhookStoreSaveOutgoing(t *testing.T) { Setup() -- cgit v1.2.3-1-g7c22