jest.mock('../../server/lib/postgres', () => ({ get: jest.fn(), run: jest.fn(), })); const { get, run } = require('../../server/lib/postgres'); const { deleteAccount, signUp } = require('../../server/lib/auth'); describe('server auth account deletion', () => { beforeEach(() => { jest.clearAllMocks(); get.mockResolvedValue(null); run.mockResolvedValue({ lastId: null, changes: 1, rows: [] }); }); it('removes auth and billing rows so the same email can sign up again', async () => { const email = 'same@example.com'; await signUp({}, email, 'First User', 'password-1'); await deleteAccount({}, 'usr_deleted'); await signUp({}, email, 'Second User', 'password-2'); const authDeletes = run.mock.calls.filter(([, sql]) => ( typeof sql === 'string' && sql.includes('DELETE FROM auth_users') )); expect(authDeletes).toHaveLength(1); const billingAccountDeletes = run.mock.calls.filter(([, sql]) => ( typeof sql === 'string' && sql.includes('DELETE FROM billing_accounts') )); expect(billingAccountDeletes).toHaveLength(1); const signupChecks = get.mock.calls.filter(([, sql], params) => ( typeof sql === 'string' && sql.includes('SELECT id FROM auth_users WHERE LOWER(email)') && params?.[0] === email )); expect(signupChecks).toHaveLength(2); }); });