69 lines
3.9 KiB
JavaScript
69 lines
3.9 KiB
JavaScript
import { test } from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import fs from "node:fs";
|
||
import { buildOnboardingBrief, buildEvolutionBrief, EXAMPLE_PAYLOAD } from "../../app/domain/ai-brief.js";
|
||
import { decodeProposalFragment } from "../../app/domain/link.js";
|
||
import { validateProgram } from "../../app/domain/program.js";
|
||
import { validateProfile } from "../../app/domain/profile.js";
|
||
import { EXERCISES, FAMILIES } from "../../app/domain/exercises.js";
|
||
import { convertAtelier } from "../../app/domain/atelier.js";
|
||
import { foldEvents, emptyState } from "../../app/domain/state.js";
|
||
|
||
const baseUrl = "https://ia-fit.sans.pub";
|
||
|
||
test("l'exemple donné à l'IA est valide", () => {
|
||
assert.deepEqual(validateProgram(EXAMPLE_PAYLOAD.program), []);
|
||
assert.deepEqual(validateProfile(EXAMPLE_PAYLOAD.profile), []);
|
||
});
|
||
|
||
test("accueil : questions, ingestion d'un programme existant, formats, lien, MCP", () => {
|
||
const brief = buildOnboardingBrief({ baseUrl });
|
||
assert.match(brief, /en une seule fois/);
|
||
assert.match(brief, /capture d'écran/);
|
||
for (const ref of Object.keys(EXERCISES)) assert.ok(brief.includes("`" + ref + "`"), ref);
|
||
// bibliothèque groupée par famille, une ligne par exercice
|
||
for (const label of Object.values(FAMILIES)) assert.ok(brief.includes("### " + label + "\n"), label);
|
||
assert.match(brief, /^- `leg-press` : Presse à cuisses \(machine guidée ; quadriceps, fessiers\)$/m);
|
||
assert.match(brief, /sets: entier de 1 à 12/);
|
||
assert.match(brief, /sessionMinutes: durée visée/);
|
||
assert.ok(brief.includes("https://ia-fit.sans.pub/#import-json=%7B%22program%22%3A"));
|
||
assert.match(brief, /## Connecteur MCP \(disponible\)[\s\S]*https:\/\/ia-fit\.sans\.pub\/mcp[\s\S]*ChatGPT[\s\S]*get_overview/);
|
||
// l'exemple du texte se relit tel quel
|
||
const example = /```json\n(.*)\n```/.exec(brief)?.[1];
|
||
assert.deepEqual(JSON.parse(example ?? "null"), EXAMPLE_PAYLOAD);
|
||
});
|
||
|
||
test("un lien écrit comme le demande le texte devient une proposition", async () => {
|
||
const link = baseUrl + "/#import-json=" + encodeURIComponent(JSON.stringify(EXAMPLE_PAYLOAD));
|
||
const e = await decodeProposalFragment(link, { device: "phone" });
|
||
assert.equal(e.data.source, "link");
|
||
assert.deepEqual(/** @type {any} */ (e.data).profile, EXAMPLE_PAYLOAD.profile);
|
||
});
|
||
|
||
|
||
test("évolution : profil, mode, assiduité, historique condensé, programme", () => {
|
||
const raw = JSON.parse(fs.readFileSync(new URL("../fixtures/atelier-etat.json", import.meta.url), "utf8"));
|
||
const state = foldEvents(convertAtelier(raw, { device: "import", now: new Date("2026-11-18T10:00:00Z") }).events);
|
||
const brief = buildEvolutionBrief(state, { today: "2026-11-18", baseUrl });
|
||
assert.match(brief, /Objectif : Ancrer l'habitude/);
|
||
assert.match(brief, /109\.6 kg le 2026-11-17, en baisse de 0\.\d\d kg par semaine/);
|
||
assert.match(brief, /maintien : /);
|
||
assert.match(brief, /Jours disponibles : lundi, mercredi, vendredi, samedi\. Jours imposés : lundi = strength:A/);
|
||
assert.match(brief, /6 séance\(s\), soit 2\.6 par semaine depuis la première : séance A × 2/);
|
||
assert.match(brief, /2026-11-11, 2026-11-14/);
|
||
assert.match(brief, /- 2026-11-02 · séance A \(Bas du corps \+ dos\) · échauffement 7\/9\n {2}squat 60 kg \(objectif 4 × 8\) : 8 ok, 8 ok, 8 hard, 7 failure/);
|
||
assert.match(brief, /- 2026-11-06 · activité : Foot à 5/);
|
||
assert.match(brief, /plank 40 s \(objectif 3 × 40 s\) : faite, faite, faite/);
|
||
assert.match(brief, /- C-farmer-walk : 22 kg, 40 s/);
|
||
assert.match(brief, /"name": "L'atelier"/);
|
||
assert.match(brief, /"profile": … \(seulement s'il change\)/);
|
||
});
|
||
|
||
test("évolution sans programme ni séance", () => {
|
||
const state = { ...emptyState(), program: /** @type {any} */ (null) };
|
||
const brief = buildEvolutionBrief(state, { today: "2026-11-18", baseUrl });
|
||
assert.match(brief, /Aucun programme pour l'instant/);
|
||
assert.match(brief, /Aucune séance enregistrée sur la période/);
|
||
assert.match(brief, /Objectif : non renseigné/);
|
||
});
|