petitspas/tests/scripts/register-parent-durand-rousseau-test.mjs
Julien Martin 58607cdbc9 feat(inscription AM #120): UI étape pro, photo unifiée, scripts et données test
- Panneau AM : validation NIR alignée API, date d’agrément requise côté app,
  capacité 1–10, n° agrément + date sur une ligne, ville/pays formatés au blur.
- Widget RegistrationPhotoSlot (cadre, croix) partagé avec les cartes enfant.
- AuthService : MIME PNG/JPEG pour la photo ; payload date_agrement.
- Scripts register-am-dubois / mansouri ; chemins tests/ressources/photos ;
  doc test-data + seed ; smoke curl inscription AM.

Made-with: Cursor
2026-04-13 13:19:32 +02:00

157 lines
4.7 KiB
JavaScript

/**
* POST /api/v1/auth/register/parent — jeu de test officiel couple DURAND / ROUSSEAU (docs/test-data + seed).
* Emails : amelie.durand@ptits-pas.fr, julien.rousseau@ptits-pas.fr
*
* Les PNG dans tests/ressources/photos dépassent la limite JSON (~15 Mo) du serveur : réduction locale
* via npx sharp-cli (resize 600 + JPEG q80) avant encodage base64.
*
* Usage : node tests/scripts/register-parent-durand-rousseau-test.mjs [BASE_URL]
*/
import fs from 'fs';
import path from 'path';
import os from 'os';
import https from 'https';
import http from 'http';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.join(__dirname, '..', '..');
const photosDir = path.join(__dirname, '..', 'ressources', 'photos');
function shrinkToJpeg(inputPath, label) {
const out = path.join(os.tmpdir(), `ptitspas-${label}-${Date.now()}.jpg`);
const cmd = `npx --yes sharp-cli -i ${JSON.stringify(inputPath)} -o ${JSON.stringify(out)} -mq80 resize 600 600`;
execSync(cmd, { cwd: repoRoot, stdio: 'inherit', shell: true });
return out;
}
function toDataUri(filePath) {
const buf = fs.readFileSync(filePath);
const ext = path.extname(filePath).toLowerCase();
const mime =
ext === '.jpg' || ext === '.jpeg' ? 'image/jpeg' : 'image/png';
return `data:${mime};base64,${buf.toString('base64')}`;
}
const presentationDossier =
"Nous sommes Amélie DURAND et Julien ROUSSEAU, parents de Chloé et Hugo. " +
"Nous sommes divorcés ; Amélie assure la garde principale et nous pratiquons la garde alternée un week-end sur deux. " +
"Nous recherchons une assistante maternelle à Bezons pour accueillir nos enfants dans un cadre bienveillant et stable. " +
"Merci pour l'étude de notre dossier.";
const chloeSrc = path.join(photosDir, 'rousseau-chloe.png');
const hugoSrc = path.join(photosDir, 'rousseau-hugo.png');
let chloeJpg;
let hugoJpg;
try {
console.error('Réduction des photos (sharp-cli)…');
chloeJpg = shrinkToJpeg(chloeSrc, 'chloe');
hugoJpg = shrinkToJpeg(hugoSrc, 'hugo');
const body = {
email: 'amelie.durand@ptits-pas.fr',
prenom: 'Amélie',
nom: 'DURAND',
telephone: '0667788990',
adresse: '23 Rue Victor Hugo',
code_postal: '95870',
ville: 'Bezons',
co_parent_email: 'julien.rousseau@ptits-pas.fr',
co_parent_prenom: 'Julien',
co_parent_nom: 'ROUSSEAU',
co_parent_telephone: '0656677889',
co_parent_meme_adresse: false,
co_parent_adresse: '14 Rue Pasteur',
co_parent_code_postal: '95870',
co_parent_ville: 'Bezons',
enfants: [
{
prenom: 'Chloé',
nom: 'ROUSSEAU',
date_naissance: '2022-04-20',
genre: 'F',
photo_base64: toDataUri(chloeJpg),
photo_filename: 'chloe_rousseau.jpg',
grossesse_multiple: false,
},
{
prenom: 'Hugo',
nom: 'ROUSSEAU',
date_naissance: '2024-03-10',
genre: 'H',
photo_base64: toDataUri(hugoJpg),
photo_filename: 'hugo_rousseau.jpg',
grossesse_multiple: false,
},
],
presentation_dossier: presentationDossier,
acceptation_cgu: true,
acceptation_privacy: true,
};
const json = JSON.stringify(body);
const baseArg = process.argv[2] || 'https://app.ptits-pas.fr';
const base = new URL(baseArg.endsWith('/') ? baseArg.slice(0, -1) : baseArg);
const url = new URL('/api/v1/auth/register/parent', `${base.protocol}//${base.host}`);
const opts = {
hostname: url.hostname,
port: url.port || (url.protocol === 'https:' ? 443 : 80),
path: url.pathname,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'Content-Length': Buffer.byteLength(json, 'utf8'),
},
};
const lib = url.protocol === 'https:' ? https : http;
console.error(`POST ${url.href} (payload ~${Math.round(json.length / 1024)} Ko)`);
const req = lib.request(opts, (res) => {
let data = '';
res.on('data', (c) => {
data += c;
});
res.on('end', () => {
console.log('HTTP', res.statusCode);
try {
const j = JSON.parse(data);
console.log(JSON.stringify(j, null, 2));
} catch {
console.log(data.slice(0, 4000));
}
});
});
req.on('error', (e) => {
console.error('Erreur réseau:', e.message);
process.exit(1);
});
req.setTimeout(120000, () => {
req.destroy();
console.error('Timeout 120s');
process.exit(1);
});
req.write(json);
req.end();
} finally {
try {
if (chloeJpg) fs.unlinkSync(chloeJpg);
} catch {
/* ignore */
}
try {
if (hugoJpg) fs.unlinkSync(hugoJpg);
} catch {
/* ignore */
}
}