Files
doormilxpress_astryx/tests/lib/skills/HubCongestionSkill.test.js

51 lines
2.3 KiB
JavaScript

import { HubCongestionSkill } from '@/lib/assistant/skills/definitions/HubCongestionSkill';
describe('HubCongestionSkill', () => {
const NOW = '2026-08-31 14:00:00';
it('detects parcels stalled at hub beyond dwell threshold', () => {
const rows = [
{ bookingid: 1, bookingno: 'BK-1', orderstatus: 'pending', orderdate: '2026-08-31 13:00:00' }, // 60 min
{ bookingid: 2, bookingno: 'BK-2', orderstatus: 'accepted', orderdate: '2026-08-31 13:10:00' }, // 50 min
{ bookingid: 3, bookingno: 'BK-3', orderstatus: 'pending', orderdate: '2026-08-31 13:50:00' }, // 10 min — not stalled
{ bookingid: 4, bookingno: 'BK-4', orderstatus: 'picked', orderdate: '2026-08-31 12:00:00' }, // in transit — excluded
];
const findings = HubCongestionSkill.evaluate(rows, NOW, { hubDwellMinutes: 45 });
expect(findings.length).toBe(1);
expect(findings[0].id).toBe('hub_parcel_stalled');
expect(findings[0].count).toBe(2);
expect(findings[0].rows.map((r) => r.bookingid)).toContain(1);
expect(findings[0].rows.map((r) => r.bookingid)).toContain(2);
expect(findings[0].rows.map((r) => r.bookingid)).not.toContain(3);
});
it('returns no findings when all parcels are within dwell threshold', () => {
const rows = [
{ bookingid: 5, orderstatus: 'pending', orderdate: '2026-08-31 13:50:00' }, // 10 min
];
const findings = HubCongestionSkill.evaluate(rows, NOW, { hubDwellMinutes: 45 });
expect(findings.length).toBe(0);
});
it('executes dispatch_hub_idle_parcels tool handler', async () => {
const tool = HubCongestionSkill.tools.find((t) => t.name === 'dispatch_hub_idle_parcels');
expect(tool).toBeDefined();
const result = await tool.handler({ bookingIds: [1, 2], milerId: 99 });
expect(result.success).toBe(true);
expect(result.proposal.action).toBe('dispatch_hub_parcels');
expect(result.proposal.bookingIds).toEqual([1, 2]);
});
it('respects custom dwell threshold', () => {
const rows = [
{ bookingid: 10, orderstatus: 'pending', orderdate: '2026-08-31 13:45:00' }, // 15 min
];
const findingsStrict = HubCongestionSkill.evaluate(rows, NOW, { hubDwellMinutes: 10 });
expect(findingsStrict.length).toBe(1);
const findingsLenient = HubCongestionSkill.evaluate(rows, NOW, { hubDwellMinutes: 30 });
expect(findingsLenient.length).toBe(0);
});
});