Symétrique #168 : GET/PUT /assistantes-maternelles/me/couples-garde avec parents[] pour le bandeau enfant|foyer. Colonne id_placement_garde_courant sur assistantes_maternelles. Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
3.2 KiB
TypeScript
98 lines
3.2 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { AssistantesMaternellesController } from './assistantes_maternelles.controller';
|
|
import { AssistantesMaternellesService } from './assistantes_maternelles.service';
|
|
import { AuthService } from '../auth/auth.service';
|
|
import { AuthGuard } from 'src/common/guards/auth.guard';
|
|
import { RolesGuard } from 'src/common/guards/roles.guard';
|
|
|
|
describe('AssistantesMaternellesController', () => {
|
|
let controller: AssistantesMaternellesController;
|
|
const authServiceMock = {
|
|
createAmDossierStaff: jest.fn(),
|
|
};
|
|
const amServiceMock = {
|
|
listerCouplesGarde: jest.fn(),
|
|
definirCoupleGardeCourant: jest.fn(),
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [AssistantesMaternellesController],
|
|
providers: [
|
|
{ provide: AssistantesMaternellesService, useValue: amServiceMock },
|
|
{ provide: AuthService, useValue: authServiceMock },
|
|
],
|
|
})
|
|
.overrideGuard(AuthGuard)
|
|
.useValue({ canActivate: () => true })
|
|
.overrideGuard(RolesGuard)
|
|
.useValue({ canActivate: () => true })
|
|
.compile();
|
|
|
|
controller = module.get<AssistantesMaternellesController>(AssistantesMaternellesController);
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(controller).toBeDefined();
|
|
});
|
|
|
|
it('createDossier delegates to authService.createAmDossierStaff with CGU accepted', async () => {
|
|
authServiceMock.createAmDossierStaff.mockResolvedValue({
|
|
message: 'ok',
|
|
user_id: 'u1',
|
|
statut: 'actif',
|
|
numero_dossier: '2026-000001',
|
|
});
|
|
|
|
const body = {
|
|
email: 'am.staff@test.fr',
|
|
prenom: 'Marie',
|
|
nom: 'TEST',
|
|
telephone: '0689567890',
|
|
consentement_photo: false,
|
|
lieu_naissance_ville: 'Paris',
|
|
lieu_naissance_pays: 'France',
|
|
nir: '285017512345678',
|
|
numero_agrement: 'AGR-TEST-001',
|
|
capacite_accueil: 3,
|
|
places_disponibles: 2,
|
|
};
|
|
|
|
const res = await controller.createDossier(body as any);
|
|
expect(authServiceMock.createAmDossierStaff).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
email: body.email,
|
|
acceptation_cgu: true,
|
|
acceptation_privacy: true,
|
|
}),
|
|
);
|
|
expect(res.numero_dossier).toBe('2026-000001');
|
|
});
|
|
|
|
it('listerCouplesGarde délègue au service (#171)', async () => {
|
|
amServiceMock.listerCouplesGarde.mockResolvedValue({
|
|
couples: [],
|
|
couple_courant_id: null,
|
|
});
|
|
const res = await controller.listerCouplesGarde('am-uuid');
|
|
expect(amServiceMock.listerCouplesGarde).toHaveBeenCalledWith('am-uuid');
|
|
expect(res.couple_courant_id).toBeNull();
|
|
});
|
|
|
|
it('definirCoupleGardeCourant délègue au service (#171)', async () => {
|
|
amServiceMock.definirCoupleGardeCourant.mockResolvedValue({
|
|
couples: [{ id: 'pl-1', courant: true }],
|
|
couple_courant_id: 'pl-1',
|
|
});
|
|
const res = await controller.definirCoupleGardeCourant('am-uuid', {
|
|
couple_id: 'pl-1',
|
|
});
|
|
expect(amServiceMock.definirCoupleGardeCourant).toHaveBeenCalledWith(
|
|
'am-uuid',
|
|
'pl-1',
|
|
);
|
|
expect(res.couple_courant_id).toBe('pl-1');
|
|
});
|
|
});
|