import assert from 'node:assert/strict'; import fs from 'node:fs'; const base = process.env.BLOG_TEST_URL || 'http://127.0.0.1:3108'; const indexing = process.env.BLOG_INDEXING_ENABLED === 'true'; const approvedInventory = JSON.parse(fs.readFileSync('src/content/blog/approved-inventory.json', 'utf8')); const all = JSON.parse(fs.readFileSync('src/content/blog/articles.json', 'utf8')); const visible = all.filter(a => !indexing || a.published); const published = all.filter(a => a.published); const pathFor = a => `${a.locale === 'en' ? '' : `/${a.locale}`}/blogs/${a.slug}`; const indexFor = locale => `${locale === 'en' ? '' : `/${locale}`}/blogs`; const locales = ['en', 'de', 'fr', 'es', 'it', 'pt', 'zh']; const publicPaths = ['/', '/services', '/slots', '/terms', '/refund-policy', '/privacy', '/cookie-policy', '/contact']; const localize = (path, locale) => locale === 'en' ? path : '/' + locale + (path === '/' ? '' : path); const publicCopy = JSON.parse(fs.readFileSync('src/lib/i18n/public-pages.json', 'utf8')); const serviceIds = { 'netherlands-appointment-booking': 35, 'greece-appointment-booking': 34, 'denmark-appointment-booking': 36 }; const receipt = []; const escape = value => value.replaceAll('&', '&').replaceAll('"', '"').replaceAll("'", ''').replaceAll('<', '<').replaceAll('>', '>'); let checked = 0; for (const locale of new Set(visible.map(a => a.locale))) { const records = [{ locale, path: indexFor(locale) }, ...visible.filter(a => a.locale === locale).map(a => ({ ...a, path: pathFor(a) }))]; for (const a of records) { const response = await fetch(`${base}${a.path}`); assert.equal(response.status, 200, a.path); assert.equal(response.headers.get('x-robots-tag'), null, `Private route header leaked onto blog: ${a.path}`); const html = await response.text(); assert(html.includes(`[^<]+STRATA<\/title>/.test(html), `Missing title: ${a.path}`); assert(/name="description" content="[^"]+"/.test(html)); assert(html.includes(`property="og:url" content="https://text.skin${a.path}"`)); const ogLocales = { en:'en_IE', de:'de_DE', fr:'fr_FR', es:'es_ES', it:'it_IT', pt:'pt_PT', zh:'zh_CN' }; assert(html.includes(`property="og:locale" content="${ogLocales[locale]}"`)); assert(html.includes('rel="icon" href="/blog-icon.svg"'), `Missing blog icon: ${a.path}`); const variants = a.id ? published.filter(b => b.id === a.id) : [...new Set(published.map(b => b.locale))].map(locale => ({ locale })); for (const b of variants) assert(html.includes(`hrefLang="${b.locale}" href="https://text.skin${b.id ? pathFor(b) : indexFor(b.locale)}"`), `Missing SEO alternate ${a.path} → ${b.locale}`); const alternateCount = (html.match(/rel="alternate" hrefLang=/g) || []).length; assert.equal(alternateCount, variants.length + (variants.some(b => b.locale === 'en') ? 1 : 0), `Unexpected alternate: ${a.path}`); assert(!html.replace(/]*>.*?<\/script>/gs, '').includes('nav.blogs'), 'Untranslated key in visible markup'); assert(html.includes('data-blog-navigation'), 'Missing shared site navigation wrapper'); assert(!html.includes('class="blog-languages"'), 'Duplicate blog language row must be absent'); for (const target of ['/services', '/slots', '/login'].map(path => localize(path, locale))) assert(html.includes(`href="${target}"`), `Missing shared navigation action: ${target}`); assert(html.includes('aria-expanded="false"'), 'Mobile menu must SSR closed'); assert(html.includes(']*value="([^"]+)"/g)].map(m => m[1]); const expectedOptions = a.id ? visible.filter(b => b.id === a.id).map(pathFor) : [...new Set(visible.map(b => b.locale))].map(indexFor); assert.deepEqual([...new Set(options)].sort(), expectedOptions.sort(), 'Navigation must link actual counterparts'); assert([...html.matchAll(/]+>/g)].some(([tag]) => tag.includes(`value="${a.path}"`) && tag.includes('selected=""')), 'Current locale counterpart must be selected'); receipt.push({ path: a.path, status: response.status, language: locale, canonical: 'https://text.skin' + a.path, robots: indexing ? 'index, follow' : 'noindex, follow', alternates: alternateCount }); if (a.id) { assert(html.includes(`data-service-id="${serviceIds[a.id]}"`), 'Missing destination-specific conversion section'); assert(html.includes(`class="blog-service-button" href="${localize('/create-order/' + serviceIds[a.id], locale)}"`), 'Wrong service CTA'); assert(/

.+?<\/h1>/.test(html), 'Missing server-rendered heading'); assert(/]*>.+?<\/h2>/.test(html), 'Missing server-rendered article body'); const schema = JSON.parse(html.match(/