1
0
mirror of synced 2024-11-21 20:46:05 +03:00

Support for the sending of order and product messages

This commit is contained in:
Pavel 2024-07-26 14:04:23 +03:00 committed by GitHub
commit ee80215c09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 146 additions and 15 deletions

View File

@ -605,6 +605,134 @@ func (t *MGClientTest) Test_ImageMessages() {
t.Assert().Equal(1, data.MessageID)
}
func (t *MGClientTest) Test_ProductMessages() {
c := t.client()
snd := SendData{
Message: Message{
ExternalID: "external_id",
Type: MsgTypeProduct,
Product: &MessageDataProduct{
ID: 2,
Name: "Product name",
Article: "Product article",
Url: "https://example.loca/product/1",
Img: "https://example.loca/product/1/img",
Cost: &MessageDataOrderCost{
Value: 100,
Currency: "USD",
},
Unit: "pcs",
},
},
Originator: OriginatorCustomer,
Customer: Customer{
ExternalID: "6",
Nickname: "octopus",
Firstname: "Joe",
Utm: &Utm{
Source: "test-source",
Term: "",
},
},
Channel: 1,
ExternalChatID: "24798237492374",
}
defer gock.Off()
t.gock().
Post(t.transportURL("messages")).
Filter(func(request *http.Request) bool {
data, err := ioutil.ReadAll(request.Body)
if err != nil {
return false
}
request.Body = ioutil.NopCloser(bytes.NewReader(data))
var snd SendData
t.Require().NoError(json.Unmarshal(data, &snd))
return t.Assert().Equal(uint64(2), snd.Message.Product.ID)
}).
Reply(http.StatusOK).
JSON(
MessagesResponse{
MessageID: 1,
Time: time.Now(),
},
)
data, status, err := c.Messages(snd)
t.Require().NoError(err)
t.Assert().Equal(http.StatusOK, status)
t.Assert().NotEmpty(data.Time.String())
t.Assert().Equal(1, data.MessageID)
}
func (t *MGClientTest) Test_OrderMessages() {
c := t.client()
snd := SendData{
Message: Message{
ExternalID: "external_id",
Type: MsgTypeOrder,
Order: &MessageDataOrder{
Number: "C1234",
ExternalID: 123,
Date: time.Now().String(),
Cost: &MessageDataOrderCost{
Value: 100,
Currency: "USD",
},
Discount: nil,
Status: nil,
Delivery: nil,
Payments: nil,
Items: nil,
},
},
Originator: OriginatorCustomer,
Customer: Customer{
ExternalID: "6",
Nickname: "octopus",
Firstname: "Joe",
Utm: &Utm{
Source: "test-source",
Term: "",
},
},
Channel: 1,
ExternalChatID: "24798237492374",
}
defer gock.Off()
t.gock().
Post(t.transportURL("messages")).
Filter(func(request *http.Request) bool {
data, err := ioutil.ReadAll(request.Body)
if err != nil {
return false
}
request.Body = ioutil.NopCloser(bytes.NewReader(data))
var snd SendData
t.Require().NoError(json.Unmarshal(data, &snd))
return t.Assert().Equal(int64(123), snd.Message.Order.ExternalID)
}).
Reply(http.StatusOK).
JSON(
MessagesResponse{
MessageID: 1,
Time: time.Now(),
},
)
data, status, err := c.Messages(snd)
t.Require().NoError(err)
t.Assert().Equal(http.StatusOK, status)
t.Assert().NotEmpty(data.Time.String())
t.Assert().Equal(1, data.MessageID)
}
func (t *MGClientTest) Test_UpdateMessages() {
c := t.client()

View File

@ -312,6 +312,8 @@ type Message struct {
Note string `json:"note,omitempty"`
Items []Item `json:"items,omitempty"`
PageLink string `json:"page_link,omitempty"`
Product *MessageDataProduct `json:"product,omitempty"`
Order *MessageDataOrder `json:"order,omitempty"`
}
// SendMessage struct.
@ -546,8 +548,9 @@ type MessageDataProduct struct {
// MessageDataOrder order data from webhook.
type MessageDataOrder struct {
ExternalID int64 `json:"external_id"`
Number string `json:"number"`
Url string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
Date string `json:"date,omitempty"`
Cost *MessageDataOrderCost `json:"cost,omitempty"`
Discount *MessageDataOrderCost `json:"discount,omitempty"`