summaryrefslogtreecommitdiffstats
path: root/app/post_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-08-29 16:14:59 -0500
committerGitHub <noreply@github.com>2017-08-29 16:14:59 -0500
commit213a072b38d29d3c3ec8e150584685b1144a7d6a (patch)
tree1da10a494e49914b0f6641db79e7dcf8ad3886f6 /app/post_test.go
parent59798c137584a0b7e008ec713b489929dd83a690 (diff)
downloadchat-213a072b38d29d3c3ec8e150584685b1144a7d6a.tar.gz
chat-213a072b38d29d3c3ec8e150584685b1144a7d6a.tar.bz2
chat-213a072b38d29d3c3ec8e150584685b1144a7d6a.zip
PLT-6403: Interactive messages (#7274)
* wip * finish first pass * requested changes * add DoPostAction to Client4
Diffstat (limited to 'app/post_test.go')
-rw-r--r--app/post_test.go72
1 files changed, 71 insertions, 1 deletions
diff --git a/app/post_test.go b/app/post_test.go
index 416fbfc9e..ab8e27021 100644
--- a/app/post_test.go
+++ b/app/post_test.go
@@ -4,11 +4,18 @@
package app
import (
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
"testing"
"time"
- "fmt"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
"github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
)
func TestUpdatePostEditAt(t *testing.T) {
@@ -68,3 +75,66 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestPostAction(t *testing.T) {
+ th := Setup().InitBasic()
+
+ allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
+ defer func() {
+ utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = &allowedInternalConnections
+ }()
+ *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ var request model.PostActionIntegrationRequest
+ err := json.NewDecoder(r.Body).Decode(&request)
+ assert.NoError(t, err)
+ assert.Equal(t, request.UserId, th.BasicUser.Id)
+ assert.Equal(t, "foo", request.Context["s"])
+ assert.EqualValues(t, 3, request.Context["n"])
+ fmt.Fprintf(w, `{"update": {"message": "updated"}, "ephemeral_text": "foo"}`)
+ }))
+ defer ts.Close()
+
+ interactivePost := 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{
+ &model.SlackAttachment{
+ Text: "hello",
+ Actions: []*model.PostAction{
+ &model.PostAction{
+ Integration: &model.PostActionIntegration{
+ Context: model.StringInterface{
+ "s": "foo",
+ "n": 3,
+ },
+ URL: ts.URL,
+ },
+ Name: "action",
+ },
+ },
+ },
+ },
+ },
+ }
+
+ post, err := CreatePostAsUser(&interactivePost)
+ require.Nil(t, err)
+
+ attachments, ok := post.Props["attachments"].([]*model.SlackAttachment)
+ require.True(t, ok)
+
+ require.NotEmpty(t, attachments[0].Actions)
+ require.NotEmpty(t, attachments[0].Actions[0].Id)
+
+ err = DoPostAction(post.Id, "notavalidid", th.BasicUser.Id)
+ require.NotNil(t, err)
+ assert.Equal(t, http.StatusNotFound, err.StatusCode)
+
+ err = DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id)
+ require.Nil(t, err)
+}