summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-07-19 03:43:31 +0800
committerJoram Wilander <jwawilander@gmail.com>2017-07-18 15:43:31 -0400
commit21a3219b9b1df033635631afa751742bd4c56ea0 (patch)
tree6e97722afc7fc9ff3cee1c562732bd0924cf71da /api
parent8fb58b1fc9f38db22beca42dcd3e692fe5b547ba (diff)
downloadchat-21a3219b9b1df033635631afa751742bd4c56ea0.tar.gz
chat-21a3219b9b1df033635631afa751742bd4c56ea0.tar.bz2
chat-21a3219b9b1df033635631afa751742bd4c56ea0.zip
[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
Diffstat (limited to 'api')
-rw-r--r--api/post_test.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/api/post_test.go b/api/post_test.go
index dea7afa39..c4e016b0b 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -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) {