feat(features): add test factories to all 5 features
Adds src/__factories__/<entity>.factory.ts to auth, blog, marketing-pages, navigation, media. Each factory uses defineFactory from @repo/core-testing with stable date defaults (2026-01-01) so snapshot diffs reflect SUT behavior only. Refactors mechanical inline-fixture tests to use factories. Also adds vitest.config.ts and tsconfig path alias to @repo/media (lacked both), and adds @repo/core-testing devDependency to @repo/media. Spec: §5.1, §6.3
This commit is contained in:
2
packages/marketing-pages/src/__factories__/index.ts
Normal file
2
packages/marketing-pages/src/__factories__/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { pageFactory } from "./page.factory.js";
|
||||
export { siteSettingsFactory } from "./site-settings.factory.js";
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { pageFactory } from "@/__factories__/page.factory";
|
||||
|
||||
describe("pageFactory", () => {
|
||||
beforeEach(() => pageFactory.reset());
|
||||
|
||||
it("returns a Page with stable defaults", () => {
|
||||
const p = pageFactory.build();
|
||||
expect(p.id).toBe("page-1");
|
||||
expect(p.title).toBe("Page 1");
|
||||
expect(p.slug).toBe("page-1");
|
||||
expect(p.status).toBe("draft");
|
||||
expect(p.createdAt).toEqual(new Date("2026-01-01T00:00:00Z"));
|
||||
});
|
||||
|
||||
it("applies overrides", () => {
|
||||
const p = pageFactory.build({ status: "published", title: "About" });
|
||||
expect(p.status).toBe("published");
|
||||
expect(p.title).toBe("About");
|
||||
expect(p.id).toBe("page-1");
|
||||
});
|
||||
|
||||
it("increments sequence per build", () => {
|
||||
const a = pageFactory.build();
|
||||
const b = pageFactory.build();
|
||||
expect(a.id).toBe("page-1");
|
||||
expect(b.id).toBe("page-2");
|
||||
});
|
||||
});
|
||||
19
packages/marketing-pages/src/__factories__/page.factory.ts
Normal file
19
packages/marketing-pages/src/__factories__/page.factory.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineFactory } from "@repo/core-testing/factory";
|
||||
import type { Page } from "../entities/page.js";
|
||||
|
||||
export const pageFactory = defineFactory<Page>(({ sequence }) => ({
|
||||
id: `page-${sequence}`,
|
||||
title: `Page ${sequence}`,
|
||||
slug: `page-${sequence}`,
|
||||
hero: {
|
||||
heading: `Hero ${sequence}`,
|
||||
},
|
||||
layout: [],
|
||||
status: "draft",
|
||||
publishedAt: null,
|
||||
seo: {
|
||||
title: `Page ${sequence} | Site`,
|
||||
},
|
||||
createdAt: new Date("2026-01-01T00:00:00Z"),
|
||||
updatedAt: new Date("2026-01-01T00:00:00Z"),
|
||||
}));
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
import { siteSettingsFactory } from "@/__factories__/site-settings.factory";
|
||||
|
||||
describe("siteSettingsFactory", () => {
|
||||
beforeEach(() => siteSettingsFactory.reset());
|
||||
|
||||
it("returns SiteSettings with stable defaults", () => {
|
||||
const s = siteSettingsFactory.build();
|
||||
expect(s.siteName).toBe("Site 1");
|
||||
});
|
||||
|
||||
it("applies overrides", () => {
|
||||
const s = siteSettingsFactory.build({ siteName: "My Brand" });
|
||||
expect(s.siteName).toBe("My Brand");
|
||||
});
|
||||
|
||||
it("increments sequence per build (siteName reflects it)", () => {
|
||||
const a = siteSettingsFactory.build();
|
||||
const b = siteSettingsFactory.build();
|
||||
expect(a.siteName).toBe("Site 1");
|
||||
expect(b.siteName).toBe("Site 2");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineFactory } from "@repo/core-testing/factory";
|
||||
import type { SiteSettings } from "../entities/site-settings.js";
|
||||
|
||||
export const siteSettingsFactory = defineFactory<SiteSettings>(({ sequence }) => ({
|
||||
siteName: `Site ${sequence}`,
|
||||
}));
|
||||
Reference in New Issue
Block a user