[PLT-6676] Make OutgoingWebhook to fire when post has no text content but only attachment (#6935)
* make OutgoingWebhook to fire when post has no text content but only attachment * update per comment and modify payload & test
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
8fb58b1fc9
Коммит
21a3219b9b
@@ -177,8 +177,9 @@ func TestCreatePostWithCreateAt(t *testing.T) {
|
||||
|
||||
func testCreatePostWithOutgoingHook(
|
||||
t *testing.T,
|
||||
hookContentType string,
|
||||
expectedContentType string,
|
||||
hookContentType, expectedContentType, message, triggerWord string,
|
||||
fileIds []string,
|
||||
triggerWhen int,
|
||||
) {
|
||||
th := Setup().InitSystemAdmin()
|
||||
Client := th.SystemAdminClient
|
||||
@@ -221,7 +222,8 @@ func testCreatePostWithOutgoingHook(
|
||||
UserName: user.Username,
|
||||
PostId: post.Id,
|
||||
Text: post.Message,
|
||||
TriggerWord: strings.Fields(post.Message)[0],
|
||||
TriggerWord: triggerWord,
|
||||
FileIds: strings.Join(post.FileIds, ","),
|
||||
}
|
||||
|
||||
// depending on the Content-Type, we expect to find a JSON or form encoded payload
|
||||
@@ -256,11 +258,17 @@ func testCreatePostWithOutgoingHook(
|
||||
defer ts.Close()
|
||||
|
||||
// create an outgoing webhook, passing it the test server URL
|
||||
triggerWord := "bingo"
|
||||
var triggerWords []string
|
||||
if triggerWord != "" {
|
||||
triggerWords = []string{triggerWord}
|
||||
}
|
||||
|
||||
hook = &model.OutgoingWebhook{
|
||||
ChannelId: channel.Id,
|
||||
TeamId: team.Id,
|
||||
ContentType: hookContentType,
|
||||
TriggerWords: []string{triggerWord},
|
||||
TriggerWords: triggerWords,
|
||||
TriggerWhen: triggerWhen,
|
||||
CallbackURLs: []string{ts.URL},
|
||||
}
|
||||
|
||||
@@ -271,10 +279,10 @@ func testCreatePostWithOutgoingHook(
|
||||
}
|
||||
|
||||
// create a post to trigger the webhook
|
||||
message := triggerWord + " lorem ipusm"
|
||||
post = &model.Post{
|
||||
ChannelId: channel.Id,
|
||||
Message: message,
|
||||
FileIds: fileIds,
|
||||
}
|
||||
|
||||
if result, err := Client.CreatePost(post); err != nil {
|
||||
@@ -290,25 +298,34 @@ func testCreatePostWithOutgoingHook(
|
||||
select {
|
||||
case ok := <-success:
|
||||
if !ok {
|
||||
t.Fatal("Test server was sent an invalid webhook.")
|
||||
t.Fatal("Test server did send an invalid webhook.")
|
||||
}
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("Timeout, test server wasn't sent the webhook.")
|
||||
t.Fatal("Timeout, test server did not send the webhook.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreatePostWithOutgoingHook_form_urlencoded(t *testing.T) {
|
||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded")
|
||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TRIGGERWORDS_EXACT_MATCH)
|
||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TRIGGERWORDS_STARTS_WITH)
|
||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "", "", []string{"file_id_1"}, app.TRIGGERWORDS_EXACT_MATCH)
|
||||
testCreatePostWithOutgoingHook(t, "application/x-www-form-urlencoded", "application/x-www-form-urlencoded", "", "", []string{"file_id_1"}, app.TRIGGERWORDS_STARTS_WITH)
|
||||
}
|
||||
|
||||
func TestCreatePostWithOutgoingHook_json(t *testing.T) {
|
||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json")
|
||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TRIGGERWORDS_EXACT_MATCH)
|
||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1, file_id_2"}, app.TRIGGERWORDS_STARTS_WITH)
|
||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerword lorem ipsum", "", []string{"file_id_1"}, app.TRIGGERWORDS_EXACT_MATCH)
|
||||
testCreatePostWithOutgoingHook(t, "application/json", "application/json", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1"}, app.TRIGGERWORDS_STARTS_WITH)
|
||||
}
|
||||
|
||||
// hooks created before we added the ContentType field should be considered as
|
||||
// application/x-www-form-urlencoded
|
||||
func TestCreatePostWithOutgoingHook_no_content_type(t *testing.T) {
|
||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded")
|
||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "triggerword", []string{"file_id_1"}, app.TRIGGERWORDS_EXACT_MATCH)
|
||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "triggerword", []string{"file_id_1"}, app.TRIGGERWORDS_STARTS_WITH)
|
||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerword lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TRIGGERWORDS_EXACT_MATCH)
|
||||
testCreatePostWithOutgoingHook(t, "", "application/x-www-form-urlencoded", "triggerwordaaazzz lorem ipsum", "", []string{"file_id_1, file_id_2"}, app.TRIGGERWORDS_STARTS_WITH)
|
||||
}
|
||||
|
||||
func TestUpdatePost(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user