feat(#217): Agenda B3 — filtres from/to + historique

Closes #217

Co-authored-by: Julien Martin <julien.martin@ptits-pas.fr>
This commit was merged in pull request #232.
This commit is contained in:
2026-10-16 14:50:31 +00:00
committed by jmartin
parent af7d1b4da4
commit 6419f4e8d3
3 changed files with 144 additions and 8 deletions
@@ -245,6 +245,96 @@ describe('EvenementsAgendaService (#172)', () => {
expect(res.actions.peut_modifier).toBe(true);
});
describe('lister — #217', () => {
const andWhere = jest.fn().mockReturnThis();
const qb = {
leftJoinAndSelect: jest.fn().mockReturnThis(),
where: jest.fn().mockReturnThis(),
andWhere,
orderBy: jest.fn().mockReturnThis(),
getMany: jest.fn().mockResolvedValue([]),
};
beforeEach(() => {
andWhere.mockClear();
absencesRepo.createQueryBuilder.mockReturnValue(qb);
amChildrenRepo.find.mockResolvedValue([{ id: 'pl-1' }, { id: 'pl-ended' }]);
});
it('from > to → BadRequest', async () => {
await expect(
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
from: '2026-10-31',
to: '2026-10-01',
}),
).rejects.toBeInstanceOf(BadRequestException);
});
it('date invalide (31 nov) → BadRequest', async () => {
await expect(
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
from: '2026-11-31',
to: '2026-12-01',
}),
).rejects.toBeInstanceOf(BadRequestException);
});
it('exclut les annulés par défaut + bornes inclusives', async () => {
await service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
from: '2026-10-01',
to: '2026-10-31',
});
expect(amChildrenRepo.find).toHaveBeenCalledWith(
expect.objectContaining({
where: expect.objectContaining({ amId: 'am-1' }),
}),
);
// pas de date_fin: IsNull() → historique inclus
const whereArg = amChildrenRepo.find.mock.calls[0][0].where;
expect(whereArg.date_fin).toBeUndefined();
expect(andWhere).toHaveBeenCalledWith('ag.statut != :annule', {
annule: StatutEvenementAgendaType.ANNULE,
});
expect(andWhere).toHaveBeenCalledWith('ag.date_fin >= :from', {
from: '2026-10-01',
});
expect(andWhere).toHaveBeenCalledWith('ag.date_debut <= :to', {
to: '2026-10-31',
});
});
it('DST octobre : bornes calendaires acceptées (2026-10-25)', async () => {
// dernier dimanche d’octobre 2026 = 25 oct. — strings YYYY-MM-DD, pas Date UTC
await expect(
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
from: '2026-10-25',
to: '2026-10-26',
}),
).resolves.toEqual({ items: [] });
expect(andWhere).toHaveBeenCalledWith('ag.date_fin >= :from', {
from: '2026-10-25',
});
});
it('année bissextile : 2024-02-29 valide', async () => {
await expect(
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
from: '2024-02-29',
to: '2024-03-01',
}),
).resolves.toEqual({ items: [] });
});
it('2025-02-29 invalide (non bissextile)', async () => {
await expect(
service.lister('am-1', RoleType.ASSISTANTE_MATERNELLE, {
from: '2025-02-29',
to: '2025-03-01',
}),
).rejects.toBeInstanceOf(BadRequestException);
});
});
it('libelle_refus n’expose pas l’auteur — #215', async () => {
absencesRepo.findOne.mockResolvedValue({
id: 'ev-ref',