summaryrefslogtreecommitdiffstats
path: root/store/sql_webhook_store_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/sql_webhook_store_test.go')
-rw-r--r--store/sql_webhook_store_test.go67
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()