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:
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user