Commit 8d6c999e by PLN (Algolia)

couple: fix questionss — kind already plural, href and route lookup agreed on adding an s

itemHref and findCoupleItem both appended 's' to the kind, so every question
set linked to /couple/questionss/<slug> (404) and the prerendered question
pages resolved to notFound content. The collection mapping now lives in one
place and a validation test walks every guide item through its own href:
no 404, no collision, payload present per kind.
parent 8b8f00cd
...@@ -10,8 +10,10 @@ import Link from 'next/link'; ...@@ -10,8 +10,10 @@ import Link from 'next/link';
import { readGuideMark, readGuideNotes } from './engine'; import { readGuideMark, readGuideNotes } from './engine';
import { strings } from './strings'; import { strings } from './strings';
/* Collection d'URL d'un item : fiches et videos prennent un s, questions
l'a déjà (kind 'questions' est pluriel dans le corpus). */
export function itemHref(item) { export function itemHref(item) {
return '/couple/' + item.kind + 's/' + item.id.split(':')[1]; return '/couple/' + (item.kind === 'questions' ? 'questions' : item.kind + 's') + '/' + item.id.split(':')[1];
} }
function itemState(item) { function itemState(item) {
......
...@@ -117,12 +117,18 @@ export async function loadCoupleItems() { ...@@ -117,12 +117,18 @@ export async function loadCoupleItems() {
return items; return items;
} }
/* Route → item : collection = nom de dossier du corpus (fiches, videos, /* Collection d'URL d'un kind : fiches et videos prennent un s, questions
questions), slug = nom de fichier. Retourne aussi le voisin suivant pour l'a déjà (même règle que itemHref dans GuideHub). */
le lien « poursuivre » en bas de page. */ function kindToCollection(kind) {
return kind === 'questions' ? 'questions' : kind + 's';
}
/* Route → item : collection = nom d'URL (fiches, videos, questions), slug =
nom de fichier. Retourne aussi le voisin suivant pour le lien « poursuivre »
en bas de page. */
export async function findCoupleItem(collection, slug) { export async function findCoupleItem(collection, slug) {
const items = await loadCoupleItems(); const items = await loadCoupleItems();
const index = items.findIndex((it) => it.kind + 's' === collection && it.id.split(':')[1] === slug); const index = items.findIndex((it) => kindToCollection(it.kind) === collection && it.id.split(':')[1] === slug);
if (index === -1) return null; if (index === -1) return null;
return { item: items[index], next: items[index + 1] || null }; return { item: items[index], next: items[index + 1] || null };
} }
/* Clarté couple : validation des URL du guide. Chaque item doit se rendre
par son href (itemHref → findCoupleItem), sans 404 ni décalage de
collection (l'incident « questionss » : kind déjà pluriel + 's'). */
import {
findCoupleItem,
loadCoupleItems,
} from '@/lib/couple-guide';
import { itemHref } from '@/components/couple/GuideHub';
describe('couple guide URLs', () => {
const items = () => loadCoupleItems();
test('every item href resolves to the same item', async () => {
for (const item of await items()) {
const href = itemHref(item);
const collection = href.split('/')[2];
const slug = href.split('/')[3];
const found = await findCoupleItem(collection, slug);
expect(found).not.toBeNull();
expect(found.item.id).toBe(item.id);
}
});
test('each kind maps to its own collection, no collisions', async () => {
const seen = await items();
const hrefs = seen.map(itemHref);
expect(new Set(hrefs).size).toBe(hrefs.length);
});
test('every item carries its payload: html, youtube id or questions', async () => {
for (const item of await items()) {
if (item.kind === 'fiche') {
expect(item.html.length).toBeGreaterThan(40);
} else if (item.kind === 'video') {
expect(item.youtube).toMatch(/^[\w-]{6,}$/);
} else if (item.kind === 'questions') {
expect(item.questions.length).toBeGreaterThan(0);
}
}
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment