refactor: refactorizar mocks de validación de usuario para aislamiento local

Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <aider@aider.chat>
pull/1/head
borja 2 months ago
parent d898cd2500
commit 536076d8f9

@ -524,24 +524,24 @@ describe('WebhookServer', () => {
let mockEnsureUserExists: any; let mockEnsureUserExists: any;
let consoleSpy: any; let consoleSpy: any;
let originalConsoleLog: any; let originalConsoleLog: any;
let originalEnsureUserExists: any;
beforeEach(async () => { beforeEach(async () => {
// Import the db module dynamically to mock ensureUserExists locally
const dbModule = await import('../../src/db');
originalEnsureUserExists = dbModule.ensureUserExists;
mockEnsureUserExists = mock(() => '1234567890'); mockEnsureUserExists = mock(() => '1234567890');
dbModule.ensureUserExists = mockEnsureUserExists;
// Mock the db module to replace ensureUserExists
mock.module('../../src/db', () => ({
db: {},
getDb: () => ({}),
initializeDatabase: () => {},
ensureUserExists: mockEnsureUserExists
}));
originalConsoleLog = console.log; originalConsoleLog = console.log;
consoleSpy = mock(() => {}); consoleSpy = mock(() => {});
console.log = consoleSpy; console.log = consoleSpy;
}); });
afterEach(() => { afterEach(async () => {
// Restore the original functions manually
const dbModule = await import('../../src/db');
dbModule.ensureUserExists = originalEnsureUserExists;
console.log = originalConsoleLog; console.log = originalConsoleLog;
}); });

Loading…
Cancel
Save