Skip to content

Commit e6b2b17

Browse files
test(worker): cover delegated endpoint operations after init (#370)
Added comprehensive testing for previously uncovered `createWorkerEndpoint` delegated methods in `src/core/sqlite-db.ts` to ensure full reliability of the worker IPC interface. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 6511313 commit e6b2b17

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/unit/worker_endpoint.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,55 @@ describe('Worker Endpoint', () => {
112112
const hasTestTable = schema.tables.some(t => t.identifier === 'test_table');
113113
assert.strictEqual(hasTestTable, false);
114114
});
115+
116+
it('should delegate remaining operations after database is initialized', async () => {
117+
await endpoint.initializeDatabase('test.db', {
118+
content: null,
119+
maxSize: 0,
120+
readOnlyMode: false,
121+
wasmBinary
122+
});
123+
124+
await endpoint.createTable('users', [
125+
{ name: 'id', type: 'INTEGER', primaryKey: true, notNull: false },
126+
{ name: 'name', type: 'TEXT', primaryKey: false, notNull: false }
127+
]);
128+
129+
await endpoint.insertRowBatch('users', [
130+
{ id: 1, name: 'Alice' },
131+
{ id: 2, name: 'Bob' }
132+
]);
133+
134+
await endpoint.updateCellBatch('users', [
135+
{ rowId: 1, column: 'name', value: 'Alice Smith' },
136+
{ rowId: 2, column: 'name', value: 'Bob Jones' }
137+
]);
138+
139+
await endpoint.updateCell('users', 1, 'name', 'Alice S.');
140+
141+
await endpoint.addColumn('users', 'age', 'INTEGER', '30');
142+
143+
const tableData = await endpoint.fetchTableData('users', { offset: 0, limit: 10 });
144+
assert.deepStrictEqual(tableData.rows, [
145+
[1, 'Alice S.', 30],
146+
[2, 'Bob Jones', 30]
147+
]);
148+
149+
await endpoint.setPragma('journal_mode', 'WAL');
150+
const pragmas = await endpoint.getPragmas();
151+
assert.ok(pragmas.journal_mode !== undefined);
152+
153+
await endpoint.deleteColumns('users', ['age']);
154+
const info = await endpoint.getTableInfo('users');
155+
assert.strictEqual(info.length, 2);
156+
157+
const dependentIndexes = await endpoint.findDependentIndexes('users', ['name']);
158+
assert.deepStrictEqual(dependentIndexes, []);
159+
160+
await endpoint.deleteRows('users', [1]);
161+
const count = await endpoint.fetchTableCount('users', {});
162+
assert.strictEqual(count, 1);
163+
164+
await endpoint.writeToFile('/tmp/test_dump.db');
165+
});
115166
});

0 commit comments

Comments
 (0)