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
Этот коммит содержится в:
Poornima
2017-02-27 00:18:20 +05:30
коммит произвёл Joram Wilander
родитель c0bb6f99f8
Коммит 19b753467d
35 изменённых файлов: 1939 добавлений и 763 удалений

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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 TestWebhookStoreUpdateIncoming(t *testing.T) {
Setup()
o1 := buildIncomingWebhook()
o1 = (<-store.Webhook().SaveIncoming(o1)).Data.(*model.IncomingWebhook)
previousUpdatedAt := o1.UpdateAt
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 := &model.IncomingWebhook{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.TeamId = model.NewId()
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()

Просмотреть файл

@@ -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)