summaryrefslogtreecommitdiffstats
path: root/model/client4_test.go
blob: f7923fa8fa703fbc4ffb4f7b2031473af3de43cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/assert"
)

// https://github.com/mattermost/mattermost-server/issues/8205
func TestClient4CreatePost(t *testing.T) {
	post := &Post{
		Props: map[string]interface{}{
			"attachments": []*SlackAttachment{
				&SlackAttachment{
					Actions: []*PostAction{
						&PostAction{
							Integration: &PostActionIntegration{
								Context: map[string]interface{}{
									"foo": "bar",
								},
								URL: "http://foo.com",
							},
							Name: "Foo",
						},
					},
				},
			},
		},
	}

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		attachments := PostFromJson(r.Body).Attachments()
		assert.Equal(t, []*SlackAttachment{
			&SlackAttachment{
				Actions: []*PostAction{
					&PostAction{
						Integration: &PostActionIntegration{
							Context: map[string]interface{}{
								"foo": "bar",
							},
							URL: "http://foo.com",
						},
						Name: "Foo",
					},
				},
			},
		}, attachments)
	}))

	client := NewAPIv4Client(server.URL)
	_, resp := client.CreatePost(post)
	assert.Equal(t, http.StatusOK, resp.StatusCode)
}