Skip to content

Commit

Permalink
Merge pull request #123 from TonPC64/master
Browse files Browse the repository at this point in the history
omitempty size in SpacerComponent of flex message
  • Loading branch information
sugyan authored Feb 12, 2019
2 parents c4086b7 + 05fa3a6 commit dd918fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion linebot/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ type SpacerComponent struct {
func (c *SpacerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Size FlexSpacerSizeType `json:"size"`
Size FlexSpacerSizeType `json:"size,omitempty"`
}{
Type: FlexComponentTypeSpacer,
Size: c.Size,
Expand Down
14 changes: 14 additions & 0 deletions linebot/flex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ func TestUnmarshalFlexMessageJSON(t *testing.T) {
{
"type": "spacer",
"size": "sm"
},
{
"type": "spacer"
},
{
"type": "spacer",
"size": "xs"
}
],
"flex": 0
Expand Down Expand Up @@ -415,6 +422,13 @@ func TestUnmarshalFlexMessageJSON(t *testing.T) {
Type: FlexComponentTypeSpacer,
Size: FlexSpacerSizeTypeSm,
},
&SpacerComponent{
Type: FlexComponentTypeSpacer,
},
&SpacerComponent{
Type: FlexComponentTypeSpacer,
Size: FlexSpacerSizeTypeXs,
},
},
Spacing: FlexComponentSpacingTypeSm,
},
Expand Down
5 changes: 4 additions & 1 deletion linebot/send_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ func TestPushMessages(t *testing.T) {
Type: FlexComponentTypeText,
Text: "world",
},
&SpacerComponent{
Type: FlexComponentTypeSpacer,
},
},
},
},
Expand All @@ -393,7 +396,7 @@ func TestPushMessages(t *testing.T) {
ResponseCode: 200,
Response: []byte(`{}`),
Want: want{
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"flex","altText":"this is a flex message","contents":{"type":"bubble","body":{"type":"box","layout":"vertical","contents":[{"type":"text","text":"hello"},{"type":"text","text":"world"}]}}}]}` + "\n"),
RequestBody: []byte(`{"to":"U0cc15697597f61dd8b01cea8b027050e","messages":[{"type":"flex","altText":"this is a flex message","contents":{"type":"bubble","body":{"type":"box","layout":"vertical","contents":[{"type":"text","text":"hello"},{"type":"text","text":"world"},{"type":"spacer"}]}}}]}` + "\n"),
Response: &BasicResponse{},
},
},
Expand Down

0 comments on commit dd918fb

Please sign in to comment.