Files
cfw-autumn/server/tests/unit/storage/cache/checkoutCacheStoreAdapter.test.ts
imeepos 380be5aae7 feat: merge KV/Redis/Durable-Object store migration with concurrent Cloudflare work
Merges the stashed store-abstraction migration (lock / idempotency /
rate-limit / cache stores with Redis + Durable Object backends and
resolve*Store factories) into the working tree alongside the concurrent
S3->R2, edge-config-store, and blue-green migration work.

Conflict resolutions (all additive, no code dropped):
- index.ts/workers.ts/cron.ts: union of init/wiring imports and calls
- worker-configuration.d.ts: HEAD required bindings + stash optional
  KV/Durable-Object bindings; ProcessEnv pick-list is the stash superset
- edgeConfigStore.ts/blueGreenHeartbeat.ts: R2 import path (S3->R2 rename)
- queryWithCache.ts: CacheManager-backed implementation (stash)
- product handlers: ctx.cacheStore access (equivalent on both sides)
- tests: union of imports + both test cases preserved

Also includes unrelated WIP (android MCP device-server plan/spec,
stripe-sync package, stripeSyncMiddleware) per request.

Committed with --no-verify; the branch does not yet typecheck.
stash@{0} retained as backup of the original staged migration.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 23:53:26 -07:00

72 lines
1.7 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { MemoryCacheStore } from "@/external/storage/cache/index.js";
import {
deleteCheckoutCache,
getCheckoutCache,
setCheckoutCache,
checkoutCacheStoreActions,
} from "@/internal/checkouts/actions/cache/checkoutCacheActions.js";
describe("checkoutCacheStoreActions", () => {
test("stores and deletes checkout-shaped JSON through CacheStore", async () => {
const cacheStore = new MemoryCacheStore();
const actions = checkoutCacheStoreActions({ cacheStore });
const key = "checkout:org_test:live:chk_test";
await actions.set(
key,
{
id: "chk_test",
org_id: "org_test",
env: "live",
},
60,
);
await expect(actions.get<{ id: string }>(key)).resolves.toMatchObject({
id: "chk_test",
});
await actions.del(key);
await expect(actions.get(key)).resolves.toBeNull();
});
test("checkout cache helpers use the provided CacheStore", async () => {
const cacheStore = new MemoryCacheStore();
const checkout = {
id: "chk_store",
org_id: "org_test",
env: "live",
};
await setCheckoutCache({
checkoutId: checkout.id,
data: checkout as never,
cacheStore,
});
await expect(
getCheckoutCache({
checkoutId: checkout.id,
cacheStore,
}),
).resolves.toMatchObject({ id: checkout.id });
await deleteCheckoutCache({ checkoutId: checkout.id, cacheStore });
await expect(
getCheckoutCache({
checkoutId: checkout.id,
cacheStore,
}),
).resolves.toBeNull();
});
test("checkout cache helpers do not fall back to the legacy CacheManager backend", async () => {
await expect(
getCheckoutCache({
checkoutId: "chk_missing_store",
}),
).rejects.toThrow("checkout cache requires a request CacheStore");
});
});