From 1af34f363197294c756329fd1e3f8fe3af9e64cd Mon Sep 17 00:00:00 2001 From: Aliaksandr Pliutau Date: Mon, 24 Oct 2016 13:49:11 +0700 Subject: [PATCH] Item.Quantity is string now --- types.go | 2 +- types_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/types.go b/types.go index 170d758..2b33fb2 100644 --- a/types.go +++ b/types.go @@ -147,7 +147,7 @@ type ( // Item struct Item struct { - Quantity int `json:"quantity"` + Quantity string `json:"quantity"` Name string `json:"name"` Price string `json:"price"` Currency string `json:"currency"` diff --git a/types_test.go b/types_test.go index 0fb3585..8e6a73e 100644 --- a/types_test.go +++ b/types_test.go @@ -30,3 +30,25 @@ func TestTypeUserInfo(t *testing.T) { t.Errorf("UserInfo decoded result is incorrect, Given: %v", u) } } + +func TestTypeItem(t *testing.T) { + response := `{ + "name":"Item", + "price":"22.99", + "currency":"GBP", + "quantity":"1" +}` + + i := &Item{} + err := json.Unmarshal([]byte(response), i) + if err != nil { + t.Errorf("Item Unmarshal failed") + } + + if i.Name != "Item" || + i.Price != "22.99" || + i.Currency != "GBP" || + i.Quantity != "1" { + t.Errorf("Item decoded result is incorrect, Given: %v", i) + } +}