Skip to content

fix: accept money without type in typed money drafts - #458

Merged
mvantellingen merged 1 commit into
mainfrom
fix/typed-money-draft
Oct 26, 2026
Merged

mvantellingen merged 1 commit into
mainfrom
fix/typed-money-draft

Conversation

@mvantellingen

Copy link
Copy Markdown
Member

The mock rejected a plain Money (no type) wherever a TypedMoneyDraft is expected, e.g. the money of a fixed cart discount value:

POST /unittest/cart-discounts  value: {"type":"fixed","money":[{"centAmount":1000,"currencyCode":"USD"}]}
-> 400 InvalidJsonInput: value.money.0.type: Invalid enum value

commercetools accepts this and treats the money as centPrecision. This broke the terraform-provider-commercetools acceptance tests (TestAccCartDiscountFixed, TestAccCartDiscountStores) against mock 5.1.0.

Changes

  • scripts/generate-schemas.ts: add an OPTIONAL_PROPERTIES override (applied in patchSpec, next to EXTRA_PROPERTIES) that drops type from the required list of TypedMoneyDraft; regenerated common.ts (only TypedMoneyDraftSchema.type changes to .nullish()).
  • The resource builders already go through createTypedMoney, which defaults to centPrecision with currency-based fractionDigits.
  • StandalonePriceDraft.staged (the other TypedMoneyDraft consumer) was silently dropped; it is now stored via createTypedMoney as well.
  • Tests: strict-mode draft tests for fixed/absolute cart discount values with plain money, typed (highPrecision) money still accepted, unknown money type still rejected, staged standalone price with plain money; generator test for the override.
  • Changeset (patch).

Verified locally with a docker image built from this branch: TestAccCartDiscountFixed and TestAccCartDiscountStores from terraform-provider-commercetools pass.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 692d46d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@labdigital/commercetools-mock Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mvantellingen
mvantellingen merged commit 29b4f36 into main Oct 26, 2026
11 checks passed
@mvantellingen
mvantellingen deleted the fix/typed-money-draft branch October 26, 2026 08:02
@github-actions github-actions Bot mentioned this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant