Some checks failed
Validation applicative / TypeScript, tests et build (push) Failing after 2m21s
105 lines
3.5 KiB
TypeScript
105 lines
3.5 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import * as XLSX from "xlsx";
|
|
import { describe, expect, it } from "vitest";
|
|
import { generateApprenantsExcelExport } from "../apprenantExportService";
|
|
import { sortSequencesForRegistration } from "../../shared/registration";
|
|
|
|
const inscriptionSource = readFileSync(
|
|
new URL("../../client/src/pages/Inscription.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
const sequencesSource = readFileSync(
|
|
new URL("../../client/src/pages/AdminSequences.tsx", import.meta.url),
|
|
"utf8",
|
|
);
|
|
|
|
describe("parcours d'inscription", () => {
|
|
it("place les sessions avec places disponibles avant les sessions complètes ou fermées", () => {
|
|
const now = new Date("2026-10-01T10:00:00.000Z");
|
|
const sorted = sortSequencesForRegistration(
|
|
[
|
|
{
|
|
id: 1,
|
|
nom: "Session fermée",
|
|
statut: "bloquee",
|
|
dateBlocage: null,
|
|
capaciteMax: 12,
|
|
nbInscrits: 0,
|
|
dates: [{ dateDebut: "2026-10-04T09:00:00.000Z" }],
|
|
},
|
|
{
|
|
id: 2,
|
|
nom: "Session complète",
|
|
statut: "ouverte",
|
|
dateBlocage: null,
|
|
capaciteMax: 12,
|
|
nbInscrits: 12,
|
|
dates: [{ dateDebut: "2026-10-03T09:00:00.000Z" }],
|
|
},
|
|
{
|
|
id: 3,
|
|
nom: "Session disponible tardive",
|
|
statut: "ouverte",
|
|
dateBlocage: null,
|
|
capaciteMax: 12,
|
|
nbInscrits: 3,
|
|
dates: [{ dateDebut: "2026-10-05T09:00:00.000Z" }],
|
|
},
|
|
{
|
|
id: 4,
|
|
nom: "Session disponible prioritaire",
|
|
statut: "ouverte",
|
|
dateBlocage: null,
|
|
capaciteMax: 12,
|
|
nbInscrits: 2,
|
|
dates: [{ dateDebut: "2026-10-02T09:00:00.000Z" }],
|
|
},
|
|
],
|
|
now,
|
|
);
|
|
|
|
expect(sorted.map((sequence) => sequence.id)).toEqual([4, 3, 2, 1]);
|
|
expect(sorted[0]).toMatchObject({ isBloquee: false, placesRestantes: 10 });
|
|
expect(sorted[3]).toMatchObject({ isBloquee: true });
|
|
});
|
|
|
|
it("présente un bouton explicite de sélection de session et le libellé Tous managers", () => {
|
|
expect(inscriptionSource).toContain("Choisir cette session");
|
|
expect(inscriptionSource).toContain("Session sélectionnée");
|
|
expect(inscriptionSource).toContain("Tous managers");
|
|
expect(sequencesSource).toContain("Tous managers");
|
|
});
|
|
});
|
|
|
|
describe("export Excel des apprenants", () => {
|
|
it("génère les colonnes nom, prénom et formation suivie", () => {
|
|
const buffer = generateApprenantsExcelExport([
|
|
{ nom: "Durand", prenom: "Alice", formationSuivie: "Manager de proximité" },
|
|
{ nom: "Martin", prenom: "Bruno", formationSuivie: "Gestion de projet | Communication" },
|
|
]);
|
|
|
|
const workbook = XLSX.read(buffer, { type: "buffer" });
|
|
expect(workbook.SheetNames).toEqual(["Apprenants"]);
|
|
|
|
const rows = XLSX.utils.sheet_to_json<string[]>(workbook.Sheets.Apprenants, {
|
|
header: 1,
|
|
raw: false,
|
|
});
|
|
expect(rows).toEqual([
|
|
["Nom", "Prénom", "Formation suivie"],
|
|
["Durand", "Alice", "Manager de proximité"],
|
|
["Martin", "Bruno", "Gestion de projet | Communication"],
|
|
]);
|
|
});
|
|
|
|
it("neutralise les valeurs interprétables comme formules Excel", () => {
|
|
const buffer = generateApprenantsExcelExport([
|
|
{ nom: "=HYPERLINK(\"https://example.org\")", prenom: "Alice", formationSuivie: "Formation test" },
|
|
]);
|
|
|
|
const workbook = XLSX.read(buffer, { type: "buffer" });
|
|
const sheet = workbook.Sheets.Apprenants;
|
|
expect(sheet.A2?.v).toBe("'=HYPERLINK(\"https://example.org\")");
|
|
});
|
|
});
|