github.com/vnforks/kid@v5.11.1+incompatible/model/client4_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"net/http"
     8  	"net/http/httptest"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  // https://github.com/mattermost/mattermost-server/issues/8205
    15  func TestClient4CreatePost(t *testing.T) {
    16  	post := &Post{
    17  		Props: map[string]interface{}{
    18  			"attachments": []*SlackAttachment{
    19  				&SlackAttachment{
    20  					Actions: []*PostAction{
    21  						&PostAction{
    22  							Integration: &PostActionIntegration{
    23  								Context: map[string]interface{}{
    24  									"foo": "bar",
    25  								},
    26  								URL: "http://foo.com",
    27  							},
    28  							Name: "Foo",
    29  						},
    30  					},
    31  				},
    32  			},
    33  		},
    34  	}
    35  
    36  	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    37  		attachments := PostFromJson(r.Body).Attachments()
    38  		assert.Equal(t, []*SlackAttachment{
    39  			&SlackAttachment{
    40  				Actions: []*PostAction{
    41  					&PostAction{
    42  						Integration: &PostActionIntegration{
    43  							Context: map[string]interface{}{
    44  								"foo": "bar",
    45  							},
    46  							URL: "http://foo.com",
    47  						},
    48  						Name: "Foo",
    49  					},
    50  				},
    51  			},
    52  		}, attachments)
    53  	}))
    54  
    55  	client := NewAPIv4Client(server.URL)
    56  	_, resp := client.CreatePost(post)
    57  	assert.Equal(t, http.StatusOK, resp.StatusCode)
    58  }