flowiseClient.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { test } from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import { normaliseFlowiseResponse } from '../src/clients/flowiseClient.js';
  4. test('reads the `text` field', () => {
  5. const r = normaliseFlowiseResponse({ text: 'Cześć!' }, '{"text":"Cześć!"}');
  6. assert.equal(r.type, 'reply');
  7. assert.equal(r.text, 'Cześć!');
  8. });
  9. test('falls back to `response` and `answer`', () => {
  10. assert.equal(normaliseFlowiseResponse({ response: 'A' }, '').text, 'A');
  11. assert.equal(normaliseFlowiseResponse({ answer: 'B' }, '').text, 'B');
  12. });
  13. test('a handoff action wins over the plain reply path', () => {
  14. const r = normaliseFlowiseResponse(
  15. { text: 'Przekazuję do supportu', actions: [{ type: 'handoff' }] },
  16. '',
  17. );
  18. assert.equal(r.type, 'handoff');
  19. assert.equal(r.text, 'Przekazuję do supportu');
  20. });
  21. test('non-handoff actions stay a normal reply', () => {
  22. const r = normaliseFlowiseResponse({ text: 'ok', actions: [{ type: 'log' }] }, '');
  23. assert.equal(r.type, 'reply');
  24. assert.equal(r.actions?.length, 1);
  25. });
  26. test('a plain-text body is the answer', () => {
  27. const r = normaliseFlowiseResponse(null, 'Dzień dobry, oto odpowiedź.');
  28. assert.equal(r.type, 'reply');
  29. assert.equal(r.text, 'Dzień dobry, oto odpowiedź.');
  30. });
  31. test('an empty response is reported as unknown', () => {
  32. assert.equal(normaliseFlowiseResponse(null, '').type, 'unknown');
  33. assert.equal(normaliseFlowiseResponse({}, '{}').type, 'unknown');
  34. assert.equal(normaliseFlowiseResponse({ text: ' ' }, '').type, 'unknown');
  35. });