34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { execFileSync } from "node:child_process";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { resolveTestDatabaseUrl } from "../../prisma/database-safety";
|
|
|
|
const databaseUrl = resolveTestDatabaseUrl();
|
|
const prisma = new PrismaClient({ datasources: { db: { url: databaseUrl } } });
|
|
|
|
describe("seed", () => {
|
|
beforeAll(async () => {
|
|
await prisma.$connect();
|
|
await prisma.$executeRawUnsafe(`TRUNCATE TABLE "accounts" CASCADE`);
|
|
});
|
|
afterAll(async () => prisma.$disconnect());
|
|
|
|
it("is idempotent and leaves exact fixture counts", async () => {
|
|
const runSeed = () =>
|
|
execFileSync("corepack", ["pnpm", "prisma:seed"], {
|
|
cwd: process.cwd(),
|
|
env: { ...process.env, DATABASE_URL: databaseUrl },
|
|
encoding: "utf8",
|
|
});
|
|
expect(runSeed()).toContain("Seed complete");
|
|
expect(runSeed()).toContain("Seed complete");
|
|
await expect(
|
|
Promise.all([
|
|
prisma.account.count(),
|
|
prisma.anonymousProfile.count(),
|
|
prisma.bottle.count({ where: { poolStatus: "IN_POOL" } }),
|
|
]),
|
|
).resolves.toEqual([3, 3, 1]);
|
|
}, 30_000);
|
|
});
|