Item.Quantity is string now

This commit is contained in:
Aliaksandr Pliutau 2016-10-24 13:49:11 +07:00
parent da5fe595b3
commit 1af34f3631
2 changed files with 23 additions and 1 deletions

View File

@ -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"`

View File

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