| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import { Test, TestingModule } from '@nestjs/testing';
- import { INestApplication } from '@nestjs/common';
- import request from 'supertest';
- import { AppModule } from '../src/app.module';
- // Mocks to avoid actual OpenAI/Mongo calls if possible, or use real ones if we want integration tests.
- // For "testing if states are handled", we ideally want to check the response.
- // However, since we are using real LLMs, we might want to mock the FFBLangChainService OR
- // just run it against the real API if the user has keys set up (which they do).
- // Let's assume we run against the real app for "integration" style checking of the router.
- describe('Agentic Intent Router (E2E)', () => {
- let app: INestApplication;
- beforeAll(async () => {
- const moduleFixture: TestingModule = await Test.createTestingModule({
- imports: [AppModule],
- }).compile();
- app = moduleFixture.createNestApplication();
- await app.init();
- });
- // 1. General Intent
- it('/POST chat (General Intent)', async () => {
- const response = await request(app.getHttpServer())
- .post('/api/ffb-production/chat')
- .send({ message: 'Hi, who are you?' })
- .expect(201);
- console.log('General Response:', response.text);
- // Expect a helpful response, not a database query result
- expect(response.text).toBeTruthy();
- });
- // 2. Clarification Intent (Site mentioned but ambiguous)
- it('/POST chat (Clarification Intent)', async () => {
- const response = await request(app.getHttpServer())
- .post('/api/ffb-production/chat')
- .send({ message: 'Tell me about Site A' })
- .expect(201);
- console.log('Clarify Response:', response.text);
- // Should imply a question back to the user
- expect(response.text.includes('?')).toBeTruthy();
- });
- // 3. Semantic Search Intent
- it('/POST chat (Semantic Search Intent)', async () => {
- const response = await request(app.getHttpServer())
- .post('/api/ffb-production/chat')
- .send({ message: 'Find records about high production at Site A' })
- .expect(201);
- console.log('Semantic Response:', response.text);
- // Should typically return search results or say "Found..."
- // Hard to assert exact text, but checking for success code 201 implies it didn't crash.
- expect(response.text).toBeTruthy();
- });
- // 4. Aggregation Intent (Quantitative)
- it('/POST chat (Aggregate Intent)', async () => {
- const response = await request(app.getHttpServer())
- .post('/api/ffb-production/chat')
- .send({ message: 'What is the total production quantity for Site A?' })
- .expect(201);
- console.log('Aggregate Response:', response.text);
- // Should mention a number or total
- expect(response.text).toBeTruthy();
- });
- afterAll(async () => {
- await app.close();
- });
- });
|