gapmind/test/ml-gate.test.ts
2026-09-11 23:59:05 -04:00

34 lines
1.1 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { MlGeolocationService } from '../src/services/ml-geolocation.service.js';
const emptyRepo = { find: async () => [], count: async () => 0 } as any;
const features = {
geoliteLatitude: 40.7,
geoliteLongitude: -74,
pennsylvaniaMs: 20,
oregonMs: 80,
};
describe('MlGeolocationService gate', () => {
it('predict is unavailable below 25 samples', async () => {
const ml = new MlGeolocationService(emptyRepo);
const out = (await ml.predict(features)) as any;
assert.equal(out.available, false);
assert.match(out.reason, /25/);
});
it('status reports minimumSamples 25', async () => {
const ml = new MlGeolocationService(emptyRepo);
const status = await ml.status();
assert.equal(status.minimumSamples, 25);
assert.equal(status.ready, false);
});
it('rejects invalid features', async () => {
const ml = new MlGeolocationService(emptyRepo);
await assert.rejects(() =>
ml.predict({ ...features, pennsylvaniaMs: -1 } as any),
);
});
});