SPB Git

Repository Public

exports.spec.ts 6.4 KB 99 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | ACADEMIC RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * PROJECT METADATA8 * -----------------------------------------------------------------------------9 * Project          : UQO Éval10 * File             : e2e/exports.spec.ts11 * Module           : e2e12 * Repository       : https://git.spboucher.ai/uqo-eval13 * Project Website  : https://www.uqo-eval.app14 * Created          : 2026-10-2815 * Last Modified    : 2026-10-2816 *17 * =============================================================================18 * SOFTWARE MAINTAINER & AFFILIATION19 * =============================================================================20 *21 * Maintainer       : Simon-Pierre Boucher22 * Position         : Professor of Finance23 * Institution      : Université du Québec en Outaouais (UQO)24 * Department       : Département des sciences administratives25 * Website          : https://spboucher.ai26 * Git              : https://git.spboucher.ai27 *28 * Research Contact : research@spboucher.ai29 * Direct Contact   : simon@spboucher.ai30 * Security/Admin   : admin@spboucher.ai31 *32 * The affiliation is descriptive. It is not an institutional endorsement,33 * a license grant or a determination of ownership.34 *35 * =============================================================================36 * COPYRIGHT, AUTHORSHIP & DATA37 * =============================================================================38 *39 * Copyright (c) the author(s) of this work.40 * Ownership is not asserted by this notice; see the repository records.41 *42 * This header identifies the maintainer of the software. Scientific43 * authorship of any associated paper is stated in the paper itself and44 * is not changed by this notice. Datasets and third-party materials45 * remain the property of their respective owners and licensors.46 *47 * This file is governed by the applicable project license, copyright48 * notices, institutional agreements and relevant law.49 *50 * =============================================================================51 * LICENSE & MAINTENANCE52 * =============================================================================53 *54 * License          : None specified (no license file in this repository)55 * Classification   : Public56 *57 * =============================================================================58 * END OF SP BOUCHER SOURCE HEADER59 * =============================================================================60 */6162// UQO Éval — Playwright : tout élément généré se télécharge (PDF, XLSX, CSV, JSON) avec la mention UQO Éval — estimation, parc, stats, marché, municipalité, résultats client.63import { expect, test } from "playwright/test";6465const XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";6667test("exports serveur : estimation, parc, stats, marché, municipalité en 4 formats, mention UQO Éval", async ({ page, request }) => {68  await page.goto("/municipalite/gatineau");69  // première unité de la page qui possède des comparables (certaines n'en ont aucun)70  const hrefs = await page.locator('a[href^="/estimation/"]').evaluateAll((as) => as.map((a) => (a as HTMLAnchorElement).getAttribute("href")!));71  let id = decodeURIComponent(hrefs[0].split("/estimation/")[1]);72  for (const h of hrefs.slice(0, 12)) { const cand = decodeURIComponent(h.split("/estimation/")[1]); const j = await (await request.get(`/api/export?kind=estimate&id=${encodeURIComponent(cand)}&format=json`)).json(); if (j.comparables?.length) { id = cand; break; } }73  const csv = await request.get(`/api/export?kind=estimate&id=${encodeURIComponent(id)}&format=csv`);74  expect(csv.status()).toBe(200); expect(csv.headers()["content-type"]).toContain("text/csv");75  const txt = await csv.text(); expect(txt).toContain("UQO Éval"); expect(txt).toContain("# Résumé"); expect(txt).toContain("result.estimate,"); expect(txt).toContain("Estimation —");76  if (txt.includes("# comparables")) expect(txt).toMatch(/# comparables\n[^\n]*id/);77  for (const [kind, q] of [["estimate", `id=${encodeURIComponent(id)}`], ["portfolio", `ids=${encodeURIComponent(id)}`], ["stats", ""], ["prov", ""], ["marche", ""], ["municipalite", "slug=gatineau"]] as const) {78    const x = await request.get(`/api/export?kind=${kind}&${q}&format=xlsx`); expect(x.status(), kind).toBe(200); expect(x.headers()["content-type"]).toBe(XLSX); expect((await x.body()).length).toBeGreaterThan(4000);79    const j = await request.get(`/api/export?kind=${kind}&${q}&format=json&lang=en`); const body = await j.json(); expect(body._uqo_eval.mention, kind).toContain("UQO Éval");80  }81  const pdf = await request.get(`/api/export?kind=municipalite&slug=gatineau&format=pdf`); expect(pdf.headers()["content-type"]).toBe("application/pdf"); expect((await pdf.body()).subarray(0, 5).toString()).toBe("%PDF-");82  expect((await request.get(`/api/export?kind=nope`)).status()).toBe(400);83  expect((await request.get(`/api/export?kind=estimate&id=zz`)).status()).toBe(404);84});8586test("export client (POST) d'un résultat calculé, et boutons de téléchargement visibles sur les pages", async ({ page, request }) => {87  const r = await request.post("/api/export?format=xlsx", { data: { kind: "hedonique", title: "Essai POST", lang: "fr", result: { n: 3, coefficients: [{ name: "a", value: 1 }], plots: { big: [{ x: 1 }] } } } });88  expect(r.status()).toBe(200); expect(r.headers()["content-type"]).toBe(XLSX); expect(r.headers()["content-disposition"]).toContain("uqo-eval_essai-post_");89  const pdf = await request.post("/api/export?format=pdf", { data: { kind: "avendre", title: "Atelier", lang: "en", result: { valeur: 1, comparables: [{ id: "x", amount: 1 }] } } });90  expect(pdf.headers()["content-type"]).toBe("application/pdf");91  for (const [p, kind] of [["/stats", "stats"], ["/stats", "prov"], ["/stats/marche", "marche"], ["/municipalite/gatineau", "municipalite"]] as const) {92    await page.goto(p);93    await expect(page.locator(`[data-download-menu="${kind}"] button`, { hasText: "XLSX" }).first()).toBeVisible();94  }95  await page.goto("/municipalite/gatineau");96  const [dl] = await Promise.all([page.waitForEvent("download"), page.locator('[data-download-menu="municipalite"] button', { hasText: "CSV" }).click()]);97  expect(dl.suggestedFilename()).toMatch(/^uqo-eval_l-immobilier-a-gatineau_.*\.csv$/);98});99
Files main
Menu

Theme