fde6503bdf
Memind CI / Test, build, and release guards (push) Has been cancelled
Enable optional SEO/GEO injection and discovery routes for confirmed public pages while keeping private pages noindex. Add premium page template skills, portal catalog API, template shop UI, and Baidu push gated by memind_adm config. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import express from 'express';
|
|
import { attachPortalSeoDiscoveryRoutes } from './portal-seo-discovery-routes.mjs';
|
|
|
|
function createApp(deps) {
|
|
const app = express();
|
|
attachPortalSeoDiscoveryRoutes(app, deps);
|
|
return app;
|
|
}
|
|
|
|
async function getText(app, path) {
|
|
const server = app.listen(0);
|
|
try {
|
|
const { port } = server.address();
|
|
const response = await fetch(`http://127.0.0.1:${port}${path}`);
|
|
const body = await response.text();
|
|
return { status: response.status, body };
|
|
} finally {
|
|
await new Promise((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
|
|
}
|
|
}
|
|
|
|
test('GET /robots.txt returns closed policy when disabled', async () => {
|
|
const app = createApp({
|
|
getMindSpaceConfig: async () => ({ seoGeo: { enabled: false } }),
|
|
});
|
|
const result = await getText(app, '/robots.txt');
|
|
assert.equal(result.status, 200);
|
|
assert.match(result.body, /Disallow: \//);
|
|
});
|
|
|
|
test('GET /sitemap.xml returns 404 when sitemap disabled', async () => {
|
|
const app = createApp({
|
|
getMindSpaceConfig: async () => ({
|
|
seoGeo: { enabled: true, seo: { enabled: true, sitemap: false } },
|
|
}),
|
|
});
|
|
const result = await getText(app, '/sitemap.xml');
|
|
assert.equal(result.status, 404);
|
|
});
|
|
|
|
test('GET /sitemap.xml renders xml when enabled', async () => {
|
|
const app = createApp({
|
|
getAuthPool: () => ({}),
|
|
getMindSpaceConfig: async () => ({
|
|
seoGeo: { enabled: true, seo: { enabled: true, sitemap: true } },
|
|
}),
|
|
getSeoDiscoveryService: () => ({
|
|
listIndexablePublications: async () => [
|
|
{ publicUrl: '/u/john/pages/demo', updatedAt: Date.now() },
|
|
],
|
|
renderSitemapXml: (entries, ctx) =>
|
|
`<urlset origin="${ctx.origin}">${entries.length}</urlset>`,
|
|
}),
|
|
resolveRequestOrigin: () => 'https://m.tkmind.cn',
|
|
});
|
|
const result = await getText(app, '/sitemap.xml');
|
|
assert.equal(result.status, 200);
|
|
assert.match(result.body, /origin="https:\/\/m\.tkmind\.cn">1<\/urlset>/);
|
|
});
|