github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/message_test.go (about)

     1  // Copyright 2021 LINE Corporation
     2  //
     3  // LINE Corporation licenses this file to you under the Apache License,
     4  // version 2.0 (the "License"); you may not use this file except in compliance
     5  // with the License. You may obtain a copy of the License at:
     6  //
     7  //   http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  package linebot
    16  
    17  import (
    18  	"strconv"
    19  	"testing"
    20  )
    21  
    22  func TestMessageTypes(t *testing.T) {
    23  	type want struct {
    24  		Type MessageType
    25  	}
    26  	testCases := []struct {
    27  		Label   string
    28  		Message Message
    29  		Want    want
    30  	}{
    31  		{
    32  			Label:   "A text message",
    33  			Message: NewTextMessage("Hello, world"),
    34  			Want: want{
    35  				Type: MessageTypeText,
    36  			},
    37  		},
    38  		{
    39  			Label:   "A location message",
    40  			Message: NewLocationMessage("title", "address", 35.65910807942215, 139.70372892916203),
    41  			Want: want{
    42  				Type: MessageTypeLocation,
    43  			},
    44  		},
    45  		{
    46  			Label:   "A image message",
    47  			Message: NewImageMessage("https://example.com/original.jpg", "https://example.com/preview.jpg"),
    48  			Want: want{
    49  				Type: MessageTypeImage,
    50  			},
    51  		},
    52  		{
    53  			Label:   "A sticker message",
    54  			Message: NewStickerMessage("1", "1"),
    55  			Want: want{
    56  				Type: MessageTypeSticker,
    57  			},
    58  		},
    59  		{
    60  			Label:   "A audio message",
    61  			Message: NewAudioMessage("https://example.com/original.m4a", 1000),
    62  			Want: want{
    63  				Type: MessageTypeAudio,
    64  			},
    65  		},
    66  		{
    67  			Label: "A template message",
    68  			Message: NewTemplateMessage(
    69  				"this is a buttons template",
    70  				NewButtonsTemplate(
    71  					"https://example.com/bot/images/image.jpg",
    72  					"",
    73  					"Please select",
    74  					NewPostbackAction("Buy", "action=buy&itemid=123", "", "displayText", "", ""),
    75  				),
    76  			),
    77  			Want: want{
    78  				Type: MessageTypeTemplate,
    79  			},
    80  		},
    81  		{
    82  			Label: "A flex message",
    83  			Message: NewFlexMessage(
    84  				"this is a flex message",
    85  				&BubbleContainer{}),
    86  			Want: want{
    87  				Type: MessageTypeFlex,
    88  			},
    89  		},
    90  		{
    91  			Label: "A Imagemap message",
    92  			Message: NewImagemapMessage(
    93  				"https://example.com/bot/images/rm001",
    94  				"this is an imagemap",
    95  				ImagemapBaseSize{1040, 1040},
    96  				NewURIImagemapAction("example", "https://example.com/", ImagemapArea{520, 0, 520, 1040}),
    97  			),
    98  			Want: want{
    99  				Type: MessageTypeImagemap,
   100  			},
   101  		},
   102  	}
   103  
   104  	for i, tc := range testCases {
   105  		t.Run(strconv.Itoa(i)+"/"+tc.Label, func(t *testing.T) {
   106  			if tc.Message.Type() != tc.Want.Type {
   107  				t.Errorf("Message type mismatch: have %v; want %v", tc.Message.Type(), tc.Want.Type)
   108  			}
   109  		})
   110  	}
   111  }