From 55ec1a75a3280100891c5ada8acaeff0d9555b6d Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Wed, 9 Oct 2024 22:29:31 +0200 Subject: [PATCH] test(server): fix flaky housing test --- server/src/controllers/housingController.test.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server/src/controllers/housingController.test.ts b/server/src/controllers/housingController.test.ts index 277d10d33..5e2131534 100644 --- a/server/src/controllers/housingController.test.ts +++ b/server/src/controllers/housingController.test.ts @@ -143,15 +143,12 @@ describe('Housing API', () => { }); it('should sort housings by occupancy', async () => { - const housings = Object.values(OccupancyKindApi) - // Filter this out to avoid a collation issue with the databases - // that don’t use the fr_FR collation. - // "inconnu" will be before "L", while it should be after it - .filter((occupancy) => occupancy !== OccupancyKindApi.Unknown) - .map((occupancy) => ({ + const housings = Object.values(OccupancyKindApi).map( + (occupancy) => ({ ...genHousingApi(faker.helpers.arrayElement(establishment.geoCodes)), occupancy - })); + }) + ); const owner = genOwnerApi(); await Promise.all([ Housing().insert(housings.map(formatHousingRecordApi)), @@ -171,7 +168,9 @@ describe('Housing API', () => { expect(status).toBe(constants.HTTP_STATUS_OK); expect(body.entities.length).toBeGreaterThan(0); expect(body.entities).toBeSortedBy('occupancy', { - descending: true + descending: true, + compare: (a: string, b: string) => + a.toUpperCase().localeCompare(b.toUpperCase()) }); }); });