| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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(`<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]}"`));
- 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\b[^>]*>.*?<\/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('<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');
- 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>.+?<\/h1>/.test(html), 'Missing server-rendered heading');
- assert(/<h2\b[^>]*>.+?<\/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']) {
- const response = await fetch(`${base}${route}`);
- assert.equal(response.status, 404, `Should 404: ${route}`);
- assert(/name="robots" content="noindex(?:,|"|\s)/.test(await response.text()), `Missing error-page noindex: ${route}`);
- }
- let publicChecked = 0, privateChecked = 0;
- for (const locale of locales) {
- for (const path of publicPaths) {
- const route = localize(path, locale);
- const response = await fetch(base + route);
- assert.equal(response.status, 200, route);
- assert.equal(response.headers.get('x-robots-tag'), null, route);
- const html = await response.text();
- const canonical = 'https://text.skin' + route;
- const robots = indexing || (locale === 'en' && path === '/') ? 'index, follow' : 'noindex, follow';
- assert(html.includes(`<html lang="${locale === 'zh' ? 'zh-CN' : locale}"`), route);
- assert.equal((html.match(/<html\b/g) || []).length, 1, route);
- assert(html.includes(`<title>${escape(publicCopy[locale][path][0])} | STRATA</title>`), route);
- assert(html.includes(`name="description" content="${escape(publicCopy[locale][path][1])}"`), route);
- assert(html.includes(`name="robots" content="${robots}"`), route);
- assert(html.includes(`rel="canonical" href="${canonical}"`), route);
- assert.equal((html.match(/rel="canonical"/g) || []).length, 1, route);
- assert(html.includes(`property="og:url" content="${canonical}"`), route);
- assert.equal((html.match(/rel="alternate" hrefLang=/g) || []).length, 8, route);
- for (const other of locales) assert(html.includes(`hrefLang="${other}" href="https://text.skin${localize(path, other)}"`), route);
- assert(html.includes(`hrefLang="x-default" href="https://text.skin${path}"`), route);
- assert.equal((html.match(/<h1\b/g) || []).length, 1, route);
- for (const target of ['/services', '/slots', '/login', '/blogs']) assert(html.includes(`href="${localize(target, locale)}"`), route);
- receipt.push({ path: route, status: 200, language: locale, canonical, robots, alternates: 8 });
- publicChecked++;
- }
- for (const path of ['/login', '/dashboard', '/dashboard/settings', '/payment/test', '/payment/confirm', '/create-order/35']) {
- const route = localize(path, locale);
- const response = await fetch(base + route);
- assert.equal(response.status, 200, route);
- assert.equal(response.headers.get('x-robots-tag'), 'noindex, nofollow', route);
- const html = await response.text();
- assert(html.includes(`<html lang="${locale === 'zh' ? 'zh-CN' : locale}"`), route);
- assert(html.includes('name="robots" content="noindex, nofollow"'), route);
- assert(html.includes(`rel="canonical" href="https://text.skin${route}"`), route);
- assert.equal((html.match(/rel="alternate" hrefLang=/g) || []).length, 0, route);
- receipt.push({ path: route, status: 200, language: locale, robots: 'noindex, nofollow', private: true });
- privateChecked++;
- }
- const query = await fetch(base + localize('/', locale) + '?utm_source=qa');
- assert.equal(query.status, 200);
- assert((await query.text()).includes(`rel="canonical" href="https://text.skin${localize('/', locale)}"`), 'Query leaked into canonical');
- }
- const admin = await fetch(base + '/admin');
- assert.equal(admin.status, 200);
- assert.equal(admin.headers.get('x-robots-tag'), 'noindex, nofollow');
- for (const route of ['/en', '/en/services', '/xx', '/fr/admin', '/de/not-a-page', '/fr/services/missing']) {
- const response = await fetch(base + route); assert.equal(response.status, 404, route);
- assert((await response.text()).includes('noindex'), '404 must be non-indexable: ' + route);
- }
- const spoof = await fetch(base + '/fr/services', { headers: { 'x-strata-locale': 'zh', 'x-strata-path': '/' } });
- assert((await spoof.text()).includes('<html lang="fr"'), 'Client headers must not override URL language');
- const sitemapResponse = await fetch(`${base}/sitemap.xml`);
- assert.equal(sitemapResponse.status, 200, 'Sitemap response');
- const sitemap = await sitemapResponse.text();
- const urls = [...sitemap.matchAll(/<loc>(.*?)<\/loc>/g)].map(m => m[1]);
- assert.equal(urls.length, indexing ? publicPaths.length * locales.length + published.length + new Set(published.map(a => a.locale)).size : 0);
- if (indexing) {
- const expectedUrls = [...locales.flatMap(locale => publicPaths.map(path => 'https://text.skin' + localize(path, locale))), ...new Set(approvedInventory.map(a => `https://text.skin${indexFor(a.locale)}`)), ...approvedInventory.map(a => `https://text.skin${pathFor(a)}`)].sort();
- assert.equal(expectedUrls.length, 84, 'Local indexing-enabled scope is 56 public pages and 28 blog pages; not production approval');
- assert.deepEqual([...urls].sort(), expectedUrls, 'Sitemap must exactly match approved multilingual cohort');
- }
- for (const url of urls) assert(url.startsWith('https://text.skin/') && !/\/(?:admin|login|dashboard|payment|create-order)(?:\/|$)/.test(url));
- const robotsResponse = await fetch(`${base}/robots.txt`);
- assert.equal(robotsResponse.status, 200, 'Robots response');
- const robots = await robotsResponse.text();
- const iconResponse = await fetch(`${base}/blog-icon.svg`);
- assert.equal(iconResponse.status, 200, 'Blog icon response');
- assert(iconResponse.headers.get('content-type')?.includes('image/svg+xml'), 'Blog icon MIME type');
- assert(robots.includes('Disallow: /api/'));
- assert(!/Disallow: \/(?:blogs|admin|dashboard|login|payment|create-order)/.test(robots));
- if (process.env.BLOG_HTTP_RECEIPT) fs.writeFileSync(process.env.BLOG_HTTP_RECEIPT, JSON.stringify({ base, indexing, pages: receipt, sitemapUrls: urls, publication: 'Local build verification only; no production approval or deployment' }, null, 2) + '\n');
- console.log(`PASS: ${publicChecked} public and ${privateChecked} private localized pages, admin exclusions and ${checked} server-rendered blog pages; language, metadata, sources, structured data; excluded/unknown routes; query canonicals; private headers; sitemap (${urls.length} URLs) and robots.`);
|