Files
petitspas/tests/scripts/register-parent-bernard-test.mjs
T
2026-09-24 00:49:02 +02:00

104 lines
2.8 KiB
JavaScript

/**
* POST /api/v1/auth/register/parent — foyer mono-parent (1 parent + 1 enfant).
* Inspiré de register-parent-lecomte-test.mjs.
* Email : sophie.bernard@example.com
*
* Usage : node tests/scripts/register-parent-bernard-test.mjs [BASE_URL]
*/
import fs from 'fs';
import path from 'path';
import https from 'https';
import http from 'http';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const photosDir = path.join(__dirname, '..', 'ressources', 'photos');
function toDataUri(filePath) {
const buf = fs.readFileSync(filePath);
return `data:image/png;base64,${buf.toString('base64')}`;
}
const presentationDossier =
"Je suis Sophie BERNARD, mère isolée de Jules. J'ai la garde complète de mon fils. " +
"Je recherche une assistante maternelle bienveillante à Bezons. " +
"Merci pour l'étude de notre dossier.";
const body = {
email: 'sophie.bernard@example.com',
prenom: 'Sophie',
nom: 'BERNARD',
telephone: '0611223344',
adresse: '12 Rue des Lilas',
code_postal: '95870',
ville: 'Bezons',
// Pas de co-parent (mono-parent).
enfants: [
{
prenom: 'Jules',
nom: 'BERNARD',
date_naissance: '2024-06-10',
genre: 'H',
// Réutilise une photo de test existante.
photo_base64: toDataUri(path.join(photosDir, 'lecomte-maxime.png')),
photo_filename: 'jules_bernard.png',
},
],
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));
}
if (res.statusCode < 200 || res.statusCode >= 300) process.exit(1);
});
});
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();