Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : agentilab-web8 * File : tests/unit/catalog.test.ts9 * Module : Tests10 * Repository : https://git.spboucher.ai/agentilab-web11 * Project Website : Not specified12 * Created : 2026-12-0513 * Last Modified : 2026-12-0514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : Proprietary34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { describe, expect, it } from 'vitest';44import { brands } from '@/content/public/brands';45import { products } from '@/content/public/products';46import { technologies } from '@/content/public/technologies';47import { milestones } from '@/content/public/milestones';48import { contactChannels } from '@/content/public/contact';49import { assetRecords } from '@/content/public/assets';50import { publishedProducts, verifiedChannels } from '@/lib/catalog';51import { validateCatalog } from '@/lib/catalog/validate';52import type { Product } from '@/lib/catalog/types';53import { existsSync } from 'node:fs';54import path from 'node:path';5556const base = { brands, products, technologies, milestones, channels: contactChannels };57const sample = products.find((p) => p.id === 'orix-calc') as Product;58const withProduct = (patch: Partial<Product>) => validateCatalog({ ...base, products: [...products.filter((p) => p.id !== sample.id), { ...sample, ...patch }] });5960describe('catalogue réel', () => {61 it('est valide', () => {62 expect(validateCatalog(base)).toEqual([]);63 });6465 it('publie 6 plateformes Groupe Ka et 14 applications ORIX', () => {66 expect(publishedProducts.filter((p) => p.brandId === 'groupe-ka')).toHaveLength(6);67 expect(publishedProducts.filter((p) => p.brandId === 'orix')).toHaveLength(14);68 });6970 it('ne publie aucune entrée non vérifiée et retire les champs internes', () => {71 for (const product of publishedProducts) {72 expect(product.status).not.toBe('unverified');73 expect(product).not.toHaveProperty('evidenceRef');74 expect(product).not.toHaveProperty('publish');75 }76 expect(publishedProducts.map((p) => p.id)).not.toContain('orix-secure');77 });7879 it('ne référence que des fichiers d’image présents dans public/', () => {80 for (const record of assetRecords) {81 expect(existsSync(path.join(process.cwd(), 'public', record.file)), record.file).toBe(true);82 }83 });8485 it('n’affiche aucun canal de contact non vérifié', () => {86 expect(verifiedChannels.every((c) => c.verified && c.verifiedAt)).toBe(true);87 });88});8990describe('règles de validation', () => {91 it('refuse publish=true avec le statut unverified', () => {92 expect(withProduct({ status: 'unverified' }).join('\n')).toMatch(/publish=true interdit/);93 });94 it('refuse un slug en double', () => {95 expect(withProduct({ slug: 'lou-ka' }).join('\n')).toMatch(/en double/);96 });97 it('refuse une marque inconnue', () => {98 expect(withProduct({ brandId: 'fictive' as Product['brandId'] }).join('\n')).toMatch(/inconnue/);99 });100 it('refuse une URL non HTTPS', () => {101 expect(withProduct({ officialUrl: { fr: 'http://exemple.test', en: 'https://exemple.test' } }).join('\n')).toMatch(/HTTPS/);102 });103 it('refuse une traduction manquante', () => {104 expect(withProduct({ description: { fr: 'Texte', en: ' ' } }).join('\n')).toMatch(/traduction manquante/);105 });106 it('refuse un lien App Store sans date de vérification', () => {107 expect(withProduct({ storeLinks: [{ kind: 'app-store', url: 'https://apps.apple.com/app/x/id1', verifiedAt: '' }] }).join('\n')).toMatch(/date de vérification/);108 });109 it('refuse une image distante (hotlink)', () => {110 expect(withProduct({ icon: { src: 'https://tiers.test/i.png', width: 1, height: 1, alt: { fr: '', en: '' } } }).join('\n')).toMatch(/hotlink/);111 });112 it('refuse un champ sensible', () => {113 expect(withProduct({ ...({ homeAddress: 'x' } as object) }).join('\n')).toMatch(/champ sensible/);114 });115 it('refuse un jalon sans preuve', () => {116 const errors = validateCatalog({ ...base, milestones: [{ date: '2026-01-01', title: { fr: 'a', en: 'a' }, text: { fr: 'a', en: 'a' }, evidenceRef: '' }] });117 expect(errors.join('\n')).toMatch(/sur preuve/);118 });119});120