29 lines
807 B
TypeScript
29 lines
807 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { createRequestScopedDb } from "@/db/initDrizzle.js";
|
|
|
|
describe("createRequestScopedDb", () => {
|
|
test("creates a one-connection client from DATABASE_URL", async () => {
|
|
const scoped = createRequestScopedDb({
|
|
DATABASE_URL: "postgres://user:pass@localhost:5432/autumn",
|
|
} as Env);
|
|
|
|
expect(scoped.db).toBeDefined();
|
|
expect(scoped.client.options.max).toBe(1);
|
|
|
|
await scoped.dispose();
|
|
});
|
|
|
|
test("creates a one-connection client for Worker Hyperdrive requests", async () => {
|
|
const scoped = createRequestScopedDb({
|
|
HYPERDRIVE: {
|
|
connectionString: "postgres://user:pass@localhost:5432/autumn",
|
|
},
|
|
} as Env);
|
|
|
|
expect(scoped.db).toBeDefined();
|
|
expect(scoped.client.options.max).toBe(1);
|
|
|
|
await scoped.dispose();
|
|
});
|
|
});
|