Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : tests/unit/regions.test.ts9 * Module : tests10 * Repository : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website : https://jeux.uqo-eval.app12 * Created : 2026-11-2513 * Last Modified : 2026-11-2514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { describe, expect, it } from "vitest";44import { REGIONS, municipalityByCode, municipalityByName, normalizeName, regionCodeFromLabel, regionName } from "../../packages/engine/src/index.ts";4546describe("Régions administratives", () => {47 it("compte les 17 régions du Québec, codes 01 à 17", () => {48 expect(Object.keys(REGIONS).sort()).toEqual(Array.from({ length: 17 }, (_, i) => String(i + 1).padStart(2, "0")));49 expect(REGIONS["07"]).toBe("Outaouais");50 expect(REGIONS["06"]).toBe("Montréal");51 expect(REGIONS["11"]).toBe("Gaspésie–Îles-de-la-Madeleine");52 });53 it("retourne le nom d'une région par son code, et null pour un code inconnu ou absent", () => {54 expect(regionName("16")).toBe("Montérégie");55 expect(regionName("18")).toBeNull();56 expect(regionName("")).toBeNull();57 expect(regionName(null)).toBeNull();58 expect(regionName(undefined)).toBeNull();59 });60});6162describe("regionCodeFromLabel", () => {63 it.each([64 ["Outaouais", "07"], [" outaouais ", "07"], ["Montérégie", "16"], ["MONTEREGIE", "16"], ["Saguenay–Lac-Saint-Jean", "02"],65 ["Saguenay-Lac-St-Jean", "02"], ["Gaspésie–Îles-de-la-Madeleine", "11"], ["Capitale-Nationale", "03"], ["Eastern Townships", "05"],66 ["The Laurentians", "15"], ["Rive-Sud de Montréal", "16"], ["Centre-du-Québec", "17"], ["Côte-Nord", "09"], ["Abitibi-Témiscamingue", "08"],67 ])("reconnaît l'étiquette « %s » → %s", (label, code) => {68 expect(regionCodeFromLabel(label)).toBe(code);69 });70 it("reconnaît le nom officiel de chacune des 17 régions", () => {71 for (const [code, name] of Object.entries(REGIONS)) expect(regionCodeFromLabel(name)).toBe(code);72 });73 it("accepte un code à deux chiffres valide et refuse un code hors plage", () => {74 expect(regionCodeFromLabel("07")).toBe("07");75 expect(regionCodeFromLabel(" 17 ")).toBe("17");76 expect(regionCodeFromLabel("00")).toBeNull();77 expect(regionCodeFromLabel("18")).toBeNull();78 expect(regionCodeFromLabel("99")).toBeNull();79 });80 it("ne devine pas une étiquette inconnue, vide ou absente", () => {81 expect(regionCodeFromLabel("Grand Nord")).toBeNull();82 expect(regionCodeFromLabel("Québec")).toBeNull(); // ville ou province : ambigu83 expect(regionCodeFromLabel("")).toBeNull();84 expect(regionCodeFromLabel(null)).toBeNull();85 expect(regionCodeFromLabel(undefined)).toBeNull();86 });87});8889describe("normalizeName", () => {90 it("retire accents, casse, ponctuation et développe St / Ste", () => {91 expect(normalizeName("Saint-Jérôme")).toBe("saint jerome");92 expect(normalizeName("ST-JEROME")).toBe("saint jerome");93 expect(normalizeName("Ste-Adèle")).toBe("sainte adele");94 expect(normalizeName("L'Ange-Gardien")).toBe("l ange gardien");95 expect(normalizeName("L’Île-Perrot")).toBe("l ile perrot");96 expect(normalizeName(" Val-d'Or ")).toBe("val d or");97 });98 it("ne transforme pas « st » à l'intérieur d'un mot", () => {99 expect(normalizeName("Estrie")).toBe("estrie");100 expect(normalizeName("Stoneham")).toBe("stoneham");101 });102});103104describe("Municipalités", () => {105 it("retrouve une municipalité par son code géographique", () => {106 expect(municipalityByCode("81017")).toMatchObject({ name: "Gatineau", regionCode: "07" });107 expect(municipalityByCode("66023")).toMatchObject({ name: "Montréal", regionCode: "06" });108 expect(municipalityByCode("00000")).toBeNull();109 expect(municipalityByCode(null)).toBeNull();110 });111 it("retrouve une municipalité par son nom, sans égard aux accents, à la casse et aux abréviations", () => {112 expect(municipalityByName("gatineau")).toMatchObject({ code: "81017", regionCode: "07" });113 expect(municipalityByName("ST-JEROME")).toMatchObject({ name: "Saint-Jérôme", regionCode: "15", mrc: "La Rivière-du-Nord" });114 expect(municipalityByName("Sainte-Adele")).toMatchObject({ name: "Sainte-Adèle" });115 expect(municipalityByName("Ville Imaginaire")).toBeNull();116 expect(municipalityByName("")).toBeNull();117 expect(municipalityByName(null)).toBeNull();118 });119 it("ne tranche pas un nom porté par plusieurs municipalités (ambigu → null), mais les retrouve par code", () => {120 // Bedford (ville, 46035) et Bedford (canton, 46040) ; Cacouna (municipalité 12057 et réserve 12804).121 expect(municipalityByName("Bedford")).toBeNull();122 expect(municipalityByName("Cacouna")).toBeNull();123 expect(municipalityByCode("46035")).toMatchObject({ name: "Bedford" });124 expect(municipalityByCode("46040")).toMatchObject({ name: "Bedford" });125 expect(municipalityByCode("12057")).toMatchObject({ name: "Cacouna", regionCode: "01" });126 });127 it("rattache chaque municipalité à une région existante", () => {128 for (const code of ["81017", "66023", "75017", "46035", "12057"]) {129 expect(REGIONS[municipalityByCode(code)!.regionCode]).toBeTypeOf("string");130 }131 });132});133