fix: 完善权威数据约束与测试隔离
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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([2, 2, 1]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user