api-client-go/types_test.go
Neur0toxine 97b1abf470
Correct v2 (#55)
* 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
2021-10-27 15:49:06 +03:00

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