| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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`;
- 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(`<html lang="${locale}"`), `Wrong HTML language: ${a.path}`);
- assert.equal((html.match(/<html\b/g) || []).length, 1, 'Nested HTML root');
- assert(html.includes(`rel="canonical" href="https://text.skin${a.path}"`), `Wrong canonical: ${a.path}`);
- assert(html.includes(`name="robots" content="${indexing ? 'index' : 'noindex'}, follow"`), `Wrong robots: ${a.path}`);
- assert(/<title>[^<]+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]}"`));
- 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.includes('nav.blogs'), 'Untranslated key');
- 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']) assert(html.includes(`href="${target}"`), `Missing shared navigation action: ${target}`);
- assert(html.includes('aria-expanded="false"'), 'Mobile menu must SSR closed');
- assert(html.includes('<select') && html.includes('lang="'+locale+'"'), 'Missing locale navigation selector');
- const options = [...html.matchAll(/<option[^>]*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(/<option[^>]+>/g)].some(([tag]) => tag.includes(`value="${a.path}"`) && tag.includes('selected=""')), 'Current locale counterpart must be selected');
- if (a.id) {
- assert(/<h1>.+?<\/h1>/.test(html), 'Missing server-rendered heading');
- assert(/<h2>.+?<\/h2>/.test(html), 'Missing server-rendered article body');
- const schema = JSON.parse(html.match(/<script type="application\/ld\+json">(.*?)<\/script>/s)[1]);
- assert.equal(schema[0]['@type'], 'Article');
- assert.equal(schema[0].inLanguage, locale);
- assert.equal(schema[1]['@type'], 'BreadcrumbList');
- assert(!('datePublished' in schema[0]), 'Invented publish date');
- for (const source of a.sources) assert(html.includes(source.url.replace(/&/g, '&')), `Missing source: ${source.url}`);
- assert(html.includes(a.officialBooking.url.replace(/&/g, '&')), 'Missing destination-specific official CTA');
- assert(!html.includes('prenotami.esteri.it'), 'Stale Italy CTA');
- }
- checked++;
- }
- }
- for (const route of [...new Set(visible.map(a => `${indexFor(a.locale)}/nonexistent-guide`)), '/xx/blogs', '/en/blogs', '/blogs/nonexistent-guide', '/de/blogs/nonexistent-guide', '/blogs/italy-visa-appointments-dublin-prenotami', '/blogs/no-italy-visa-appointments-dublin', '/blogs/italy-tourist-visa-documents-ireland', '/nonexistent-route']) {
- assert.equal((await fetch(`${base}${route}`)).status, 404, `Should 404: ${route}`);
- }
- for (const route of ['/','/services','/slots','/login','/dashboard','/dashboard/settings','/admin','/payment/test','/payment/confirm','/create-order/test']) {
- const response = await fetch(`${base}${route}`);
- assert.equal(response.status, 200, `Old route regression: ${route}`);
- const html = await response.text(); assert(html.includes('<html lang="zh-CN"'), `Old root altered: ${route}`);
- if (/^\/(login|dashboard|admin|payment|create-order)(\/|$)/.test(route)) assert.equal(response.headers.get('x-robots-tag'), 'noindex, nofollow', `Missing privacy indexing header: ${route}`);
- }
- const queryResponse = await fetch(`${base}/blogs?utm_source=qa`);
- assert.equal(queryResponse.status, 200);
- const queryHtml = await queryResponse.text();
- assert(queryHtml.includes('rel="canonical" href="https://text.skin/blogs"'), 'Query-bearing index canonical must remain clean');
- assert(!queryResponse.headers.get('link')?.includes('hreflang'), 'Unexpected conflicting HTTP hreflang');
- const sitemap = await (await fetch(`${base}/sitemap.xml`)).text();
- const urls = [...sitemap.matchAll(/<loc>(.*?)<\/loc>/g)].map(m => m[1]);
- assert.equal(urls.length, indexing ? published.length + new Set(published.map(a => a.locale)).size : 0);
- if (indexing) {
- const expectedUrls = [...new Set(approvedInventory.map(a => `https://text.skin${indexFor(a.locale)}`)), ...approvedInventory.map(a => `https://text.skin${pathFor(a)}`)].sort();
- assert.equal(expectedUrls.length, 28, 'Approved scope is 21 translated guides plus seven indexes');
- assert.deepEqual([...urls].sort(), expectedUrls, 'Sitemap must exactly match approved multilingual cohort');
- }
- for (const url of urls) assert(url.startsWith('https://text.skin/') && /\/blogs(?:\/|$)/.test(url));
- const robots = await (await fetch(`${base}/robots.txt`)).text();
- assert(robots.includes('Disallow: /api/'));
- assert(!/Disallow: \/(?:blogs|admin|dashboard|login|payment|create-order)/.test(robots));
- console.log(`PASS: ${checked} server-rendered blog pages; language, metadata, sources, structured data; excluded/unknown routes; query canonical; 10 existing routes; private headers; sitemap and robots.`);
|