Skip to content

Commit 77d01aa

Browse files
committed
feat: update database schema tests to use static schema module and remove unused imports
1 parent 3776fd0 commit 77d01aa

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

services/backend/src/db/schema.sqlite.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
// SINGLE SOURCE OF TRUTH FOR DATABASE SCHEMA
23
// This file is the definitive schema definition for the SQLite database.
34
// It is used by:

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { drizzle as drizzleSqliteAdapter } from 'drizzle-orm/better-sqlite3';
77
// Modules to mock
88
import * as configModule from '../../../src/db/config';
99
import * as staticSchemaModule from '../../../src/db/schema.sqlite';
10-
import * as schemaModule from '../../../src/db/schema'; // For inputPluginTableDefinitions
1110

1211
// Functions from the module under test
1312
import {
@@ -100,10 +99,6 @@ vi.mock('../../../src/db/schema.sqlite', () => ({
10099
// e.g., authUser: {}, authSession: {}
101100
// For now, an empty object might suffice if generateSchema doesn't rely on specific props
102101
// from staticSchema for the core tests.
103-
}));
104-
105-
// Mock './schema' for inputPluginTableDefinitions
106-
vi.mock('../../../src/db/schema', () => ({
107102
pluginTableDefinitions: {}, // Start with empty plugin definitions
108103
}));
109104

@@ -207,20 +202,20 @@ describe('Database Service (db/index.ts)', () => {
207202
};
208203

209204
beforeEach(() => {
210-
// Reset pluginTableDefinitions from schemaModule for each test
211-
// schemaModule.pluginTableDefinitions = {}; // This causes a read-only error
205+
// Reset pluginTableDefinitions from staticSchemaModule for each test
206+
// staticSchemaModule.pluginTableDefinitions = {}; // This causes a read-only error
212207
// Instead, clear the properties of the mocked object
213-
const ptd = schemaModule.pluginTableDefinitions as Record<string, any>;
208+
const ptd = staticSchemaModule.pluginTableDefinitions as Record<string, any>;
214209
for (const key in ptd) {
215210
delete ptd[key];
216211
}
217212
});
218213

219214
it('should register table definitions from plugins', () => {
220215
registerPluginTables([plugin1, plugin2]);
221-
expect(schemaModule.pluginTableDefinitions).toHaveProperty('plugin1_myTable');
222-
expect(schemaModule.pluginTableDefinitions['plugin1_myTable']).toEqual(plugin1.databaseExtension?.tableDefinitions?.myTable);
223-
expect(Object.keys(schemaModule.pluginTableDefinitions).length).toBe(1);
216+
expect(staticSchemaModule.pluginTableDefinitions).toHaveProperty('plugin1_myTable');
217+
expect(staticSchemaModule.pluginTableDefinitions['plugin1_myTable']).toEqual(plugin1.databaseExtension?.tableDefinitions?.myTable);
218+
expect(Object.keys(staticSchemaModule.pluginTableDefinitions).length).toBe(1);
224219
});
225220
});
226221
});

0 commit comments

Comments
 (0)