feat(features): contract suites for all repository interfaces
Each repository interface now has a contract suite under
src/__contracts__/. Both Mock and Payload implementations run the
same suite, eliminating mock-vs-real drift. Payload impls back the
contract with an in-memory stub via vi.mock('payload') + a small
buildPayloadStub helper.
Spec: §5.2, §6.4
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import { describe } from "vitest";
|
||||
import { MockHeaderRepository } from "@/infrastructure/repositories/mock-header.repository";
|
||||
import { headerRepositoryContract } from "@/__contracts__/header-repository.contract";
|
||||
|
||||
describe("MockHeaderRepository", () => {
|
||||
headerRepositoryContract.run(() => new MockHeaderRepository());
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, vi } from "vitest";
|
||||
import { PayloadHeaderRepository } from "@/infrastructure/repositories/payload-header.repository";
|
||||
import { headerRepositoryContract } from "@/__contracts__/header-repository.contract";
|
||||
import { stubPayloadConfig } from "@repo/core-testing/payload/stub-config";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// In-memory Payload stub for header (Global)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function buildHeaderStub() {
|
||||
const globalData = {
|
||||
logo: null,
|
||||
items: [
|
||||
{ label: "Home", href: "/", external: false },
|
||||
{ label: "Blog", href: "/blog", external: false },
|
||||
{ label: "About", href: "/about", external: false },
|
||||
],
|
||||
};
|
||||
|
||||
return {
|
||||
findGlobal: vi.fn(async () => {
|
||||
return { ...globalData };
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
vi.mock("payload", () => ({
|
||||
getPayload: vi.fn(),
|
||||
}));
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Contract suite
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe("PayloadHeaderRepository", () => {
|
||||
describe("contract", () => {
|
||||
headerRepositoryContract.run(async () => {
|
||||
const stub = buildHeaderStub();
|
||||
const { getPayload } = await import("payload");
|
||||
(getPayload as ReturnType<typeof vi.fn>).mockResolvedValue(stub);
|
||||
return new PayloadHeaderRepository(stubPayloadConfig);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user