Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Make the one-connection test use its pool for every read
Claude7da67a62aa6a
diff --git a/src/lib/db/connection.ts b/src/lib/db/connection.tsindex ace5aff..d2f29ba 100644--- a/src/lib/db/connection.ts+++ b/src/lib/db/connection.ts@@ -65,6 +65,19 @@ export function getDb(): Pool {return pool;}+/**+ * Makes getDb() return this pool from now on, for tests that need the code+ * under test to use a pool of their own. Returns the pool it replaces.+ */+export function replaceDbPoolForTests(pool: Pool): Pool | null {+ const replaced = cachedPool;++ cachedPool = pool;+ globalThis.__signudocPgPool = pool;++ return replaced;+}+export async function withTransaction<T>(run: (client: PoolClient) => Promise<T>,pool: Pool = getDb(),diff --git a/src/lib/provider-signing.dbtest.ts b/src/lib/provider-signing.dbtest.tsindex fddd234..6861bad 100644--- a/src/lib/provider-signing.dbtest.ts+++ b/src/lib/provider-signing.dbtest.ts@@ -10,6 +10,7 @@ import { promisify } from "node:util";import { PDFDocument, StandardFonts } from "pdf-lib";import pg from "pg";+import { replaceDbPoolForTests } from "./db/connection.ts";import { openTestDatabase } from "./db/test-database.ts";import { ELECTRONIC_RECORDS_DISCLOSURE_VERSION } from "./electronic-records-disclosure.ts";import {@@ -853,8 +854,9 @@ test("the last signature needs no second connection while it holds the envelope"max: 1,});const draft = await createDraft();-- globalThis.__signudocPgPool = single;+ // What the code reads without being handed a pool (the install's name,+ // the seal key) comes from this one too.+ const replaced = replaceDbPoolForTests(single);try {await send(draft, "simple");@@ -882,7 +884,7 @@ test("the last signature needs no second connection while it holds the envelope"assert.equal(finished.rows[0]!.status, "completed");} finally {- globalThis.__signudocPgPool = database;+ replaceDbPoolForTests(replaced ?? database);await single.end();}});