T-10: tests

This commit is contained in:
Studio 2026-11-27 11:48:35 -05:00
parent e9659f4dfb
commit 55629edb13

View file

@ -4,7 +4,9 @@ import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'bun:test';
import { Hono } from 'hono';
import type { IServiceContainer } from '@stock-bot/handlers';
import { ExchangesHandler } from '../../apps/stock/data-pipeline/src/handlers/exchanges/exchanges.handler';
import { createPipelineRoutes } from '../../apps/stock/web-api/src/routes/pipeline.routes';
import { PipelineService } from '../../apps/stock/web-api/src/services/pipeline.service';
const repository = fileURLToPath(new URL('../../', import.meta.url));
@ -77,3 +79,64 @@ describe('legacy sync-ib-exchanges removal', () => {
]);
});
});
describe('exchanges handler after sync-ib-exchanges removal', () => {
it('registers exactly the remaining exchange operations and no IB operation', () => {
const metadata = ExchangesHandler.extractMetadata();
expect(metadata?.name).toBe('exchanges');
// @Operation + @ScheduledOperation on one method registers the name twice, so compare the set.
expect([...new Set(metadata?.operations ?? [])].sort()).toEqual([
'clear-postgresql-data',
'get-exchange-stats',
'get-provider-mapping-stats',
'sync-all-exchanges',
'sync-qm-exchanges',
'sync-qm-provider-mappings',
]);
});
it('keeps the other nightly schedules but drops the 03:00 IB exchange schedule', () => {
const metadata = ExchangesHandler.extractMetadata();
const schedules = (metadata?.scheduledJobs ?? [])
.map(job => ({ operation: job.operation, cronPattern: job.cronPattern }))
.sort((a, b) => a.operation.localeCompare(b.operation));
expect(schedules).toEqual([
{ operation: 'sync-all-exchanges', cronPattern: '0 0 * * 0' },
{ operation: 'sync-qm-exchanges', cronPattern: '0 1 * * *' },
{ operation: 'sync-qm-provider-mappings', cronPattern: '0 3 * * *' },
]);
});
it('rejects a leftover queued sync-ib-exchanges job without touching MongoDB', async () => {
const mongoCalls: string[] = [];
const mongodb = new Proxy(
{},
{
get(_target, property) {
mongoCalls.push(String(property));
return () => {
throw new Error('MongoDB must not be used');
};
},
}
);
const handler = new ExchangesHandler({ mongodb } as unknown as IServiceContainer);
await expect(
handler.execute('sync-ib-exchanges', {}, { type: 'queue', metadata: {} } as never)
).rejects.toThrow('Unknown operation: sync-ib-exchanges');
expect(mongoCalls).toEqual([]);
});
});
describe('web-api pipeline service after sync-ib-exchanges removal', () => {
it('no longer exposes a method that enqueues sync-ib-exchanges', () => {
const service = new PipelineService({} as IServiceContainer);
expect('syncIBExchanges' in service).toBe(false);
expect(typeof service.syncQMProviderMappings).toBe('function');
});
});