support datafields in projection
This commit is contained in:
1 parent
b128608316
commit
d04679daf5
4 files changed
+64
-7
No files matched your search
@@ -37,6 +37,39 @@ func TestBuilderJSONNumber(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderAttributes(t *testing.T) {
|
||||
s := DefaultSchema()
|
||||
s.AttributesFields = []string{"cart", "color"}
|
||||
src := map[string]any{
|
||||
"sku": "X-1",
|
||||
"price_inc_vat": int64(100),
|
||||
"updated_at": int64(1700000000000),
|
||||
"cart": map[string]any{"data": "some-cart-data"},
|
||||
"color": "red",
|
||||
"ignored": "should-not-be-in-attrs",
|
||||
}
|
||||
p, err := Apply(s, src)
|
||||
if err != nil {
|
||||
t.Fatalf("Apply: %v", err)
|
||||
}
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(p.Attributes, &m); err != nil {
|
||||
t.Fatalf("unmarshal Attributes: %v", err)
|
||||
}
|
||||
if len(m) != 2 {
|
||||
t.Errorf("expected 2 attributes, got %d", len(m))
|
||||
}
|
||||
if cartVal, ok := m["cart"].(map[string]any); !ok || cartVal["data"] != "some-cart-data" {
|
||||
t.Errorf("cart attribute: got %v", m["cart"])
|
||||
}
|
||||
if m["color"] != "red" {
|
||||
t.Errorf("color attribute: got %v", m["color"])
|
||||
}
|
||||
if _, ok := m["ignored"]; ok {
|
||||
t.Errorf("ignored attribute was extracted: %v", m)
|
||||
}
|
||||
}
|
||||
|
||||
// Updated=UseSourceField: missing source updated_at MUST be a loud error,
|
||||
// not a stamp-now fallback. (Foot-gun 3 resolution: silence here invalidates
|
||||
// every consumer's cache on rebuild.)
|
||||
|
||||
Reference in new issue
Block a user