test: add comprehensive automated test coverage
- Vitest multi-project setup (unit / integration / component) - Real-Postgres integration harness via in-process PGlite (TEST_DATABASE_URL override), migrations applied per worker; production code untouched - Unit: routing, locale, validation/Zod schemas, metadata, mail, site-theme, marquee, media, portfolio helpers, plus architecture-rule tests - Integration: Prisma data layer, API routes, and all server actions - Component: UI primitives and form components (jsdom + Testing Library) - 371 tests passing
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import { MediaKind, MediaSource, MediaUsageType, PortfolioSectionType } from "@prisma/client";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
let counter = 0;
|
||||
function uniq(prefix: string) {
|
||||
counter += 1;
|
||||
return `${prefix}-${counter}`;
|
||||
}
|
||||
|
||||
export function createCategory(overrides: Record<string, unknown> = {}) {
|
||||
const slug = (overrides.slug as string) ?? uniq("cat");
|
||||
return prisma.category.create({
|
||||
data: {
|
||||
slug,
|
||||
nameAr: "الاسم",
|
||||
nameEn: "Name",
|
||||
nameDe: "Name",
|
||||
descriptionAr: "وصف",
|
||||
descriptionEn: "Description",
|
||||
descriptionDe: "Beschreibung",
|
||||
sortOrder: 0,
|
||||
isActive: true,
|
||||
...overrides,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function createProject(overrides: Record<string, unknown> = {}) {
|
||||
const categoryId = (overrides.categoryId as string) ?? (await createCategory()).id;
|
||||
const isPublished = (overrides.isPublished as boolean) ?? true;
|
||||
const slug = (overrides.slug as string) ?? uniq("proj");
|
||||
return prisma.portfolioProject.create({
|
||||
data: {
|
||||
categoryId,
|
||||
slug,
|
||||
viewMode: "GRID",
|
||||
titleAr: "عنوان",
|
||||
titleEn: "Title",
|
||||
titleDe: "Titel",
|
||||
summaryAr: "ملخص",
|
||||
summaryEn: "Summary",
|
||||
summaryDe: "Zusammenfassung",
|
||||
clientName: "Client",
|
||||
projectYear: 2025,
|
||||
serviceLabelAr: "خدمة",
|
||||
serviceLabelEn: "Service",
|
||||
serviceLabelDe: "Service",
|
||||
isFeatured: false,
|
||||
sortOrder: 0,
|
||||
...overrides,
|
||||
isPublished,
|
||||
publishedAt: isPublished ? new Date() : null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function createSection(projectId: string, overrides: Record<string, unknown> = {}) {
|
||||
return prisma.portfolioSection.create({
|
||||
data: {
|
||||
projectId,
|
||||
type: PortfolioSectionType.RICH_TEXT,
|
||||
titleAr: "ع",
|
||||
titleEn: "t",
|
||||
titleDe: "t",
|
||||
bodyAr: "ب",
|
||||
bodyEn: "b",
|
||||
bodyDe: "b",
|
||||
sortOrder: 0,
|
||||
...overrides,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function createAsset(projectId: string, overrides: Record<string, unknown> = {}) {
|
||||
return prisma.portfolioAsset.create({
|
||||
data: {
|
||||
projectId,
|
||||
kind: "IMAGE",
|
||||
filePath: "/uploads/media/assets/x.svg",
|
||||
altAr: "ع",
|
||||
altEn: "a",
|
||||
altDe: "a",
|
||||
sortOrder: 0,
|
||||
...overrides,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function createMediaAsset(overrides: Record<string, unknown> = {}) {
|
||||
return prisma.mediaAsset.create({
|
||||
data: {
|
||||
source: MediaSource.EXTERNAL,
|
||||
kind: MediaKind.IMAGE,
|
||||
url: (overrides.url as string) ?? `https://cdn.example.com/${uniq("img")}.png`,
|
||||
fileName: "img.png",
|
||||
label: "Image",
|
||||
...overrides,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function createMediaUsage(
|
||||
assetId: string,
|
||||
overrides: Record<string, unknown> = {},
|
||||
) {
|
||||
return prisma.mediaUsage.create({
|
||||
data: {
|
||||
assetId,
|
||||
usageType: MediaUsageType.GENERIC,
|
||||
entityType: "test-entity",
|
||||
entityId: "e1",
|
||||
fieldKey: uniq("field"),
|
||||
...overrides,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user