mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 23:16:46 +00:00
test(server): seed the plugin specs through the repositories
The plugin service, instance and user settings, OAuth, audit, route profile, host state and request context suites seeded plugin rows, settings fields, actions, tokens and audit entries with raw statements and read them back the same way. They now go through the ORM factories and readers over the suite's own test ORM. Two raw statements stay, marked: the PRAGMA table_info read that proves the actions scope column exists, and the audit insert that reproduces the pre-conversion appendAudit byte for byte for the hash chain parity check. The instance settings suite's stubbed isActive now follows the status the test flips through markActive instead of a synchronous read.
This commit is contained in:
@@ -11,6 +11,7 @@ import { createSnapshotTestDb } from '../../helpers/db-mock';
|
||||
import { resetTestDb } from '../../helpers/test-db';
|
||||
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
|
||||
import { Plugins } from '../../../src/db/entities/Plugins.entity';
|
||||
import { insertRow } from '../../helpers/factories/rows';
|
||||
import type { PluginsRepository } from '../../../src/db/repositories/Plugins.repository';
|
||||
import { declaredProfiles } from '../../../src/nest/plugins/contributions/plugin-route-normalize';
|
||||
|
||||
@@ -25,18 +26,18 @@ beforeAll(async () => {
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
|
||||
function seedPlugin(id: string, capabilities: unknown): void {
|
||||
testDb.prepare('INSERT INTO plugins (id, name, capabilities) VALUES (?, ?, ?)').run(id, id, JSON.stringify(capabilities));
|
||||
async function seedPlugin(id: string, capabilities: unknown): Promise<void> {
|
||||
await insertRow(t, Plugins, { id, name: id, capabilities: JSON.stringify(capabilities) });
|
||||
}
|
||||
|
||||
describe('declaredProfiles', () => {
|
||||
it('RN-001: returns the declared routeProfiles ids, filtered to the safe id pattern', async () => {
|
||||
seedPlugin('roadtrip-plugin', { routeProfiles: [{ id: 'eco' }, { id: 'fast-ev' }, { id: 'BAD ID' }, { id: '' }] });
|
||||
await seedPlugin('roadtrip-plugin', { routeProfiles: [{ id: 'eco' }, { id: 'fast-ev' }, { id: 'BAD ID' }, { id: '' }] });
|
||||
expect(await declaredProfiles(plugins, 'roadtrip-plugin')).toEqual(['eco', 'fast-ev']);
|
||||
});
|
||||
|
||||
it('RN-002: no routeProfiles capability → empty list', async () => {
|
||||
seedPlugin('no-routes', { widget: { slot: 'sidebar' } });
|
||||
await seedPlugin('no-routes', { widget: { slot: 'sidebar' } });
|
||||
expect(await declaredProfiles(plugins, 'no-routes')).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -45,7 +46,7 @@ describe('declaredProfiles', () => {
|
||||
});
|
||||
|
||||
it('RN-004: malformed capabilities JSON → empty list, never throws', async () => {
|
||||
testDb.prepare('INSERT INTO plugins (id, name, capabilities) VALUES (?, ?, ?)').run('bad-json', 'bad-json', 'not json');
|
||||
await insertRow(t, Plugins, { id: 'bad-json', name: 'bad-json', capabilities: 'not json' });
|
||||
expect(await declaredProfiles(plugins, 'bad-json')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user