upates on the toast and createorder and allthose things

This commit is contained in:
2026-09-25 16:02:57 +05:30
parent 3e7aaf1e25
commit f86e4b853b
16 changed files with 1274 additions and 133 deletions

131
tests/lib/smalltalk.test.js Normal file
View File

@@ -0,0 +1,131 @@
/**
* MileTruth greetings and "what can you do?".
*
* "good afternoon" used to reach the intent router and be answered with
* "I could not answer that from live data". These pin the replacement: a
* greeting back plus the capability list — and, just as important, that real
* questions are NOT swallowed as small talk.
*/
import { answerSmallTalk, splitGreeting, CAPABILITIES } from '@/lib/assistant/smalltalk';
const at = (hour) => new Date(2026, 8, 25, hour, 0, 0);
describe('MileTruth small talk', () => {
describe('greetings', () => {
it('answers "good afternoon" with a greeting and what it can do', () => {
const res = answerSmallTalk('good afternoon', { name: 'Dharaneesh', now: at(14) });
expect(res.kind).toBe('greeting');
expect(res.title).toBe('Good afternoon, Dharaneesh! Here’s what I can do for you.');
expect(res.summary).toMatch(/MileTruth/);
expect(res.capabilities).toBe(CAPABILITIES);
});
it('mirrors the greeting the user chose, whatever the clock says', () => {
expect(answerSmallTalk('Good Morning!!', { now: at(20) }).title).toMatch(/^Good morning!/);
expect(answerSmallTalk('goodevening', { now: at(9) }).title).toMatch(/^Good evening!/);
expect(answerSmallTalk('gm', { now: at(20) }).title).toMatch(/^Good morning!/);
});
it.each([
['hi', 9, 'Good morning'],
['Hello there', 14, 'Good afternoon'],
['hey miletruth', 19, 'Good evening']
])('answers "%s" by the clock', (text, hour, expected) => {
expect(answerSmallTalk(text, { now: at(hour) }).title).toMatch(new RegExp(`^${expected}!`));
});
it('greets without a name when none is known', () => {
expect(answerSmallTalk('hi', { now: at(9) }).title).toBe('Good morning! Here’s what I can do for you.');
});
});
describe('"what can you do?"', () => {
it.each(['what can you do?', 'What is this AI', 'who are you', 'help', 'how do I use this', 'what can I ask'])(
'lists capabilities for "%s"',
(text) => {
const res = answerSmallTalk(text);
expect(res.kind).toBe('capabilities');
expect(res.capabilities.length).toBeGreaterThan(0);
}
);
// Real wordings. The first one is the message that got "Sorry, I didn't
// understand" when this matched exact sentences only.
it.each([
'what are things you can do ?',
'what are the things you can do',
'What all can you do?',
'what things do you do',
'what else can u help with',
'what kind of things can you help me with',
'can you help me',
'can u do anything',
'what can I ask you?',
'what should i ask',
'tell me your features',
'show me what you can do',
'list your capabilities',
'what is your job',
'what are you good at',
'what is this',
'what is miletruth',
'how does this work?',
'how to use this',
'features',
'menu',
"what's up"
])('lists capabilities for "%s"', (text) => {
expect(answerSmallTalk(text)?.kind).toBe('capabilities');
});
it('handles a greeting and the question together', () => {
const res = answerSmallTalk('good afternoon, what can you do?', { now: at(14) });
expect(res.kind).toBe('capabilities');
expect(res.title).toMatch(/^Good afternoon!/);
});
});
describe('real questions are left alone', () => {
it.each([
'How many orders today?',
'help me assign a rider to DM-BK-12',
'create a new order',
'Which orders are delayed?',
'what can you tell me about orders today',
'what is the status of DM-BK-0D915D43-33705',
'how many riders are active',
'show me revenue this week',
'which hub is busiest',
'what is pending',
'how do i assign a rider',
'can you show vehicles available'
])(
'returns null for "%s"',
(text) => {
expect(answerSmallTalk(text)).toBeNull();
}
);
it('strips a greeting in front of a real question and passes the question through', () => {
const res = answerSmallTalk('hi, how many orders today?');
expect(res).toEqual({ kind: 'passthrough', greeting: expect.any(String), rest: 'how many orders today?' });
});
it('does not read a word that merely starts like a greeting as one', () => {
expect(splitGreeting('history of orders').greeting).toBeNull();
expect(splitGreeting('highest revenue client').greeting).toBeNull();
});
});
it('answers thanks briefly, without the whole list', () => {
const res = answerSmallTalk('thank you');
expect(res.kind).toBe('thanks');
expect(res.capabilities).toBeUndefined();
});
it('only offers examples the home page actually handles', () => {
const examples = CAPABILITIES.flatMap((g) => g.examples);
expect(examples).toEqual(expect.arrayContaining(['Create a new order', 'Create a new customer', 'How many orders today?']));
expect(examples.every((e) => typeof e === 'string' && e.length > 3)).toBe(true);
});
});