feat: Enhance logging and type safety across various components and services
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
Some checks failed
Deploy to Test Environment / deploy-to-test (push) Has been cancelled
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
// --- END FIX REGISTRY ---
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { PoolClient } from 'pg';
|
||||
import { withTransaction } from './connection.db';
|
||||
|
||||
// Mock the logger to prevent stderr noise during tests
|
||||
vi.mock('../logger.server', () => ({
|
||||
@@ -24,11 +23,12 @@ import { logger as mockLogger } from '../logger.server';
|
||||
// Un-mock the module we are testing to ensure we use the real implementation.
|
||||
vi.unmock('./user.db');
|
||||
|
||||
// Mock the withTransaction helper since we are testing a function that uses it.
|
||||
// Mock the withTransaction helper. This is the key fix.
|
||||
vi.mock('./connection.db', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('./connection.db')>();
|
||||
return { ...actual, withTransaction: vi.fn() };
|
||||
});
|
||||
import { withTransaction } from './connection.db';
|
||||
import { UserRepository, exportUserData } from './user.db';
|
||||
|
||||
import { mockPoolInstance } from '../../tests/setup/tests-setup-unit';
|
||||
@@ -61,8 +61,7 @@ describe('User DB Service', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
userRepo = new UserRepository(mockPoolInstance as any);
|
||||
// Reset the withTransaction mock before each test
|
||||
const { withTransaction } = require('./connection.db'); // eslint-disable-line @typescript-eslint/no-var-requires
|
||||
// Provide a default mock implementation for withTransaction for all tests.
|
||||
vi.mocked(withTransaction).mockImplementation(async (callback: (client: PoolClient) => Promise<any>) => callback(mockPoolInstance as any));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user