2021-10-27 15:49:06 +03:00
|
|
|
package retailcrm
|
2020-08-05 17:34:38 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClient_OrderDeliveryData(t *testing.T) {
|
|
|
|
d := OrderDeliveryData{
|
|
|
|
OrderDeliveryDataBasic: OrderDeliveryDataBasic{
|
|
|
|
"track",
|
|
|
|
"status",
|
|
|
|
"address",
|
|
|
|
"type",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
data, _ := json.Marshal(d)
|
|
|
|
expectedStr := `{"payerType":"type","pickuppointAddress":"address","status":"status","trackNumber":"track"}`
|
|
|
|
if string(data) != expectedStr {
|
2020-08-05 17:43:56 +03:00
|
|
|
t.Errorf("Marshaled: %s\nExpected: %s\n", data, expectedStr)
|
2020-08-05 17:34:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
d.AdditionalFields = map[string]interface{}{
|
|
|
|
"customFirst": "one",
|
|
|
|
"customSecond": "two",
|
|
|
|
}
|
|
|
|
|
|
|
|
data, _ = json.Marshal(d)
|
|
|
|
expectedStr = `{"customFirst":"one","customSecond":"two","payerType":"type","pickuppointAddress":"address","status":"status","trackNumber":"track"}`
|
|
|
|
if string(data) != expectedStr {
|
2020-08-05 17:43:56 +03:00
|
|
|
t.Errorf("Marshaled: %s\nExpected: %s\n", data, expectedStr)
|
2020-08-05 17:34:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
d = OrderDeliveryData{}
|
|
|
|
json.Unmarshal(data, &d)
|
|
|
|
expected := OrderDeliveryData{
|
|
|
|
OrderDeliveryDataBasic: OrderDeliveryDataBasic{
|
|
|
|
"track",
|
|
|
|
"status",
|
|
|
|
"address",
|
|
|
|
"type",
|
|
|
|
},
|
|
|
|
AdditionalFields: map[string]interface{}{
|
|
|
|
"customFirst": "one",
|
|
|
|
"customSecond": "two",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
eq := reflect.DeepEqual(expected, d)
|
|
|
|
if eq != true {
|
|
|
|
t.Errorf("Unmarshaled: %#v\nExpected: %#v\n", d, expected)
|
|
|
|
}
|
|
|
|
}
|