fix(tests): address Task 4 code review feedback

- Deprecate mockPayloadModule with throw guard (hoisting incompatible)
- Replace `as never` with stubPayloadConfig in payload-articles test (consistency)
- Tighten pages contract to use toHaveLength (exact assertions)
- Header contract: define CONTRACT_HEADER_SEED, assert item count + order

Reviewer: superpowers:code-reviewer (Task 4 of Plan 7).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 16:04:07 +02:00
parent e1355e6bc7
commit b3c903fd36
7 changed files with 76 additions and 36 deletions

View File

@@ -1,7 +1,7 @@
import { describe } from "vitest";
import { MockHeaderRepository } from "@/infrastructure/repositories/mock-header.repository";
import { headerRepositoryContract } from "@/__contracts__/header-repository.contract";
import { headerRepositoryContract, CONTRACT_HEADER_SEED } from "@/__contracts__/header-repository.contract";
describe("MockHeaderRepository", () => {
headerRepositoryContract.run(() => new MockHeaderRepository());
headerRepositoryContract.run(() => new MockHeaderRepository(CONTRACT_HEADER_SEED));
});

View File

@@ -2,17 +2,23 @@ import "reflect-metadata";
import { injectable } from "inversify";
import type { IHeaderRepository } from "../../application/repositories/header-repository.interface";
import type { Header } from "../../entities/header";
import type { Header, HeaderItem } from "../../entities/header";
const DEFAULT_ITEMS: HeaderItem[] = [
{ label: "Home", href: "/", external: false },
{ label: "Blog", href: "/blog", external: false },
{ label: "Docs", href: "/docs", external: true },
];
@injectable()
export class MockHeaderRepository implements IHeaderRepository {
private readonly data: Header;
constructor(initialData?: Header) {
this.data = initialData ?? { items: DEFAULT_ITEMS };
}
async getHeader(): Promise<Header> {
return {
items: [
{ label: "Home", href: "/", external: false },
{ label: "Blog", href: "/blog", external: false },
{ label: "About", href: "/about", external: false },
],
};
return this.data;
}
}

View File

@@ -1,6 +1,6 @@
import { describe, vi } from "vitest";
import { PayloadHeaderRepository } from "@/infrastructure/repositories/payload-header.repository";
import { headerRepositoryContract } from "@/__contracts__/header-repository.contract";
import { headerRepositoryContract, CONTRACT_HEADER_SEED } from "@/__contracts__/header-repository.contract";
import { stubPayloadConfig } from "@repo/core-testing/payload/stub-config";
// ---------------------------------------------------------------------------
@@ -8,18 +8,9 @@ import { stubPayloadConfig } from "@repo/core-testing/payload/stub-config";
// ---------------------------------------------------------------------------
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 };
return { ...CONTRACT_HEADER_SEED };
}),
};
}