diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index 40bf21a..5ac692f 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -523,20 +523,26 @@ describe('WebhookServer', () => { describe('User validation in handleMessageUpsert', () => { let mockEnsureUserExists: any; let consoleSpy: any; + let originalConsoleLog: any; beforeEach(async () => { mockEnsureUserExists = mock(() => '1234567890'); - // Mock the function in the module - const dbModule = await import('../../src/db'); - dbModule.ensureUserExists = mockEnsureUserExists; - + + // Mock the db module to replace ensureUserExists + mock.module('../../src/db', () => ({ + db: {}, + getDb: () => ({}), + initializeDatabase: () => {}, + ensureUserExists: mockEnsureUserExists + })); + + originalConsoleLog = console.log; consoleSpy = mock(() => {}); console.log = consoleSpy; }); afterEach(() => { - mockEnsureUserExists.mockRestore(); - consoleSpy.mockRestore(); + console.log = originalConsoleLog; }); test('should proceed with valid user', async () => {