Files
makelore/tests/unit/data-service-server-registration.test.ts

36 lines
1.7 KiB
TypeScript

import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
describe('Data Service Host API registration', () => {
it('registers before the existing Works catch-all', async () => {
const source = await readFile(resolve('electron/api/route-handlers.ts'), 'utf8');
expect(source).toMatch(
/import\s+\{\s*handleDataServiceRoutes\s*\}\s+from\s+['"]\.\/routes\/data-service['"]/,
);
const routeList = source.match(/hostApiRouteHandlers[^=]*=\s*\[([\s\S]*?)\];/);
expect(routeList?.[1]).toBeDefined();
const dataServiceIndex = routeList?.[1].indexOf('handleDataServiceRoutes') ?? -1;
const worksIndex = routeList?.[1].indexOf('handleWorksRoutes') ?? -1;
expect(dataServiceIndex).toBeGreaterThanOrEqual(0);
expect(worksIndex).toBeGreaterThan(dataServiceIndex);
expect(source).not.toContain('handleDataServiceRoute = handleDataServiceRoutes');
});
it('registers project plugins in the shared coding dispatcher without replacing typed configuration', async () => {
const source = await readFile(resolve('electron/api/route-handlers.ts'), 'utf8');
expect(source).toMatch(
/import\s+\{\s*handleCodingPluginRoutes\s*\}\s+from\s+['"]\.\/routes\/coding-plugins['"]/,
);
const routeList = source.match(/hostApiRouteHandlers[^=]*=\s*\[([\s\S]*?)\];/);
const routes = routeList?.[1] ?? '';
expect(routes.indexOf('handleCodingPluginRoutes')).toBeGreaterThan(
routes.indexOf('handleCodingProjectRoutes'),
);
expect(routes.indexOf('handleCodingConversationRoutes')).toBeGreaterThan(
routes.indexOf('handleCodingPluginRoutes'),
);
expect(routes.indexOf('handleDataServiceRoutes')).toBeGreaterThanOrEqual(0);
});
});