A missing capability reached the feature factory as an anonymous TypeError. The composer now names the feature and the capability, and the IndexedDB provider example moves from a browser spec into an opt-in recipe with a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { composeFeatureAdapterInputs } from "../../src/features/feature-adapter-contribution.ts";
|
|
import { LOCAL_DRAFT_FEATURE_ADAPTER_CONTRIBUTION } from "../../src/features/local-draft-feature/adapters/create-local-draft-feature-input.ts";
|
|
import { createLocalDraftIndexedDbCapability } from "../../recipes/frontend-capabilities/indexeddb-feature-capability.ts";
|
|
import { MemoryIndexedDbFactory } from "../helpers/memory-indexeddb.ts";
|
|
|
|
describe("IndexedDB feature capability recipe (09-05)", () => {
|
|
it("composes local-draft over the recipe's IndexedDB capability", async () => {
|
|
const memory = new MemoryIndexedDbFactory();
|
|
const capability = createLocalDraftIndexedDbCapability({
|
|
scope: Object.freeze({
|
|
authorityToken: "a1b2c3d4e5f60718293a4b5c6d7e8f90",
|
|
namespaceToken: "n1b2c3d4e5f60718293a4b5c6d7e8f90",
|
|
partitionToken: "p1b2c3d4e5f60718293a4b5c6d7e8f90",
|
|
accountScope: "ORIGIN_SHARED" as const,
|
|
}),
|
|
authorizeLifecycle: () => ({ authorized: false }),
|
|
factory: memory.factory,
|
|
});
|
|
try {
|
|
await expect(capability.open()).resolves.toEqual({
|
|
ok: true,
|
|
value: undefined,
|
|
});
|
|
const inputs = composeFeatureAdapterInputs(
|
|
Object.freeze([LOCAL_DRAFT_FEATURE_ADAPTER_CONTRIBUTION] as const),
|
|
Object.freeze(["local-draft"]),
|
|
Object.freeze({ indexedDb: capability.indexedDb }),
|
|
);
|
|
const localDraft = inputs["local-draft"];
|
|
if (!localDraft) throw new Error("local-draft input was not composed");
|
|
const draft = Object.freeze({
|
|
draftId: "draft-1",
|
|
title: "Architecture notes",
|
|
body: "Stored through the recipe capability.",
|
|
});
|
|
|
|
await expect(
|
|
localDraft.saveDraft({
|
|
draft,
|
|
expectedRevision: null,
|
|
idempotencyKey: "local-draft-create-1",
|
|
}),
|
|
).resolves.toEqual({ ok: true, value: { revision: 1 } });
|
|
await expect(localDraft.findDraft("draft-1")).resolves.toEqual({
|
|
ok: true,
|
|
value: { draft, revision: 1 },
|
|
});
|
|
} finally {
|
|
capability.close();
|
|
}
|
|
});
|
|
});
|