Skip to content

Testing

Use the smallest real seam that proves the behavior.

Definitions need no database or provider:

import { Billing, Downloads, Offer, Purchase } from "@byfungsi/sapa";
import { Effect } from "effect";
const parsed = await Effect.runPromise(
Effect.gen(function* () {
const download = yield* Downloads.download({
asset: { key: "ebook.pdf", revision: 1 },
duration: "perpetual",
});
const purchase = yield* Purchase.parse({
key: "ebook.benefits",
revision: 1,
provides: [download],
});
const billing = yield* Billing.oneTime({
price: { currency: "IDR", amount: 99_000n },
});
return yield* Offer.parse({
key: "ebook",
revision: 1,
purchase,
billing,
});
}),
);
console.assert(parsed.key === "ebook");

Also test snapshot round trips and Offer.checkCompatibility when your runtime supports a constrained capability set.

Provide a faithful test Layer containing storage, clock, IDs, provider registry, snapshot protection, and the chosen Sapa Layer. Keep time and generated IDs deterministic. Exercise public facade operations instead of mocking their modules.

High-value cases include:

  • exact idempotent replay and changed-material conflict;
  • concurrent seat or credit contention;
  • checkout timeout followed by reconciliation;
  • duplicate and contradictory provider notifications;
  • end-exclusive access expiry;
  • refund reversal;
  • metered late usage and post-close corrections;
  • one-time secret issuance and rotation.

Do not use vi.mock or jest.mock. In-memory fakes are appropriate when they faithfully implement the capability contract; use local database integration tests for atomicity and conflict behavior.