Skip to content

test(nodejs): add checkout behavioral test suite#138

Merged
carolinerg1 merged 1 commit into
Universal-Commerce-Protocol:mainfrom
vishkaty:test/nodejs-behavioral-suite
Jul 24, 2026
Merged

test(nodejs): add checkout behavioral test suite#138
carolinerg1 merged 1 commit into
Universal-Commerce-Protocol:mainfrom
vishkaty:test/nodejs-behavioral-suite

Conversation

@vishkaty

Copy link
Copy Markdown
Contributor

Closes the Node.js behavioral test gap described in #136.

What

Adds a behavioral test suite for the Node.js sample, mirroring the Python
server's coverage on the CI lane added in #126, so a regression in the checkout
flow no longer ships green. It uses the existing node:test + app.request()
conventions and adds no dependencies.

Area Coverage
lifecycle.test.ts create → retrieve → complete (order assigned), payment-failure (402), cancel, and completed/canceled immutability (409)
idempotency.test.ts same-key replay returns the original checkout; same-key + different body → 409; keyless requests stay independent
validation_flow.test.ts unknown product and over-stock are rejected; in-stock succeeds
discount.test.ts (extended) case-insensitive code match, empty codes[] clears discounts, and allocations[] reconcile to the applied amount

Why

The Node.js suite was three files; the Python server has a full behavioral
suite. That asymmetry meant checkout-flow regressions on the Node.js sample
passed CI. These tests exercise the real service handlers end to end through a
minimal Hono app (the same approach as discovery.test.ts), so they catch
behavioral drift, not just types.

Verification

  • npm run build clean and npm test green (21 tests).
  • pre-commit run clean (prettier, codespell).

Happy to split this into per-area PRs if that reviews more easily — offered in
#136; opening it as one small suite here since the areas share the harness.

@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Jul 22, 2026
@damaz91 damaz91 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Jul 23, 2026
@damaz91
damaz91 requested a review from carolinerg1 July 23, 2026 11:39
Adds behavioral coverage on the Node.js sample's CI lane, mirroring the Python
server's suite, so a checkout-flow regression no longer ships green. Uses the
existing node:test + app.request() conventions and the @ucp-js/sdk schemas
(rest/nodejs consumes the SDK since Universal-Commerce-Protocol#139), no new dependencies.

- lifecycle: create -> retrieve -> complete (order assigned), payment failure,
  cancel, and completed/canceled immutability
- idempotency: same-key replay, same-key/different-body conflict, keyless
- validation: unknown product and over-stock rejection
- fulfillment: options are quoted, selecting one adds its cost to the receipt,
  and completing without a fulfillment selection is rejected
- discount: case-insensitive match, empty codes clear, allocations reconcile
@vishkaty
vishkaty force-pushed the test/nodejs-behavioral-suite branch from b2c38c4 to fb97443 Compare July 24, 2026 03:38
@vishkaty

Copy link
Copy Markdown
Contributor Author

Heads-up @damaz91 — I rebased this onto latest main and adapted it to the @ucp-js/sdk refactor from #139: the suite now uses the SDK's schemas (CheckoutCompleteRequestSchema etc.) via src/models, matching how the sample consumes the SDK now, and the complete-request payloads use the new payment: { instruments: [...] } shape.

While rebasing I also added the fulfillment area — options are quoted, selecting one adds its cost to the receipt, and completing without a fulfillment selection is rejected — which completes the coverage I offered in #136.

Clean single commit on latest main; full suite green (25 tests), npm run build (tsc) clean, pre-commit clean. Sorry to reset your approval — ready for another look whenever you have a moment. 🙏

@carolinerg1
carolinerg1 merged commit cc2b57f into Universal-Commerce-Protocol:main Jul 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants