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,12 +1,26 @@
import { it, expect, beforeEach } from "vitest";
import { defineContractSuite } from "@repo/core-testing/contract";
import type { IHeaderRepository } from "../application/repositories/header-repository.interface.js";
import type { Header } from "../entities/header.js";
/**
* Known fixtures that every implementation's `buildSubject` must pre-seed.
* Exported so that test files can pass them to `MockHeaderRepository` or the
* Payload stub without duplicating definitions.
*/
export const CONTRACT_HEADER_SEED: Header = {
items: [
{ label: "Home", href: "/", external: false },
{ label: "Blog", href: "/blog", external: false },
{ label: "Docs", href: "/docs", external: true },
],
};
/**
* Contract for IHeaderRepository.
*
* Header is a singleton (Payload Global). The interface exposes only
* getHeader(). The contract verifies the shape of the return value.
* getHeader(). The contract verifies the shape, count, and order of items.
*/
export const headerRepositoryContract =
defineContractSuite<IHeaderRepository>(
@@ -20,10 +34,24 @@ export const headerRepositoryContract =
// --- getHeader ---
it("getHeader returns an object with an items array", async () => {
it("getHeader returns an object with an items array of the seeded length", async () => {
const header = await repo.getHeader();
expect(header).toBeDefined();
expect(header.items).toBeInstanceOf(Array);
expect(header.items).toHaveLength(3);
});
it("getHeader items appear in the seeded order with correct shape", async () => {
const header = await repo.getHeader();
expect(header.items[0]?.label).toBe("Home");
expect(header.items[0]?.href).toBe("/");
expect(header.items[0]?.external).toBe(false);
expect(header.items[1]?.label).toBe("Blog");
expect(header.items[1]?.href).toBe("/blog");
expect(header.items[1]?.external).toBe(false);
expect(header.items[2]?.label).toBe("Docs");
expect(header.items[2]?.href).toBe("/docs");
expect(header.items[2]?.external).toBe(true);
});
it("getHeader items have label, href, and external fields", async () => {