src/features/local-draft-feature는 기능이 아니라 IndexedDB recipe의 소비자다. 시험 5개와 recipe가 쓰고, 그래서 생성기에 NOT_A_FEATURE 예외가 있었다(S4 3.1절 S-3). 코드를 tests/fixtures/indexeddb-consumer/로 옮기고 import만 고쳤다. NOT_A_FEATURE 표식은 이 폴더만 썼고 다운스트림 둘에도 없어 생성기에서 지웠다. 선언 없는 폴더는 밖으로 옮기라는 메시지로 실패한다. 매뉴얼 오류표, README, starter-experience, capability-consumer-experience, patterns를 고쳤다. 위험: fixture는 기능 폴더 밖이라 기능 계층 규칙(dependency-cruiser)이 걸리지 않는다. recipe가 tests/ 아래 파일을 type import한다. 검증(desktop): test:contract, test:recipes, test:browser-capabilities, test:unit 통과.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
createLocalDraftFeatureInput,
|
|
type LocalDraftStore,
|
|
} from "../fixtures/indexeddb-consumer/application/local-draft-api.ts";
|
|
|
|
function recordingStore() {
|
|
const save = vi.fn<LocalDraftStore["save"]>(async () =>
|
|
Object.freeze({ ok: true as const, value: Object.freeze({ revision: 1 }) }),
|
|
);
|
|
const store: LocalDraftStore = Object.freeze({
|
|
save,
|
|
find: async () => Object.freeze({ ok: true as const, value: null }),
|
|
remove: async () => Object.freeze({ ok: true as const, value: undefined }),
|
|
});
|
|
return { save, store };
|
|
}
|
|
|
|
function command(draft: Readonly<{ draftId: string; title: string; body: string }>) {
|
|
return Object.freeze({ draft, expectedRevision: null, idempotencyKey: "save-1" });
|
|
}
|
|
|
|
describe("local-draft save applies the domain rules (09-06)", () => {
|
|
it.each([
|
|
["a blank draft id", { draftId: " ", title: "Title", body: "" }],
|
|
["a blank title", { draftId: "draft-1", title: " ", body: "" }],
|
|
["a 161-character title", { draftId: "draft-1", title: "t".repeat(161), body: "" }],
|
|
["a body over 100,000 characters", { draftId: "draft-1", title: "Title", body: "b".repeat(100_001) }],
|
|
])("rejects %s without calling the store", async (_case, draft) => {
|
|
const { save, store } = recordingStore();
|
|
const result = await createLocalDraftFeatureInput(store).saveDraft(command(draft));
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: { kind: "VALIDATION_REJECTED", operationId: "LOCAL_DRAFT_SAVE" },
|
|
});
|
|
expect(save).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("stores the normalized draft at the limits", async () => {
|
|
const { save, store } = recordingStore();
|
|
const title = "t".repeat(160);
|
|
const body = "b".repeat(100_000);
|
|
await expect(
|
|
createLocalDraftFeatureInput(store).saveDraft(
|
|
command({ draftId: " draft-1 ", title: ` ${title} `, body }),
|
|
),
|
|
).resolves.toEqual({ ok: true, value: { revision: 1 } });
|
|
expect(save).toHaveBeenCalledWith(
|
|
expect.objectContaining({ draft: { draftId: "draft-1", title, body } }),
|
|
undefined,
|
|
);
|
|
});
|
|
});
|