mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
GH-10614 getoutgoing to sync (#10628)
This commit is contained in:
committed by
Jesús Espino
parent
88810a8ec7
commit
9c9c00b020
@@ -496,11 +496,7 @@ func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.
|
||||
return nil, model.NewAppError("GetOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoing(hookId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.OutgoingWebhook), nil
|
||||
}
|
||||
return a.Srv.Store.Webhook().GetOutgoing(hookId)
|
||||
}
|
||||
|
||||
func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
|
||||
@@ -223,16 +223,15 @@ func (s SqlWebhookStore) SaveOutgoing(webhook *model.OutgoingWebhook) (*model.Ou
|
||||
return webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoing(id string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var webhook model.OutgoingWebhook
|
||||
func (s SqlWebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError) {
|
||||
|
||||
if err := s.GetReplica().SelectOne(&webhook, "SELECT * FROM OutgoingWebhooks WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id}); err != nil {
|
||||
result.Err = model.NewAppError("SqlWebhookStore.GetOutgoing", "store.sql_webhooks.get_outgoing.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
var webhook model.OutgoingWebhook
|
||||
|
||||
result.Data = &webhook
|
||||
})
|
||||
if err := s.GetReplica().SelectOne(&webhook, "SELECT * FROM OutgoingWebhooks WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id}); err != nil {
|
||||
return nil, model.NewAppError("SqlWebhookStore.GetOutgoing", "store.sql_webhooks.get_outgoing.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return &webhook, nil
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) GetOutgoingList(offset, limit int) store.StoreChannel {
|
||||
|
||||
@@ -388,7 +388,7 @@ type WebhookStore interface {
|
||||
PermanentDeleteIncomingByUser(userId string) StoreChannel
|
||||
|
||||
SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoing(id string) StoreChannel
|
||||
GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError)
|
||||
GetOutgoingList(offset, limit int) StoreChannel
|
||||
GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
|
||||
GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel
|
||||
|
||||
@@ -190,19 +190,28 @@ func (_m *WebhookStore) GetIncomingList(offset int, limit int) ([]*model.Incomin
|
||||
}
|
||||
|
||||
// GetOutgoing provides a mock function with given fields: id
|
||||
func (_m *WebhookStore) GetOutgoing(id string) store.StoreChannel {
|
||||
func (_m *WebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError) {
|
||||
ret := _m.Called(id)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 *model.OutgoingWebhook
|
||||
if rf, ok := ret.Get(0).(func(string) *model.OutgoingWebhook); ok {
|
||||
r0 = rf(id)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(*model.OutgoingWebhook)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(id)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetOutgoingByChannel provides a mock function with given fields: channelId, offset, limit
|
||||
|
||||
@@ -300,15 +300,13 @@ func testWebhookStoreGetOutgoing(t *testing.T, ss store.Store) {
|
||||
|
||||
o1, _ = ss.Webhook().SaveOutgoing(o1)
|
||||
|
||||
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
webhook, err := ss.Webhook().GetOutgoing(o1.Id)
|
||||
require.Nil(t, err)
|
||||
if webhook.CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
|
||||
if err := (<-ss.Webhook().GetOutgoing("123")).Err; err == nil {
|
||||
if _, err := ss.Webhook().GetOutgoing("123"); err == nil {
|
||||
t.Fatal("Missing id should have failed")
|
||||
}
|
||||
}
|
||||
@@ -425,20 +423,17 @@ func testWebhookStoreDeleteOutgoing(t *testing.T, ss store.Store) {
|
||||
|
||||
o1, _ = ss.Webhook().SaveOutgoing(o1)
|
||||
|
||||
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
webhook, err := ss.Webhook().GetOutgoing(o1.Id)
|
||||
require.Nil(t, err)
|
||||
if webhook.CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
|
||||
if r2 := <-ss.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
}
|
||||
|
||||
if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
|
||||
t.Log(r3.Data)
|
||||
if _, err := ss.Webhook().GetOutgoing(o1.Id); err == nil {
|
||||
t.Fatal("Missing id should have failed")
|
||||
}
|
||||
}
|
||||
@@ -452,20 +447,17 @@ func testWebhookStoreDeleteOutgoingByChannel(t *testing.T, ss store.Store) {
|
||||
|
||||
o1, _ = ss.Webhook().SaveOutgoing(o1)
|
||||
|
||||
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
webhook, err := ss.Webhook().GetOutgoing(o1.Id)
|
||||
require.Nil(t, err)
|
||||
if webhook.CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
|
||||
if err := ss.Webhook().PermanentDeleteOutgoingByChannel(o1.ChannelId); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
|
||||
t.Log(r3.Data)
|
||||
if _, err := ss.Webhook().GetOutgoing(o1.Id); err == nil {
|
||||
t.Fatal("Missing id should have failed")
|
||||
}
|
||||
}
|
||||
@@ -479,20 +471,17 @@ func testWebhookStoreDeleteOutgoingByUser(t *testing.T, ss store.Store) {
|
||||
|
||||
o1, _ = ss.Webhook().SaveOutgoing(o1)
|
||||
|
||||
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
} else {
|
||||
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
webhook, err := ss.Webhook().GetOutgoing(o1.Id)
|
||||
require.Nil(t, err)
|
||||
if webhook.CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned webhook")
|
||||
}
|
||||
|
||||
if r2 := <-ss.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil {
|
||||
t.Fatal(r2.Err)
|
||||
}
|
||||
|
||||
if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil {
|
||||
t.Log(r3.Data)
|
||||
if _, err := ss.Webhook().GetOutgoing(o1.Id); err == nil {
|
||||
t.Fatal("Missing id should have failed")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user