Merge remote-tracking branch 'gitea/feat/aep-xl-publications'
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Test des données de l'onglet « Publications » (/media?tab=projets, lot XL publications).
|
||||
* Six projets, auteurs nommés, jamais « Inconnu », une illustration WebP ≤ 60 Ko par projet,
|
||||
* et la carte entière comme seul lien.
|
||||
* Usage : node scripts/test-media-data.mjs
|
||||
*/
|
||||
|
||||
import { readFileSync, existsSync, statSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { dirname, join } from 'node:path'
|
||||
|
||||
const racine = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
const echecs = []
|
||||
let n = 0
|
||||
function verifie(ok, message) {
|
||||
n++
|
||||
if (!ok) echecs.push(message)
|
||||
}
|
||||
|
||||
const { projets } = JSON.parse(readFileSync(join(racine, 'public/data/pfe-engages.json'), 'utf8'))
|
||||
verifie(Array.isArray(projets) && projets.length === 6, `six projets attendus, ${projets?.length} trouvés`)
|
||||
verifie(new Set(projets.map(p => p.id)).size === projets.length, 'identifiants en double')
|
||||
|
||||
const MAX = 60 * 1024
|
||||
for (const p of projets) {
|
||||
const id = p.id
|
||||
verifie(Array.isArray(p.auteurs) && p.auteurs.length > 0, `${id} : auteurs vides`)
|
||||
verifie((p.auteurs || []).every(a => typeof a === 'string' && a.trim()), `${id} : un auteur vide`)
|
||||
verifie(!JSON.stringify(p).includes('Inconnu'), `${id} : « Inconnu » encore présent`)
|
||||
verifie(p.ecole === null || (typeof p.ecole === 'string' && p.ecole.trim()), `${id} : école ni nulle ni renseignée`)
|
||||
verifie(typeof p.url === 'string' && /^https?:\/\//.test(p.url), `${id} : url absente`)
|
||||
verifie(typeof p.illustration === 'string' && p.illustration === `/medias/publications/${id}.webp`,
|
||||
`${id} : illustration attendue en /medias/publications/${id}.webp`)
|
||||
const fichier = join(racine, 'public', p.illustration || '')
|
||||
verifie(existsSync(fichier), `${id} : fichier ${p.illustration} absent`)
|
||||
if (existsSync(fichier)) {
|
||||
const poids = statSync(fichier).size
|
||||
verifie(poids <= MAX, `${id} : ${poids} o, au-dessus de 60 Ko`)
|
||||
const tete = readFileSync(fichier).subarray(0, 12).toString('latin1')
|
||||
verifie(tete.startsWith('RIFF') && tete.slice(8) === 'WEBP', `${id} : le fichier n'est pas un WebP`)
|
||||
}
|
||||
verifie(p.illustration_a_venir === true || (typeof p.credit_illustration === 'string' && p.credit_illustration.trim()),
|
||||
`${id} : une image tirée du projet doit porter son crédit`)
|
||||
}
|
||||
|
||||
// Seine nature urbaine : site « tous droits réservés », placeholder tant que l'auteur n'a pas donné son accord.
|
||||
const seine = projets.find(p => p.id === 'seine-nature')
|
||||
verifie(seine?.illustration_a_venir === true, 'seine-nature : placeholder obligatoire (accord de l\'auteur en attente)')
|
||||
|
||||
// Composant : la carte entière est le seul lien, plus de « Découvrir → » en second lien.
|
||||
const vue = readFileSync(join(racine, 'components/MediaTabProjets.vue'), 'utf8')
|
||||
const gabarit = vue.slice(vue.indexOf('<template>'), vue.lastIndexOf('</template>'))
|
||||
const grille = gabarit.slice(gabarit.indexOf('projets-grid'), gabarit.indexOf('</ul>'))
|
||||
verifie((grille.match(/<a\b/g) || []).length === 1, 'un seul <a> par carte dans la grille')
|
||||
verifie(/class="projet-carte"/.test(grille), 'la carte porte la classe projet-carte')
|
||||
verifie(!/[↗→·]/.test(gabarit), 'ni flèche ni point médian dans le gabarit')
|
||||
verifie(/loading="lazy"/.test(grille) && /width="800"/.test(grille) && /height="600"/.test(grille),
|
||||
'image en lazy avec width et height posés')
|
||||
|
||||
if (echecs.length) {
|
||||
for (const e of echecs) console.log(`FAIL ${e}`)
|
||||
console.log(`\n${n - echecs.length}/${n} vérifications OK — ${echecs.length} échec(s)`)
|
||||
process.exit(1)
|
||||
}
|
||||
console.log(`${n} vérifications OK`)
|
||||
Reference in New Issue
Block a user