Skip to content

Commit

Permalink
test(server): fix flaky housing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Falinor committed Oct 9, 2024
1 parent 911c5e9 commit b6e56d2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/src/controllers/housingController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
genDatafoncierOwner,
genEstablishmentApi,
genHousingApi,
genOwnerApi,
genUserApi,
oneOf
} from '~/test/testFixtures';
Expand Down Expand Up @@ -142,13 +143,33 @@ 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<HousingApi>((occupancy) => ({
...genHousingApi(faker.helpers.arrayElement(establishment.geoCodes)),
occupancy
}));
const owner = genOwnerApi();
await Promise.all([
Housing().insert(housings.map(formatHousingRecordApi)),
Owners().insert(formatOwnerApi(owner))
]);
const housingOwners = housings.flatMap((housing) =>
formatHousingOwnersApi(housing, [owner])
);
await HousingOwners().insert(housingOwners);

const { body, status } = await request(app)
.get(testRoute)
.query('sort=-occupancy')
.set('Content-Type', 'application/json')
.use(tokenProvider(user));

expect(status).toBe(constants.HTTP_STATUS_OK);
expect(body.entities.length).toBeGreaterThan(0);
expect(body.entities).toBeSortedBy('occupancy', {
descending: true
});
Expand Down

0 comments on commit b6e56d2

Please sign in to comment.