Этот коммит содержится в:
Syerikjan Kh
2019-04-25 14:19:38 +08:00
коммит произвёл Jesús Espino
родитель 88810a8ec7
Коммит 9c9c00b020
5 изменённых файлов: 43 добавлений и 50 удалений

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

@@ -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) 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 a.Srv.Store.Webhook().GetOutgoing(hookId)
return nil, result.Err
} else {
return result.Data.(*model.OutgoingWebhook), nil
}
} }
func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) { 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 return webhook, nil
} }
func (s SqlWebhookStore) GetOutgoing(id string) store.StoreChannel { func (s SqlWebhookStore) GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError) {
return store.Do(func(result *store.StoreResult) {
var webhook model.OutgoingWebhook
if err := s.GetReplica().SelectOne(&webhook, "SELECT * FROM OutgoingWebhooks WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id}); err != nil { var webhook model.OutgoingWebhook
result.Err = model.NewAppError("SqlWebhookStore.GetOutgoing", "store.sql_webhooks.get_outgoing.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
}
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 { func (s SqlWebhookStore) GetOutgoingList(offset, limit int) store.StoreChannel {

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

@@ -388,7 +388,7 @@ type WebhookStore interface {
PermanentDeleteIncomingByUser(userId string) StoreChannel PermanentDeleteIncomingByUser(userId string) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
GetOutgoing(id string) StoreChannel GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError)
GetOutgoingList(offset, limit int) StoreChannel GetOutgoingList(offset, limit int) StoreChannel
GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel
GetOutgoingByTeam(teamId 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 // 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) ret := _m.Called(id)
var r0 store.StoreChannel var r0 *model.OutgoingWebhook
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string) *model.OutgoingWebhook); ok {
r0 = rf(id) r0 = rf(id)
} else { } else {
if ret.Get(0) != nil { 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 // 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) o1, _ = ss.Webhook().SaveOutgoing(o1)
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil { webhook, err := ss.Webhook().GetOutgoing(o1.Id)
t.Fatal(r1.Err) require.Nil(t, err)
} else { if webhook.CreateAt != o1.CreateAt {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { t.Fatal("invalid returned webhook")
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") t.Fatal("Missing id should have failed")
} }
} }
@@ -425,20 +423,17 @@ func testWebhookStoreDeleteOutgoing(t *testing.T, ss store.Store) {
o1, _ = ss.Webhook().SaveOutgoing(o1) o1, _ = ss.Webhook().SaveOutgoing(o1)
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil { webhook, err := ss.Webhook().GetOutgoing(o1.Id)
t.Fatal(r1.Err) require.Nil(t, err)
} else { if webhook.CreateAt != o1.CreateAt {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { t.Fatal("invalid returned webhook")
t.Fatal("invalid returned webhook")
}
} }
if r2 := <-ss.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil { if r2 := <-ss.Webhook().DeleteOutgoing(o1.Id, model.GetMillis()); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { if _, err := ss.Webhook().GetOutgoing(o1.Id); err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
} }
@@ -452,20 +447,17 @@ func testWebhookStoreDeleteOutgoingByChannel(t *testing.T, ss store.Store) {
o1, _ = ss.Webhook().SaveOutgoing(o1) o1, _ = ss.Webhook().SaveOutgoing(o1)
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil { webhook, err := ss.Webhook().GetOutgoing(o1.Id)
t.Fatal(r1.Err) require.Nil(t, err)
} else { if webhook.CreateAt != o1.CreateAt {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { t.Fatal("invalid returned webhook")
t.Fatal("invalid returned webhook")
}
} }
if err := ss.Webhook().PermanentDeleteOutgoingByChannel(o1.ChannelId); err != nil { if err := ss.Webhook().PermanentDeleteOutgoingByChannel(o1.ChannelId); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { if _, err := ss.Webhook().GetOutgoing(o1.Id); err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
} }
@@ -479,20 +471,17 @@ func testWebhookStoreDeleteOutgoingByUser(t *testing.T, ss store.Store) {
o1, _ = ss.Webhook().SaveOutgoing(o1) o1, _ = ss.Webhook().SaveOutgoing(o1)
if r1 := <-ss.Webhook().GetOutgoing(o1.Id); r1.Err != nil { webhook, err := ss.Webhook().GetOutgoing(o1.Id)
t.Fatal(r1.Err) require.Nil(t, err)
} else { if webhook.CreateAt != o1.CreateAt {
if r1.Data.(*model.OutgoingWebhook).CreateAt != o1.CreateAt { t.Fatal("invalid returned webhook")
t.Fatal("invalid returned webhook")
}
} }
if r2 := <-ss.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil { if r2 := <-ss.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil {
t.Fatal(r2.Err) t.Fatal(r2.Err)
} }
if r3 := (<-ss.Webhook().GetOutgoing(o1.Id)); r3.Err == nil { if _, err := ss.Webhook().GetOutgoing(o1.Id); err == nil {
t.Log(r3.Data)
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
} }