summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorPoornima <mpoornima@users.noreply.github.com>2017-02-27 00:18:20 +0530
committerJoram Wilander <jwawilander@gmail.com>2017-02-26 13:48:20 -0500
commit19b753467d37209f2227567637e60138d05dd405 (patch)
tree163ba0878c02267ecbbcb288e11d23e30ec9c8eb /store
parentc0bb6f99f89259f6728856ace23d5dd505494b26 (diff)
downloadchat-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')
-rw-r--r--store/sql_webhook_store.go21
-rw-r--r--store/sql_webhook_store_test.go67
-rw-r--r--store/store.go3
3 files changed, 63 insertions, 28 deletions
diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go
index 0e61130ad..355678064 100644
--- a/store/sql_webhook_store.go
+++ b/store/sql_webhook_store.go
@@ -107,6 +107,27 @@ func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChann
return storeChannel
}
+func (s SqlWebhookStore) UpdateIncoming(hook *model.IncomingWebhook) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ hook.UpdateAt = model.GetMillis()
+
+ if _, err := s.GetMaster().Update(hook); err != nil {
+ result.Err = model.NewLocAppError("SqlWebhookStore.UpdateIncoming", "store.sql_webhooks.update_incoming.app_error", nil, "id="+hook.Id+", "+err.Error())
+ } else {
+ result.Data = hook
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlWebhookStore) GetIncoming(id string, allowFromCache bool) StoreChannel {
storeChannel := make(StoreChannel, 1)
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()
diff --git a/store/store.go b/store/store.go
index 34a709568..06564a8c2 100644
--- a/store/store.go
+++ b/store/store.go
@@ -260,9 +260,11 @@ type WebhookStore interface {
GetIncoming(id string, allowFromCache bool) StoreChannel
GetIncomingList(offset, limit int) StoreChannel
GetIncomingByTeam(teamId string, offset, limit int) StoreChannel
+ UpdateIncoming(webhook *model.IncomingWebhook) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel
PermanentDeleteIncomingByUser(userId string) StoreChannel
+
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(id string) StoreChannel
GetOutgoingByChannel(channelId string) StoreChannel
@@ -270,6 +272,7 @@ type WebhookStore interface {
DeleteOutgoing(webhookId string, time int64) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
+
AnalyticsIncomingCount(teamId string) StoreChannel
AnalyticsOutgoingCount(teamId string) StoreChannel
InvalidateWebhookCache(webhook string)