package lulu import ( "testing" "github.com/shopspring/decimal" ) func TestMarshalUnmarshalPrintJobCostReq(t *testing.T) { j := `{ "line_items": [ { "page_count": 32, "pod_package_id": "0600X0900.BW.STD.PB.060UW444.MXX", "quantity": 20 }, { "page_count": 324, "pod_package_id": "0425X0687.BW.STD.PB.060UW444.GXX", "quantity": 200 } ], "shipping_address": { "city": "Lübeck", "country_code": "DE", "postcode": "23552", "state_code": "", "street1": "Holstenstr. 40", "phone_number": "844-212-0689", "name": "", "street2": "", "is_business": false }, "shipping_option": "EXPRESS" }` addr := printJobCostReq{ []printJobCostLineItem{ { 32, PkgId{UsTrade, Mono, Standard, Perfect, P60UncoatedWhite, Matte, NoLinen, NoFoil}, 20, }, { 324, PkgId{Pocketbook, Mono, Standard, Perfect, P60UncoatedWhite, Gloss, NoLinen, NoFoil}, 200, }, }, ShippingAddress{ City: "Lübeck", CountryCode: "DE", PostCode: "23552", Street1: "Holstenstr. 40", Phone: "844-212-0689", // TODO: does the API mind the extra fields? }, Express, } requireMarshalJsonEq(t, j, addr) requireUnmarshalJsonEq(t, addr, j) } func TestUnmarshalPrintJobCost(t *testing.T) { j := `{ "shipping_address": { "city": "Lübeck", "country_code": "DE", "is_business": false, "name": "Hans Dampf", "phone_number": "844-212-0689", "postcode": "23552", "state_code": "", "street1": "Holstenstr. 40", "street2": "", "warnings": { "type": "validation_warning", "path": "external", "code": "REPLACED", "message": "street1: Holstenstr. 40 -> Holstenstraße 40" }, "suggested_address": { "country_code": "DE", "state_code": null, "postcode": 23552, "city": "Lübeck", "street1": "Holstenstraße 40\"", "street2": null } }, "currency": "USD", "fees": [ { "currency": "USD", "fee_type": "HANDLING_FEE", "sku": "HANDLING_FEE", "tax_rate": "0.060000", "total_cost_excl_tax": "14.00", "total_cost_incl_tax": "14.84", "total_tax": "0.84" }, { "currency": "USD", "fee_type": "FULFILLMENT_FEE", "sku": "FULFILLMENT_FEE", "tax_rate": "0.060000", "total_cost_excl_tax": "0.75", "total_cost_incl_tax": "0.80", "total_tax": "0.05" } ], "fulfillment_cost": { "tax_rate": "0.06", "total_cost_excl_tax": "0.75", "total_cost_incl_tax": "0.80", "total_tax": "0.05" }, "line_item_costs": [ { "cost_excl_discounts": "2.55", "discounts": [], "quantity": 20, "tax_rate": "0.060000", "total_cost_excl_discounts": "51.00", "total_cost_excl_tax": "51.00", "total_cost_incl_tax": "54.06", "total_tax": "3.06", "unit_tier_cost": null }, { "cost_excl_discounts": "9.26", "discounts": [ { "amount": "92.60", "description": "Volume Discount 5%" } ], "quantity": 200, "tax_rate": "0.060000", "total_cost_excl_discounts": "1852.00", "total_cost_excl_tax": "1759.40", "total_cost_incl_tax": "1864.96", "total_tax": "105.56", "unit_tier_cost": null } ], "shipping_cost": { "tax_rate": "0.06", "total_cost_excl_tax": "318.44", "total_cost_incl_tax": "337.55", "total_tax": "19.11" }, "total_cost_excl_tax": "2129.59", "total_cost_incl_tax": "2257.37", "total_discount_amount": "92.60", "total_tax": "127.78" }` cost := PrintJobCost{ Addr: ShippingAddress{ City: "Lübeck", CountryCode: "DE", IsBusiness: false, Name: "Hans Dampf", Phone: "844-212-0689", PostCode: "23552", StateCode: "", Street1: "Holstenstr. 40", Street2: "", }, SuggestedAddr: ShippingAddress{ CountryCode: "DE", StateCode: "", PostCode: "23552", City: "Lübeck", Street1: "Holstenstraße 40\"", Street2: "", }, AddrWarning: ShippingAddressWarning{ "validation_warning", "external", "REPLACED", "street1: Holstenstr. 40 -> Holstenstraße 40", }, Currency: "USD", Fees: []Fee{ { Currency: "USD", Type: "HANDLING_FEE", Sku: "HANDLING_FEE", TaxRate: decimal.RequireFromString("0.060000"), TotalCostExclTax: decimal.RequireFromString("14.00"), TotalCostInclTax: decimal.RequireFromString("14.84"), TotalTax: decimal.RequireFromString("0.84"), }, { Currency: "USD", Type: "FULFILLMENT_FEE", Sku: "FULFILLMENT_FEE", TaxRate: decimal.RequireFromString("0.060000"), TotalCostExclTax: decimal.RequireFromString("0.75"), TotalCostInclTax: decimal.RequireFromString("0.80"), TotalTax: decimal.RequireFromString("0.05"), }, }, FulfillmentCost: FulfillmentCost{ TaxRate: decimal.RequireFromString("0.06"), TotalCostExclTax: decimal.RequireFromString("0.75"), TotalCostInclTax: decimal.RequireFromString("0.80"), TotalTax: decimal.RequireFromString("0.05"), }, LineItemCosts: []LineItemCost{ { CostExclDiscounts: decimal.RequireFromString("2.55"), Discounts: []Discount{}, Quantity: 20, TaxRate: decimal.RequireFromString("0.060000"), TotalCostExclDiscounts: decimal.RequireFromString("51.00"), TotalCostExclTax: decimal.RequireFromString("51.00"), TotalCostInclTax: decimal.RequireFromString("54.06"), TotalTax: decimal.RequireFromString("3.06"), UnitTierCost: nil, }, { CostExclDiscounts: decimal.RequireFromString("9.26"), Discounts: []Discount{ {decimal.RequireFromString("92.60"), "Volume Discount 5%"}, }, Quantity: 200, TaxRate: decimal.RequireFromString("0.060000"), TotalCostExclDiscounts: decimal.RequireFromString("1852.00"), TotalCostExclTax: decimal.RequireFromString("1759.40"), TotalCostInclTax: decimal.RequireFromString("1864.96"), TotalTax: decimal.RequireFromString("105.56"), UnitTierCost: nil, }, }, ShipCost: FulfillmentCost{ TaxRate: decimal.RequireFromString("0.06"), TotalCostExclTax: decimal.RequireFromString("318.44"), TotalCostInclTax: decimal.RequireFromString("337.55"), TotalTax: decimal.RequireFromString("19.11"), }, TotalCostExclTax: decimal.RequireFromString("2129.59"), TotalCostInclTax: decimal.RequireFromString("2257.37"), TotalDiscount: decimal.RequireFromString("92.60"), TotalTax: decimal.RequireFromString("127.78"), } requireUnmarshalJsonEq(t, cost, j) }