Skip to content

Commit 06e2152

Browse files
author
Lasim
committed
feat(tests): enhance database service tests with mock logger functionality
1 parent 2b7d3a3 commit 06e2152

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

services/backend/tests/unit/db/index.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ describe('Database Service (db/index.ts)', () => {
201201
// Reset plugin table definitions
202202
const ptd = staticSchemaModule.pluginTableDefinitions as Record<string, any>;
203203
Object.keys(ptd).forEach(key => delete ptd[key]);
204+
205+
// Reset mock logger child method
206+
mockLogger.child.mockReturnValue(mockChildLogger);
204207
});
205208

206209
afterEach(() => {
@@ -220,17 +223,19 @@ describe('Database Service (db/index.ts)', () => {
220223
};
221224

222225
// Create a mock logger for tests
226+
const mockChildLogger = {
227+
info: vi.fn(),
228+
error: vi.fn(),
229+
warn: vi.fn(),
230+
debug: vi.fn(),
231+
};
232+
223233
const mockLogger = {
224234
info: vi.fn(),
225235
error: vi.fn(),
226236
warn: vi.fn(),
227237
debug: vi.fn(),
228-
child: vi.fn().mockReturnValue({
229-
info: vi.fn(),
230-
error: vi.fn(),
231-
warn: vi.fn(),
232-
debug: vi.fn(),
233-
}),
238+
child: vi.fn().mockReturnValue(mockChildLogger),
234239
} as any;
235240

236241
describe('initializeDatabase', () => {
@@ -447,7 +452,8 @@ describe('Database Service (db/index.ts)', () => {
447452

448453
expect(pluginWithDbInit.databaseExtension?.onDatabaseInit).toHaveBeenCalledWith(
449454
mockDb,
450-
expect.any(Object)
455+
expect.any(Object),
456+
mockChildLogger
451457
);
452458
expect(mockLogger.info).toHaveBeenCalledWith(
453459
{ operation: 'initialize_plugin_databases', pluginId: 'dbPlugin' },

0 commit comments

Comments
 (0)