scripts: ajout des inscriptions parent test (Martin, Durand/Rousseau, Lecomte)

Scripts Node POST /api/v1/auth/register/parent alignés sur docs/test-data et le seed, avec photos ressources/Photos (réduction JPEG via sharp-cli pour Durand/Rousseau).

Made-with: Cursor
This commit is contained in:
MARTIN Julien 2026-04-11 17:59:31 +02:00
parent 4fe29799cd
commit dbca12d5d1
3 changed files with 384 additions and 0 deletions

View File

@ -0,0 +1,156 @@
/**
* 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 */
}
}

View File

@ -0,0 +1,102 @@
/**
* POST /api/v1/auth/register/parent jeu de test officiel David LECOMTE (père isolé).
* Email : david.lecomte@ptits-pas.fr
*
* Usage : node 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(repoRoot, '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, 'C_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();

View File

@ -0,0 +1,126 @@
/**
* POST /api/v1/auth/register/parent jeu de test officiel famille MARTIN (docs/test-data + seed).
* Emails canoniques : claire.martin@ptits-pas.fr, thomas.martin@ptits-pas.fr
*
* Usage : node scripts/register-parent-martin-test.mjs [BASE_URL]
* Ex. : node scripts/register-parent-martin-test.mjs https://app.ptits-pas.fr
*/
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(repoRoot, 'ressources', 'Photos');
function toDataUri(filePath) {
const buf = fs.readFileSync(filePath);
return `data:image/png;base64,${buf.toString('base64')}`;
}
const presentationDossier =
"Nous sommes Claire et Thomas MARTIN, parents d'Emma, Noah et Léa, triplés nés le 15 février 2023. " +
"Nous recherchons une assistante maternelle bienveillante et structurée pour accueillir nos trois enfants, " +
"avec une capacité d'accueil adaptée à la garde de plusieurs nourrissons. " +
"Nous habitons à Bezons ; nous tenons à remercier le service pour l'étude de notre dossier.";
const body = {
email: 'claire.martin@ptits-pas.fr',
prenom: 'Claire',
nom: 'MARTIN',
telephone: '0689567890',
adresse: '5 Avenue du Général de Gaulle',
code_postal: '95870',
ville: 'Bezons',
co_parent_email: 'thomas.martin@ptits-pas.fr',
co_parent_prenom: 'Thomas',
co_parent_nom: 'MARTIN',
co_parent_telephone: '0678456789',
co_parent_meme_adresse: true,
enfants: [
{
prenom: 'Emma',
nom: 'MARTIN',
date_naissance: '2023-02-15',
genre: 'F',
photo_base64: toDataUri(path.join(photosDir, 'C_Emma MARTIN.png')),
photo_filename: 'emma_martin.png',
grossesse_multiple: true,
},
{
prenom: 'Noah',
nom: 'MARTIN',
date_naissance: '2023-02-15',
genre: 'H',
photo_base64: toDataUri(path.join(photosDir, 'C_Noah MARTIN_2.png')),
photo_filename: 'noah_martin.png',
grossesse_multiple: true,
},
{
prenom: 'Léa',
nom: 'MARTIN',
date_naissance: '2023-02-15',
genre: 'F',
photo_base64: toDataUri(path.join(photosDir, 'C_Léa MMARTIN.png')),
photo_filename: 'lea_martin.png',
grossesse_multiple: true,
},
],
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();