forked from Chatbot/v3-api
first commit v3 initialiazed a temporary repository for darmanet client
This commit is contained in:
48
src/ai-v2/ai-v2-ask.mapper.spec.ts
Normal file
48
src/ai-v2/ai-v2-ask.mapper.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Sender } from '../common/types/sender.type';
|
||||
import {
|
||||
isEscalationOffered,
|
||||
resolveAskText,
|
||||
resolveSessionId,
|
||||
toAskCompatiblePayload,
|
||||
} from './ai-v2-ask.mapper';
|
||||
|
||||
describe('ai-v2 ask mapper', () => {
|
||||
it('reads question only', () => {
|
||||
expect(resolveAskText({ question: 'الف' })).toBe('الف');
|
||||
expect(resolveAskText({ question: ' ' })).toBe('');
|
||||
});
|
||||
|
||||
it('treats empty sessionId as a new session', () => {
|
||||
expect(resolveSessionId('')).toBeUndefined();
|
||||
expect(resolveSessionId(' ')).toBeUndefined();
|
||||
expect(resolveSessionId('64f1a2b3c4d5e6f7a8b9c0d1')).toBe(
|
||||
'64f1a2b3c4d5e6f7a8b9c0d1',
|
||||
);
|
||||
});
|
||||
|
||||
it('detects escalation_offered', () => {
|
||||
expect(isEscalationOffered({ status: 'escalation_offered' })).toBe(true);
|
||||
expect(isEscalationOffered({ status: 'answered' })).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps our messageId and stores AI runId separately', () => {
|
||||
const payload = toAskCompatiblePayload({
|
||||
session: {
|
||||
_id: '64f1a2b3c4d5e6f7a8b9c0d1',
|
||||
messages: [{ sender: Sender.User }, { sender: Sender.Bot }],
|
||||
},
|
||||
now: Date.now() / 1000,
|
||||
question: 'چقدر پوشش بستری؟',
|
||||
answer: 'با کارشناس تماس بگیرید',
|
||||
messageId: '64f1a2b3c4d5e6f7a8b9c0d2',
|
||||
runId: 'bea53a8d-3745-420f-a50d-fb700de5611d',
|
||||
status: 'escalation_offered',
|
||||
escalation: { summary: 'not in docs', handoff_context: {} },
|
||||
isNewSession: true,
|
||||
});
|
||||
|
||||
expect(payload.messageId).toBe('64f1a2b3c4d5e6f7a8b9c0d2');
|
||||
expect(payload.runId).toBe('bea53a8d-3745-420f-a50d-fb700de5611d');
|
||||
expect(payload.offerOnlineChat).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user