confirmObjective() now chains Agent 2 (mapping) then starts Agent 3 (level) synchronously after Agent 1 confirms - by the time the HTTP response returns, session.status is already "level_assessment" and the response carries Agent 3's first question in a new "nextPrompt" field, to be spoken aloud (never displayed as text). New endpoints: POST /sessions/:id/level/confirm (runs Agent 4, advances to "planning") and POST /sessions/:id/level/dispute. routeIncomingMessage dispatches "level_assessment" sessions to LevelAgent.converse(), same single entry point used for text and voice. RouteMessageResponseDto gains levelDone/levelProfile fields: every response field is a structured, typed signal the frontend's main process can branch on to decide whether to open a result window - never an instruction embedded in the LLM's reply text. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
104 lines
3.4 KiB
TypeScript
104 lines
3.4 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import type { AuthenticatedRequest } from '../auth/jwt-auth.guard';
|
|
import { SessionsController } from './sessions.controller';
|
|
import { SessionsService } from './sessions.service';
|
|
|
|
describe('SessionsController', () => {
|
|
let controller: SessionsController;
|
|
const sessionsService = {
|
|
create: jest.fn(),
|
|
findOne: jest.fn(),
|
|
sendObjectiveMessage: jest.fn(),
|
|
confirmObjective: jest.fn(),
|
|
confirmLevel: jest.fn(),
|
|
disputeLevel: jest.fn(),
|
|
routeIncomingMessage: jest.fn(),
|
|
};
|
|
const request = {
|
|
user: { sub: 7, email: 'w@example.com' },
|
|
} as AuthenticatedRequest;
|
|
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks();
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [SessionsController],
|
|
providers: [{ provide: SessionsService, useValue: sessionsService }],
|
|
})
|
|
.overrideGuard(JwtAuthGuard)
|
|
.useValue({ canActivate: () => true })
|
|
.compile();
|
|
|
|
controller = module.get(SessionsController);
|
|
});
|
|
|
|
it('should create a session for the authenticated user', async () => {
|
|
sessionsService.create.mockResolvedValueOnce({
|
|
id: 1,
|
|
status: 'objective_discovery',
|
|
});
|
|
const result = await controller.create(request);
|
|
expect(sessionsService.create).toHaveBeenCalledWith(7);
|
|
expect(result.id).toBe(1);
|
|
});
|
|
|
|
it('should fetch a session by id for the authenticated user', async () => {
|
|
sessionsService.findOne.mockResolvedValueOnce({
|
|
id: 1,
|
|
status: 'objective_discovery',
|
|
});
|
|
await controller.findOne(1, request);
|
|
expect(sessionsService.findOne).toHaveBeenCalledWith(1, 7);
|
|
});
|
|
|
|
it('should forward an objective message to the service', async () => {
|
|
sessionsService.sendObjectiveMessage.mockResolvedValueOnce({
|
|
reply: 'ok',
|
|
ready: false,
|
|
});
|
|
await controller.sendObjectiveMessage(1, { message: 'Bonjour' }, request);
|
|
expect(sessionsService.sendObjectiveMessage).toHaveBeenCalledWith(
|
|
1,
|
|
7,
|
|
'Bonjour',
|
|
);
|
|
});
|
|
|
|
it('should confirm the objective for the authenticated user', async () => {
|
|
sessionsService.confirmObjective.mockResolvedValueOnce({ id: 1 });
|
|
await controller.confirmObjective(1, request);
|
|
expect(sessionsService.confirmObjective).toHaveBeenCalledWith(1, 7);
|
|
});
|
|
|
|
it('should confirm the level profile for the authenticated user', async () => {
|
|
sessionsService.confirmLevel.mockResolvedValueOnce(undefined);
|
|
await controller.confirmLevel(1, request);
|
|
expect(sessionsService.confirmLevel).toHaveBeenCalledWith(1, 7);
|
|
});
|
|
|
|
it('should forward a level dispute to the service', async () => {
|
|
sessionsService.disputeLevel.mockResolvedValueOnce({ id: 2 });
|
|
await controller.disputeLevel(
|
|
1,
|
|
{ concept: 'TVA', answer: 'Ma reponse' },
|
|
request,
|
|
);
|
|
expect(sessionsService.disputeLevel).toHaveBeenCalledWith(1, 7, {
|
|
concept: 'TVA',
|
|
answer: 'Ma reponse',
|
|
});
|
|
});
|
|
|
|
it('should route an incoming message for the authenticated user', async () => {
|
|
sessionsService.routeIncomingMessage.mockResolvedValueOnce({
|
|
type: 'chat',
|
|
reply: 'ok',
|
|
});
|
|
await controller.routeMessage({ message: 'Salut' }, request);
|
|
expect(sessionsService.routeIncomingMessage).toHaveBeenCalledWith(
|
|
7,
|
|
'Salut',
|
|
);
|
|
});
|
|
});
|