test fixes
This commit is contained in:
parent
55d16c4dff
commit
6a02d91fed
1
mg-transport-api-client-go
Symbolic link
1
mg-transport-api-client-go
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
/home/pavel/work/mg-transports/mg-transport-api-client-go
|
@ -197,6 +197,34 @@ type TemplateHeader struct {
|
|||||||
Content HeaderContent `json:"content"`
|
Content HeaderContent `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *TemplateHeader) TextContent() *HeaderContentText {
|
||||||
|
if h.Content.HeaderContentType() != HeaderContentTypeText {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return h.Content.(*HeaderContentText)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *TemplateHeader) DocumentContent() *HeaderContentDocument {
|
||||||
|
if h.Content.HeaderContentType() != HeaderContentTypeDocument {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return h.Content.(*HeaderContentDocument)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *TemplateHeader) ImageContent() *HeaderContentImage {
|
||||||
|
if h.Content.HeaderContentType() != HeaderContentTypeImage {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return h.Content.(*HeaderContentImage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *TemplateHeader) VideoContent() *HeaderContentVideo {
|
||||||
|
if h.Content.HeaderContentType() != HeaderContentTypeVideo {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return h.Content.(*HeaderContentVideo)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *TemplateHeader) UnmarshalJSON(value []byte) error {
|
func (h *TemplateHeader) UnmarshalJSON(value []byte) error {
|
||||||
var ScanType struct {
|
var ScanType struct {
|
||||||
Content json.RawMessage `json:"content"`
|
Content json.RawMessage `json:"content"`
|
||||||
|
@ -64,51 +64,193 @@ func TestTemplateItem_UnmarshalJSON(t *testing.T) {
|
|||||||
assert.Empty(t, emptyVariableResult.Text)
|
assert.Empty(t, emptyVariableResult.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalMediaInteractiveTemplate(t *testing.T) {
|
func TestUnmarshalInteractiveTemplate_TextHeader(t *testing.T) {
|
||||||
var template Template
|
var template Template
|
||||||
input := `{
|
input := `{
|
||||||
"code":"aaa#bbb#ru",
|
"code":"aaa#bbb#ru",
|
||||||
"phone": "79252223456",
|
"phone": "79252223456",
|
||||||
"channel_id": 1,
|
"channel_id": 1,
|
||||||
"headerParams": {
|
"header": {
|
||||||
"textVars": [
|
"content": {
|
||||||
"Johny",
|
"type": "text",
|
||||||
"1234C"
|
"body": "Hello, {{1}}!"
|
||||||
],
|
}
|
||||||
"imageUrl": "http://example.com/intaro/d2354125",
|
|
||||||
"videoUrl": "http://example.com/intaro/d2222",
|
|
||||||
"documentUrl": "http://example.com/intaro/d4444"
|
|
||||||
},
|
},
|
||||||
"footer": "Scooter",
|
"footer": "Scooter",
|
||||||
"buttonParams": [
|
"buttons": {
|
||||||
{
|
"items": [
|
||||||
"type": "URL",
|
{
|
||||||
"urlParameter": "222ddd"
|
"type": "url",
|
||||||
},
|
"label": "Go to website",
|
||||||
{
|
"url": "222ddd"
|
||||||
"type": "QUICK_REPLY",
|
},
|
||||||
"text": "Yes"
|
{
|
||||||
}
|
"type": "plain",
|
||||||
],
|
"label": "Yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"verification_status": "approved"
|
"verification_status": "approved"
|
||||||
}`
|
}`
|
||||||
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
|
||||||
assert.Equal(t, "aaa#bbb#ru", template.Code)
|
assert.Equal(t, "aaa#bbb#ru", template.Code)
|
||||||
assert.Equal(t, []string{"Johny", "1234C"}, template.Header.Content.TextVars)
|
assert.Equal(t, HeaderContentTypeText, template.Header.Content.HeaderContentType())
|
||||||
assert.Equal(t, "http://example.com/intaro/d2354125", template.HeaderParams.ImageURL)
|
|
||||||
assert.Equal(t, "http://example.com/intaro/d2222", template.HeaderParams.VideoURL)
|
h := template.Header.TextContent()
|
||||||
assert.Equal(t, "http://example.com/intaro/d4444", template.HeaderParams.DocumentURL)
|
assert.Equal(t, "Hello, {{1}}!", h.Body)
|
||||||
assert.Equal(t, "Scooter", *template.Footer)
|
assert.Equal(t, "Scooter", template.Footer)
|
||||||
assert.Equal(t, "approved", template.VerificationStatus)
|
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
|
||||||
assert.Equal(t, "URL", template.ButtonParams[0].ButtonType)
|
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
|
||||||
assert.Equal(t, "222ddd", template.ButtonParams[0].URLParameter)
|
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
|
||||||
assert.Equal(t, "QUICK_REPLY", template.ButtonParams[1].ButtonType)
|
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
|
||||||
assert.Equal(t, "Yes", template.ButtonParams[1].Text)
|
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
|
||||||
|
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
|
||||||
|
|
||||||
input = `{"footer": "Scooter"}`
|
input = `{"footer": "Scooter"}`
|
||||||
template = Template{}
|
template = Template{}
|
||||||
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
assert.Nil(t, template.HeaderParams)
|
assert.Nil(t, template.Header)
|
||||||
assert.Empty(t, template.ButtonParams)
|
assert.Empty(t, template.Buttons)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalInteractiveTemplate_DocumentHeader(t *testing.T) {
|
||||||
|
var template Template
|
||||||
|
input := `{
|
||||||
|
"code":"aaa#bbb#ru",
|
||||||
|
"phone": "79252223456",
|
||||||
|
"channel_id": 1,
|
||||||
|
"header": {
|
||||||
|
"content": {
|
||||||
|
"type": "document"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"footer": "Scooter",
|
||||||
|
"buttons": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "url",
|
||||||
|
"label": "Go to website",
|
||||||
|
"url": "222ddd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "plain",
|
||||||
|
"label": "Yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"verification_status": "approved"
|
||||||
|
}`
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
|
||||||
|
assert.Equal(t, "aaa#bbb#ru", template.Code)
|
||||||
|
assert.Equal(t, HeaderContentTypeDocument, template.Header.Content.HeaderContentType())
|
||||||
|
assert.NotNil(t, template.Header.DocumentContent())
|
||||||
|
assert.Equal(t, "Scooter", template.Footer)
|
||||||
|
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
|
||||||
|
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
|
||||||
|
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
|
||||||
|
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
|
||||||
|
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
|
||||||
|
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
|
||||||
|
|
||||||
|
input = `{"footer": "Scooter"}`
|
||||||
|
template = Template{}
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
assert.Nil(t, template.Header)
|
||||||
|
assert.Empty(t, template.Buttons)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalInteractiveTemplate_ImageHeader(t *testing.T) {
|
||||||
|
var template Template
|
||||||
|
input := `{
|
||||||
|
"code":"aaa#bbb#ru",
|
||||||
|
"phone": "79252223456",
|
||||||
|
"channel_id": 1,
|
||||||
|
"header": {
|
||||||
|
"content": {
|
||||||
|
"type": "image"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"footer": "Scooter",
|
||||||
|
"buttons": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "url",
|
||||||
|
"label": "Go to website",
|
||||||
|
"url": "222ddd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "plain",
|
||||||
|
"label": "Yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"verification_status": "approved"
|
||||||
|
}`
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
|
||||||
|
assert.Equal(t, "aaa#bbb#ru", template.Code)
|
||||||
|
assert.Equal(t, HeaderContentTypeImage, template.Header.Content.HeaderContentType())
|
||||||
|
assert.NotNil(t, template.Header.ImageContent())
|
||||||
|
assert.Equal(t, "Scooter", template.Footer)
|
||||||
|
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
|
||||||
|
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
|
||||||
|
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
|
||||||
|
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
|
||||||
|
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
|
||||||
|
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
|
||||||
|
|
||||||
|
input = `{"footer": "Scooter"}`
|
||||||
|
template = Template{}
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
assert.Nil(t, template.Header)
|
||||||
|
assert.Empty(t, template.Buttons)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalInteractiveTemplate_VideoHeader(t *testing.T) {
|
||||||
|
var template Template
|
||||||
|
input := `{
|
||||||
|
"code":"aaa#bbb#ru",
|
||||||
|
"phone": "79252223456",
|
||||||
|
"channel_id": 1,
|
||||||
|
"header": {
|
||||||
|
"content": {
|
||||||
|
"type": "video"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"footer": "Scooter",
|
||||||
|
"buttons": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "url",
|
||||||
|
"label": "Go to website",
|
||||||
|
"url": "222ddd"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "plain",
|
||||||
|
"label": "Yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"verification_status": "approved"
|
||||||
|
}`
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
|
||||||
|
assert.Equal(t, "aaa#bbb#ru", template.Code)
|
||||||
|
assert.Equal(t, HeaderContentTypeVideo, template.Header.Content.HeaderContentType())
|
||||||
|
assert.NotNil(t, template.Header.VideoContent())
|
||||||
|
assert.Equal(t, "Scooter", template.Footer)
|
||||||
|
assert.Equal(t, TemplateStatusApproved, template.VerificationStatus)
|
||||||
|
assert.Equal(t, ButtonTypeUrl, template.Buttons.Items[0].ButtonType())
|
||||||
|
assert.Equal(t, "222ddd", template.Buttons.Items[0].(*UrlButton).Url)
|
||||||
|
assert.Equal(t, "Go to website", template.Buttons.Items[0].(*UrlButton).Label)
|
||||||
|
assert.Equal(t, ButtonTypePlain, template.Buttons.Items[1].ButtonType())
|
||||||
|
assert.Equal(t, "Yes", template.Buttons.Items[1].(*PlainButton).Label)
|
||||||
|
|
||||||
|
input = `{"footer": "Scooter"}`
|
||||||
|
template = Template{}
|
||||||
|
assert.NoError(t, json.Unmarshal([]byte(input), &template))
|
||||||
|
assert.Nil(t, template.Header)
|
||||||
|
assert.Empty(t, template.Buttons)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user