63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
createAuditEvent,
|
|
createStoredIdempotencyResponse,
|
|
databaseBoundary,
|
|
getDatabaseBoundary,
|
|
PRISMA_GENERATED_CLIENT_PATH,
|
|
PRISMA_MIGRATIONS_PATH,
|
|
PRISMA_SCHEMA_PATH,
|
|
prismaOwnershipMetadata,
|
|
} from ".";
|
|
|
|
describe("@hivegrid/db boundary metadata", () => {
|
|
it("documents the current Prisma ownership boundary", () => {
|
|
expect(getDatabaseBoundary()).toBe(databaseBoundary);
|
|
expect(databaseBoundary).toMatchObject({
|
|
packageName: "@hivegrid/db",
|
|
orm: "prisma",
|
|
schemaPath: PRISMA_SCHEMA_PATH,
|
|
migrationsPath: PRISMA_MIGRATIONS_PATH,
|
|
generatedClientPath: PRISMA_GENERATED_CLIENT_PATH,
|
|
serverClientEntrypoint: "@hivegrid/db/client.server",
|
|
});
|
|
});
|
|
|
|
it("is immutable at runtime", () => {
|
|
expect(Object.isFrozen(databaseBoundary)).toBe(true);
|
|
expect(Object.isFrozen(prismaOwnershipMetadata)).toBe(true);
|
|
});
|
|
|
|
it("keeps the root Prisma config aligned with package metadata", async () => {
|
|
process.env.DATABASE_URL ??= "postgresql://test:test@localhost:5432/test";
|
|
const { default: prismaConfig } = await import("../../../prisma.config");
|
|
|
|
expect(prismaConfig.schema).toBe(prismaOwnershipMetadata.schemaPath);
|
|
expect(prismaConfig.migrations?.path).toBe(
|
|
prismaOwnershipMetadata.migrationsPath,
|
|
);
|
|
expect(prismaConfig.migrations?.seed).toBe(
|
|
prismaOwnershipMetadata.seedCommand,
|
|
);
|
|
expect(PRISMA_GENERATED_CLIENT_PATH).toBe(
|
|
prismaOwnershipMetadata.generatedClientPath,
|
|
);
|
|
});
|
|
|
|
it("exposes the audit + idempotency boundary from the package root", () => {
|
|
expect(createAuditEvent).toEqual(expect.any(Function));
|
|
expect(createStoredIdempotencyResponse).toEqual(expect.any(Function));
|
|
});
|
|
|
|
it("exposes audit and idempotency boundary subpath exports", async () => {
|
|
const auditBoundary = await import("@hivegrid/db/audit-events.server");
|
|
const idempotencyBoundary = await import("@hivegrid/db/idempotency-keys.server");
|
|
|
|
expect(auditBoundary.createAuditEvent).toBe(createAuditEvent);
|
|
expect(idempotencyBoundary.createStoredIdempotencyResponse).toBe(
|
|
createStoredIdempotencyResponse,
|
|
);
|
|
});
|
|
});
|