github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/slack_attachment_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  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestParseSlackAttachment(t *testing.T) {
    13  	t.Run("empty list", func(t *testing.T) {
    14  		post := &Post{}
    15  		attachments := []*SlackAttachment{}
    16  
    17  		ParseSlackAttachment(post, attachments)
    18  
    19  		expectedPost := &Post{
    20  			Type: POST_SLACK_ATTACHMENT,
    21  			Props: map[string]interface{}{
    22  				"attachments": []*SlackAttachment{},
    23  			},
    24  		}
    25  		assert.Equal(t, expectedPost, post)
    26  	})
    27  
    28  	t.Run("list with nil", func(t *testing.T) {
    29  		post := &Post{}
    30  		attachments := []*SlackAttachment{
    31  			nil,
    32  		}
    33  
    34  		ParseSlackAttachment(post, attachments)
    35  
    36  		expectedPost := &Post{
    37  			Type: POST_SLACK_ATTACHMENT,
    38  			Props: map[string]interface{}{
    39  				"attachments": []*SlackAttachment{},
    40  			},
    41  		}
    42  		assert.Equal(t, expectedPost, post)
    43  	})
    44  }