- POST /auth/register/am : places_disponibles, enregistrement place_disponible, contrôle ≤ capacité - Formulaire pro AM : places sur la ligne capacité, mobile un champ par ligne, carte desktop plus compacte (espacements, polices, labelFieldSpacing) - Capacité et places validées jusqu’à 4 dans l’app (kAmCapaciteAccueilMax) ; hint NIR « 13 chiffres + clé » - Scripts d’inscription AM (Node + smoke shell) : places_disponibles Made-with: Cursor
129 lines
3.8 KiB
JavaScript
129 lines
3.8 KiB
JavaScript
/**
|
|
* POST /api/v1/auth/register/am — jeu de test officiel Marie DUBOIS (docs/test-data + seed).
|
|
* Email : marie.dubois@ptits-pas.fr
|
|
*
|
|
* Photo attendue : tests/ressources/photos/dubois-marie.png
|
|
* Données alignées sur database/seed/03_seed_test_data.sql (NIR, dates, agrément, adresse).
|
|
* (réduction JPEG locale via sharp-cli si besoin, comme les autres scripts lourds)
|
|
*
|
|
* Usage : node tests/scripts/register-am-dubois-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 photoSrc = path.join(photosDir, 'dubois-marie.png');
|
|
|
|
let photoPath;
|
|
try {
|
|
console.error('Préparation photo (sharp-cli)…');
|
|
photoPath = shrinkToJpeg(photoSrc, 'am-dubois');
|
|
|
|
const body = {
|
|
email: 'marie.dubois@ptits-pas.fr',
|
|
prenom: 'Marie',
|
|
nom: 'DUBOIS',
|
|
telephone: '0696345678',
|
|
adresse: '25 Rue de la République',
|
|
code_postal: '95870',
|
|
ville: 'Bezons',
|
|
photo_base64: toDataUri(photoPath),
|
|
photo_filename: 'marie_dubois.jpg',
|
|
consentement_photo: true,
|
|
date_naissance: '1980-06-08',
|
|
lieu_naissance_ville: 'Ajaccio',
|
|
lieu_naissance_pays: 'France',
|
|
nir: '280062A00100191',
|
|
numero_agrement: 'AGR-2019-095001',
|
|
date_agrement: '2019-09-01',
|
|
capacite_accueil: 4,
|
|
places_disponibles: 2,
|
|
biographie:
|
|
"Assistante maternelle agréée depuis 2019. Née en Corse à Ajaccio. Spécialité bébés 0-18 mois. " +
|
|
'Accueil bienveillant et cadre sécurisant. 2 places disponibles.',
|
|
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/am', `${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 (photoPath && fs.existsSync(photoPath)) fs.unlinkSync(photoPath);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|