mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-21 12:26:04 +03:00
Neur0toxine
97b1abf470
* refactor library and upgrade version * remove useless environment variable * remove unsupported versions from go.mod * fixes for error handling & data types * different improvements for errors * fixes for types and tests * better coverage, fix error with the unmarshalers
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
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 {
|
|
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 {
|
|
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)
|
|
}
|
|
}
|