| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { test } from 'node:test';
- import assert from 'node:assert/strict';
- import { normaliseFlowiseResponse } from '../src/clients/flowiseClient.js';
- test('reads the `text` field', () => {
- const r = normaliseFlowiseResponse({ text: 'Cześć!' }, '{"text":"Cześć!"}');
- assert.equal(r.type, 'reply');
- assert.equal(r.text, 'Cześć!');
- });
- test('falls back to `response` and `answer`', () => {
- assert.equal(normaliseFlowiseResponse({ response: 'A' }, '').text, 'A');
- assert.equal(normaliseFlowiseResponse({ answer: 'B' }, '').text, 'B');
- });
- test('a handoff action wins over the plain reply path', () => {
- const r = normaliseFlowiseResponse(
- { text: 'Przekazuję do supportu', actions: [{ type: 'handoff' }] },
- '',
- );
- assert.equal(r.type, 'handoff');
- assert.equal(r.text, 'Przekazuję do supportu');
- });
- test('non-handoff actions stay a normal reply', () => {
- const r = normaliseFlowiseResponse({ text: 'ok', actions: [{ type: 'log' }] }, '');
- assert.equal(r.type, 'reply');
- assert.equal(r.actions?.length, 1);
- });
- test('a plain-text body is the answer', () => {
- const r = normaliseFlowiseResponse(null, 'Dzień dobry, oto odpowiedź.');
- assert.equal(r.type, 'reply');
- assert.equal(r.text, 'Dzień dobry, oto odpowiedź.');
- });
- test('an empty response is reported as unknown', () => {
- assert.equal(normaliseFlowiseResponse(null, '').type, 'unknown');
- assert.equal(normaliseFlowiseResponse({}, '{}').type, 'unknown');
- assert.equal(normaliseFlowiseResponse({ text: ' ' }, '').type, 'unknown');
- });
|