diff options
author | Joram Wilander <jwawilander@gmail.com> | 2018-08-24 06:16:17 -0400 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2018-08-24 11:16:17 +0100 |
commit | 4de2e5206e23ee268b38f071ecd8fcbea0bbc80a (patch) | |
tree | be3d191545afdfa91a861be69a04dd1f646a1e16 /app/post_test.go | |
parent | 9599f1a52fd4b2d029113b3ec56bd75453ae4d7b (diff) | |
download | chat-4de2e5206e23ee268b38f071ecd8fcbea0bbc80a.tar.gz chat-4de2e5206e23ee268b38f071ecd8fcbea0bbc80a.tar.bz2 chat-4de2e5206e23ee268b38f071ecd8fcbea0bbc80a.zip |
Support for interactive menus in message attachments (#9285)
Diffstat (limited to 'app/post_test.go')
-rw-r--r-- | app/post_test.go | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/app/post_test.go b/app/post_test.go index 482197833..66a141172 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -134,6 +134,12 @@ func TestPostAction(t *testing.T) { err := json.NewDecoder(r.Body).Decode(&request) assert.NoError(t, err) assert.Equal(t, request.UserId, th.BasicUser.Id) + if request.Type == model.POST_ACTION_TYPE_SELECT { + assert.Equal(t, request.DataSource, "some_source") + assert.Equal(t, request.Context["selected_option"], "selected") + } else { + assert.Equal(t, request.DataSource, "") + } assert.Equal(t, "foo", request.Context["s"]) assert.EqualValues(t, 3, request.Context["n"]) fmt.Fprintf(w, `{"update": {"message": "updated"}, "ephemeral_text": "foo"}`) @@ -158,7 +164,9 @@ func TestPostAction(t *testing.T) { }, URL: ts.URL, }, - Name: "action", + Name: "action", + Type: "some_type", + DataSource: "some_source", }, }, }, @@ -175,11 +183,51 @@ func TestPostAction(t *testing.T) { require.NotEmpty(t, attachments[0].Actions) require.NotEmpty(t, attachments[0].Actions[0].Id) - err = th.App.DoPostAction(post.Id, "notavalidid", th.BasicUser.Id) + menuPost := model.Post{ + Message: "Interactive post", + ChannelId: th.BasicChannel.Id, + PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), + UserId: th.BasicUser.Id, + Props: model.StringInterface{ + "attachments": []*model.SlackAttachment{ + { + Text: "hello", + Actions: []*model.PostAction{ + { + Integration: &model.PostActionIntegration{ + Context: model.StringInterface{ + "s": "foo", + "n": 3, + }, + URL: ts.URL, + }, + Name: "action", + Type: model.POST_ACTION_TYPE_SELECT, + DataSource: "some_source", + }, + }, + }, + }, + }, + } + + post2, err := th.App.CreatePostAsUser(&menuPost) + require.Nil(t, err) + + attachments2, ok := post2.Props["attachments"].([]*model.SlackAttachment) + require.True(t, ok) + + require.NotEmpty(t, attachments2[0].Actions) + require.NotEmpty(t, attachments2[0].Actions[0].Id) + + err = th.App.DoPostAction(post.Id, "notavalidid", th.BasicUser.Id, "") require.NotNil(t, err) assert.Equal(t, http.StatusNotFound, err.StatusCode) - err = th.App.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id) + err = th.App.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id, "") + require.Nil(t, err) + + err = th.App.DoPostAction(post2.Id, attachments2[0].Actions[0].Id, th.BasicUser.Id, "selected") require.Nil(t, err) } |