Squash merge de develop vers master. Livrables principaux (ticket #101 et mise au point associée) : - Branchement du formulaire d'inscription parent sur POST /api/v1/auth/register/parent - Payload DTO (parents, enfants, photos base64, CGU) et services Auth - Parcours gestionnaire : cartes dossiers, wizard validation famille, images authentifiées - Scripts d'inscription test (Martin, Durand/Rousseau, Lecomte) ; .gitignore .cursor/ Inclut également les ajustements develop fusionnés dans ce lot (inscription AM, champs relais, etc.). Closes #101 Made-with: Cursor
157 lines
4.6 KiB
JavaScript
157 lines
4.6 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 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 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(repoRoot, '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, 'G_Chloé.png');
|
|
const hugoSrc = path.join(photosDir, 'G_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 */
|
|
}
|
|
}
|