agent-intent.e2e-spec.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Test, TestingModule } from '@nestjs/testing';
  2. import { INestApplication } from '@nestjs/common';
  3. import request from 'supertest';
  4. import { AppModule } from '../src/app.module';
  5. // Mocks to avoid actual OpenAI/Mongo calls if possible, or use real ones if we want integration tests.
  6. // For "testing if states are handled", we ideally want to check the response.
  7. // However, since we are using real LLMs, we might want to mock the FFBLangChainService OR
  8. // just run it against the real API if the user has keys set up (which they do).
  9. // Let's assume we run against the real app for "integration" style checking of the router.
  10. describe('Agentic Intent Router (E2E)', () => {
  11. let app: INestApplication;
  12. beforeAll(async () => {
  13. const moduleFixture: TestingModule = await Test.createTestingModule({
  14. imports: [AppModule],
  15. }).compile();
  16. app = moduleFixture.createNestApplication();
  17. await app.init();
  18. });
  19. // 1. General Intent
  20. it('/POST chat (General Intent)', async () => {
  21. const response = await request(app.getHttpServer())
  22. .post('/api/ffb-production/chat')
  23. .send({ message: 'Hi, who are you?' })
  24. .expect(201);
  25. console.log('General Response:', response.text);
  26. // Expect a helpful response, not a database query result
  27. expect(response.text).toBeTruthy();
  28. });
  29. // 2. Clarification Intent (Site mentioned but ambiguous)
  30. it('/POST chat (Clarification Intent)', async () => {
  31. const response = await request(app.getHttpServer())
  32. .post('/api/ffb-production/chat')
  33. .send({ message: 'Tell me about Site A' })
  34. .expect(201);
  35. console.log('Clarify Response:', response.text);
  36. // Should imply a question back to the user
  37. expect(response.text.includes('?')).toBeTruthy();
  38. });
  39. // 3. Semantic Search Intent
  40. it('/POST chat (Semantic Search Intent)', async () => {
  41. const response = await request(app.getHttpServer())
  42. .post('/api/ffb-production/chat')
  43. .send({ message: 'Find records about high production at Site A' })
  44. .expect(201);
  45. console.log('Semantic Response:', response.text);
  46. // Should typically return search results or say "Found..."
  47. // Hard to assert exact text, but checking for success code 201 implies it didn't crash.
  48. expect(response.text).toBeTruthy();
  49. });
  50. // 4. Aggregation Intent (Quantitative)
  51. it('/POST chat (Aggregate Intent)', async () => {
  52. const response = await request(app.getHttpServer())
  53. .post('/api/ffb-production/chat')
  54. .send({ message: 'What is the total production quantity for Site A?' })
  55. .expect(201);
  56. console.log('Aggregate Response:', response.text);
  57. // Should mention a number or total
  58. expect(response.text).toBeTruthy();
  59. });
  60. afterAll(async () => {
  61. await app.close();
  62. });
  63. });