/** * POST /api/v1/auth/register/parent — jeu de test officiel David LECOMTE (père isolé). * Email : david.lecomte@ptits-pas.fr * * Usage : node tests/scripts/register-parent-lecomte-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 repoRoot = path.join(__dirname, '..', '..'); 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 David LECOMTE, père isolé de Maxime. J'ai la garde complète de mon fils. " + "Je recherche une assistante maternelle bienveillante à Bezons. " + "En cas d'urgence, la personne à contacter est sa grand-mère paternelle. " + "Merci pour l'étude de notre dossier."; const body = { email: 'david.lecomte@ptits-pas.fr', prenom: 'David', nom: 'LECOMTE', telephone: '0645566778', adresse: '31 Rue Émile Zola', code_postal: '95870', ville: 'Bezons', enfants: [ { prenom: 'Maxime', nom: 'LECOMTE', date_naissance: '2023-04-15', genre: 'H', photo_base64: toDataUri(path.join(photosDir, 'lecomte-maxime.png')), photo_filename: 'maxime_lecomte.png', 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();