api-client-go/types_test.go

56 lines
1.3 KiB
Go
Raw Normal View History

package retailcrm
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)
}
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)
}
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)
}
}