54 lines
2.5 KiB
JavaScript
54 lines
2.5 KiB
JavaScript
import { LateDispatchSkill } from '@/lib/assistant/skills/definitions/LateDispatchSkill';
|
|
|
|
describe('LateDispatchSkill', () => {
|
|
const NOW = '2026-08-31 14:00:00';
|
|
|
|
it('detects critically late dispatch orders', () => {
|
|
const rows = [
|
|
{ bookingid: 1, bookingno: 'BK-1', orderstatus: 'pending', orderdate: '2026-08-31 11:30:00' }, // 150 min
|
|
{ bookingid: 2, bookingno: 'BK-2', orderstatus: 'pending', orderdate: '2026-08-31 12:30:00' }, // 90 min
|
|
{ bookingid: 3, bookingno: 'BK-3', orderstatus: 'pending', orderdate: '2026-08-31 13:20:00' }, // 40 min — warning only
|
|
{ bookingid: 4, bookingno: 'BK-4', orderstatus: 'pending', orderdate: '2026-08-31 13:50:00' }, // 10 min — no issue
|
|
{ bookingid: 5, bookingno: 'BK-5', orderstatus: 'picked', orderdate: '2026-08-31 11:00:00' }, // dispatched — excluded
|
|
];
|
|
|
|
const findings = LateDispatchSkill.evaluate(rows, NOW, { lateDispatchMinutes: 30, criticalDispatchMinutes: 60 });
|
|
|
|
const critical = findings.find((f) => f.id === 'late_dispatch_critical');
|
|
const warning = findings.find((f) => f.id === 'late_dispatch_warning');
|
|
|
|
expect(critical).toBeDefined();
|
|
expect(critical.count).toBe(2); // BK-1 and BK-2
|
|
|
|
expect(warning).toBeDefined();
|
|
expect(warning.count).toBe(1); // BK-3
|
|
});
|
|
|
|
it('returns no findings when all orders are dispatched quickly', () => {
|
|
const rows = [
|
|
{ bookingid: 1, orderstatus: 'pending', orderdate: '2026-08-31 13:55:00' }, // 5 min
|
|
];
|
|
const findings = LateDispatchSkill.evaluate(rows, NOW, { lateDispatchMinutes: 30, criticalDispatchMinutes: 60 });
|
|
expect(findings.length).toBe(0);
|
|
});
|
|
|
|
it('executes trigger_auto_dispatch tool handler', async () => {
|
|
const tool = LateDispatchSkill.tools.find((t) => t.name === 'trigger_auto_dispatch');
|
|
expect(tool).toBeDefined();
|
|
const result = await tool.handler({ bookingIds: [1, 2], reason: 'Test late dispatch' });
|
|
expect(result.success).toBe(true);
|
|
expect(result.proposal.action).toBe('auto_dispatch');
|
|
expect(result.proposal.bookingIds).toEqual([1, 2]);
|
|
});
|
|
|
|
it('excludes non-pending status orders', () => {
|
|
const rows = [
|
|
{ bookingid: 1, orderstatus: 'accepted', orderdate: '2026-08-31 11:00:00' },
|
|
{ bookingid: 2, orderstatus: 'picked', orderdate: '2026-08-31 11:00:00' },
|
|
{ bookingid: 3, orderstatus: 'delivered', orderdate: '2026-08-31 11:00:00' },
|
|
];
|
|
const findings = LateDispatchSkill.evaluate(rows, NOW, { lateDispatchMinutes: 30, criticalDispatchMinutes: 60 });
|
|
expect(findings.length).toBe(0);
|
|
});
|
|
});
|