Fix API Error before M5
This commit is contained in:
+19
-1
@@ -490,7 +490,25 @@ sent an English shopper following "load more" to the Vietnamese listing — invi
|
||||
default locale, which is exactly why it survived.
|
||||
|
||||
So: **exercise a flow on data you just created, not only on seeded data, perform each action
|
||||
twice, and do it in a non-default locale.** Seed data has been through every code path already; new data has been through none. The
|
||||
twice, and do it in a non-default locale.**
|
||||
|
||||
The sweep before M5 added one more, and it is the sharpest of the set. Two of the worst defects
|
||||
in the catalog write path were not logic errors at all — they were **library behaviour that had
|
||||
drifted out from under the intent written in the comments**:
|
||||
|
||||
- `z.record(z.enum(LOCALES), …)` is exhaustive in Zod 4. The helper was named
|
||||
`requiredTranslations`, its comment said "at least the default locale", and its `.refine`
|
||||
checked exactly that — and was unreachable. Every single-language product was rejected.
|
||||
- `.partial()` makes a field optional but keeps its `.default([])`. So an omitted
|
||||
`genderTargets` arrived as `[]`, and `[]` is truthy. Renaming a product cleared its targeting,
|
||||
dropped every collection link and deleted all of its attributes.
|
||||
|
||||
Both typechecked. Both read correctly. Neither had a test, because the behaviour they depended on
|
||||
was assumed rather than asserted. `packages/validation/src/catalog-admin.spec.ts` now pins both.
|
||||
|
||||
So: **when a schema encodes an intent, assert the intent — not the shape.** "Absent means leave
|
||||
alone" and "one language is enough" are claims about behaviour, and a type signature cannot make
|
||||
either of them true. Seed data has been through every code path already; new data has been through none. The
|
||||
inventory case is pinned in `apps/api/src/modules/inventory/inventory-list.spec.ts`.
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user