From 536076d8f924c07b26216c825692be31c4275cea Mon Sep 17 00:00:00 2001 From: borja Date: Fri, 5 Sep 2025 11:53:52 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20refactorizar=20mocks=20de=20validac?= =?UTF-8?q?i=C3=B3n=20de=20usuario=20para=20aislamiento=20local?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) --- tests/unit/server.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index 5ac692f..f5543e5 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -524,24 +524,24 @@ describe('WebhookServer', () => { let mockEnsureUserExists: any; let consoleSpy: any; let originalConsoleLog: any; + let originalEnsureUserExists: any; beforeEach(async () => { + // Import the db module dynamically to mock ensureUserExists locally + const dbModule = await import('../../src/db'); + originalEnsureUserExists = dbModule.ensureUserExists; mockEnsureUserExists = mock(() => '1234567890'); - - // Mock the db module to replace ensureUserExists - mock.module('../../src/db', () => ({ - db: {}, - getDb: () => ({}), - initializeDatabase: () => {}, - ensureUserExists: mockEnsureUserExists - })); + dbModule.ensureUserExists = mockEnsureUserExists; originalConsoleLog = console.log; consoleSpy = mock(() => {}); console.log = consoleSpy; }); - afterEach(() => { + afterEach(async () => { + // Restore the original functions manually + const dbModule = await import('../../src/db'); + dbModule.ensureUserExists = originalEnsureUserExists; console.log = originalConsoleLog; });