ticketService.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { test } from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import { applyTestConfig } from './helpers/testConfig.js';
  4. import { formatTicketNumber, isTicketMode } from '../src/domain/ticketService.js';
  5. test('ticket numbers use the EKS-YYYYMMDD-<conversationId> format', () => {
  6. applyTestConfig();
  7. const n = formatTicketNumber(1311, new Date(Date.UTC(2026, 7, 20, 9, 0, 0)));
  8. assert.equal(n, 'EKS-20260820-1311');
  9. });
  10. test('the ticket prefix is configurable', () => {
  11. applyTestConfig({ TICKET_NUMBER_PREFIX: 'SUP' });
  12. assert.equal(formatTicketNumber(7, new Date(Date.UTC(2026, 0, 2))), 'SUP-20260102-7');
  13. });
  14. test('the ticket label puts a conversation in manual mode', () => {
  15. applyTestConfig();
  16. assert.equal(isTicketMode({ labels: ['ticket'] }), true);
  17. assert.equal(isTicketMode({ labels: ['vip'] }), false);
  18. });
  19. test('handoff=true puts a conversation in manual mode', () => {
  20. applyTestConfig();
  21. assert.equal(isTicketMode({ custom_attributes: { handoff: true } }), true);
  22. assert.equal(isTicketMode({ custom_attributes: { handoff: 'true' } }), true);
  23. assert.equal(isTicketMode({ custom_attributes: { handoff: false } }), false);
  24. });
  25. test('a real ticket_number puts a conversation in manual mode, "0" does not', () => {
  26. applyTestConfig();
  27. assert.equal(isTicketMode({ custom_attributes: { ticket_number: 'EKS-20260820-1311' } }), true);
  28. assert.equal(isTicketMode({ custom_attributes: { ticket_number: '0' } }), false);
  29. assert.equal(isTicketMode({ custom_attributes: { ticket_number: '' } }), false);
  30. });
  31. test('an empty conversation is not in manual mode', () => {
  32. applyTestConfig();
  33. assert.equal(isTicketMode({}), false);
  34. });