diff options
author | Poornima <mpoornima@users.noreply.github.com> | 2017-02-27 00:18:20 +0530 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-02-26 13:48:20 -0500 |
commit | 19b753467d37209f2227567637e60138d05dd405 (patch) | |
tree | 163ba0878c02267ecbbcb288e11d23e30ec9c8eb /store/sql_webhook_store_test.go | |
parent | c0bb6f99f89259f6728856ace23d5dd505494b26 (diff) | |
download | chat-19b753467d37209f2227567637e60138d05dd405.tar.gz chat-19b753467d37209f2227567637e60138d05dd405.tar.bz2 chat-19b753467d37209f2227567637e60138d05dd405.zip |
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
Diffstat (limited to 'store/sql_webhook_store_test.go')
-rw-r--r-- | store/sql_webhook_store_test.go | 67 |
1 files changed, 39 insertions, 28 deletions
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() |