stuff
This commit is contained in:
1 parent
5807132ac6
commit
ccb43808fa
4 files changed
+177
-8
No files matched your search
+102
-6
@@ -15,12 +15,12 @@ import (
|
||||
func TestBuilderJSONNumber(t *testing.T) {
|
||||
// json.Number for SKU
|
||||
src := map[string]any{
|
||||
"sku": json.Number("123456789012345"), // float64-unsafe
|
||||
"title": "BigNumber SKU",
|
||||
"price_inc_vat": json.Number("14995"), // already øre
|
||||
"currency": "SEK",
|
||||
"tax_class": "standard",
|
||||
"updated_at": json.Number("1700000000000"),
|
||||
"sku": json.Number("123456789012345"), // float64-unsafe
|
||||
"title": "BigNumber SKU",
|
||||
"price_inc_vat": json.Number("14995"), // already øre
|
||||
"currency": "SEK",
|
||||
"tax_class": "standard",
|
||||
"updated_at": json.Number("1700000000000"),
|
||||
}
|
||||
p, err := Apply(DefaultSchema(), src)
|
||||
if err != nil {
|
||||
@@ -193,3 +193,99 @@ func TestBuilderFractionalStringPriceCorrectScale(t *testing.T) {
|
||||
t.Errorf("PriceIncVat: got %d want %d", p.PriceIncVat, 14995)
|
||||
}
|
||||
}
|
||||
|
||||
// Drop-ship routing carriers (docs/plan-dropship.md Phase 1): seller id /
|
||||
// name / lead time coerce from per-tenant source keys via Schema overrides,
|
||||
// mirroring how the live feed emits supplierName-style keys. Zero values
|
||||
// (missing keys, negative numbers, junk strings) must stay at the documented
|
||||
// "unset" signals rather than erroring — one bad item can't poison a batch.
|
||||
func TestBuilderDropshipCarriers(t *testing.T) {
|
||||
s := DefaultSchema()
|
||||
s.SellerIdField = "supplierId"
|
||||
s.SellerNameField = "supplierName"
|
||||
s.LeadTimeField = "deliveryTime"
|
||||
|
||||
p, err := Apply(s, map[string]any{
|
||||
"sku": "X-1",
|
||||
"price_inc_vat": int64(100_00),
|
||||
"updated_at": int64(1700000000000),
|
||||
"drop_ship": true,
|
||||
"supplierId": 4711,
|
||||
"supplierName": "Bygg Import AB",
|
||||
"deliveryTime": 3,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply with dropship carriers: %v", err)
|
||||
}
|
||||
if !p.DropShip {
|
||||
t.Error("DropShip: got false, want true")
|
||||
}
|
||||
if p.SellerID != 4711 {
|
||||
t.Errorf("SellerID: got %d, want 4711", p.SellerID)
|
||||
}
|
||||
if p.SellerName != "Bygg Import AB" {
|
||||
t.Errorf("SellerName: got %q", p.SellerName)
|
||||
}
|
||||
if p.LeadTimeDays != 3 {
|
||||
t.Errorf("LeadTimeDays: got %d, want 3", p.LeadTimeDays)
|
||||
}
|
||||
|
||||
// Missing keys → unset signals, no error.
|
||||
p, err = Apply(s, map[string]any{
|
||||
"sku": "X-2",
|
||||
"price_inc_vat": int64(100_00),
|
||||
"updated_at": int64(1700000000000),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply without dropship carriers: %v", err)
|
||||
}
|
||||
if p.DropShip || p.SellerID != 0 || p.SellerName != "" || p.LeadTimeDays != 0 {
|
||||
t.Errorf("unset carriers should zero: %+v", p)
|
||||
}
|
||||
|
||||
// Junk shapes floor to unset, never fail the build.
|
||||
for name, bad := range map[string]any{
|
||||
"negative id": -5,
|
||||
"string id": "not-a-number",
|
||||
"float id": 1.5,
|
||||
} {
|
||||
p, err = Apply(s, map[string]any{
|
||||
"sku": "X-3", "price_inc_vat": int64(100_00),
|
||||
"updated_at": int64(1700000000000),
|
||||
"supplierId": bad,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("%s: apply should not fail on junk carrier: %v", name, err)
|
||||
}
|
||||
if p.SellerID != 0 {
|
||||
t.Errorf("%s: SellerID should be 0, got %d", name, p.SellerID)
|
||||
}
|
||||
}
|
||||
|
||||
// Wire round-trip: new fields survive Encode/Decode for consumers that
|
||||
// never rebuilt.
|
||||
b, err := p.Encode()
|
||||
if err != nil {
|
||||
t.Fatalf("encode: %v", err)
|
||||
}
|
||||
rt, err := Decode(b)
|
||||
if err != nil {
|
||||
t.Fatalf("decode: %v", err)
|
||||
}
|
||||
if rt.SKU != p.SKU || rt.DropShip || rt.SellerID != 0 {
|
||||
t.Errorf("round-trip mismatch: %+v vs %+v", rt, p)
|
||||
}
|
||||
|
||||
// json.Number lead time (UseNumber producers).
|
||||
p, err = Apply(s, map[string]any{
|
||||
"sku": "X-4", "price_inc_vat": int64(100_00),
|
||||
"updated_at": int64(1700000000000),
|
||||
"deliveryTime": json.Number("7"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("json.Number lead time: %v", err)
|
||||
}
|
||||
if p.LeadTimeDays != 7 {
|
||||
t.Errorf("LeadTimeDays from json.Number: got %d, want 7", p.LeadTimeDays)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user