/** * The db handle is a lazy Proxy. These tests exist because a proxy that lies * about its prototype breaks drizzle's own runtime type dispatch — and the * failure surfaces deep inside a third-party adapter, nowhere near this file. */ import { config } from 'dotenv'; import { is } from 'drizzle-orm'; import { PgDatabase } from 'drizzle-orm/pg-core'; import { afterAll, describe, expect, it } from 'vitest'; config({ path: '../../.env' }); const { closePool, db } = await import('../src/client'); afterAll(async () => { await closePool(); }); describe('lazy db proxy', () => { it('passes the drizzle is() check that adapters dispatch on', () => { // Auth adapters dispatch on this. If it returns false they silently take a // different code path and fail with an unrelated-looking error. expect(is(db, PgDatabase)).toBe(true); }); it('satisfies instanceof', () => { expect(db instanceof PgDatabase).toBe(true); }); it('exposes the query builders', () => { expect(typeof db.select).toBe('function'); expect(typeof db.insert).toBe('function'); expect(typeof db.transaction).toBe('function'); expect(db.query).toBeDefined(); }); it('reports the relational query namespaces', () => { expect(Object.keys(db.query)).toContain('jobs'); expect(Object.keys(db.query)).toContain('proProfiles'); }); it('supports the in operator', () => { expect('select' in db).toBe(true); expect('definitelyNotAMethod' in db).toBe(false); }); it('returns the same instance across accesses', () => { expect(db.select).toBe(db.select); }); });