Files
memind/mindspace-seo-geo-admin-catalog.test.mjs
T
john 4e789663a1
Memind CI / Test, build, and release guards (push) Failing after 5m19s
feat(seo): index public online pages without confirmation
Drop the user_confirmed_at gate so public, online, unexpired pages can enter sitemap/llms and receive SEO/GEO tags. Defaults now enable all discovery switches; stored all-off config is still preserved until admin saves.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 15:51:48 +08:00

114 lines
3.4 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { classifyReferrerHost } from './mindspace-analytics-discovery.mjs';
import {
listAdminSeoGeoPublicationCatalog,
resolveAdminCatalogPublicUrl,
} from './mindspace-seo-geo-admin-catalog.mjs';
test('classifyReferrerHost maps search and ai referrers', () => {
assert.deepEqual(classifyReferrerHost('www.google.com'), {
discovery_channel: 'seo',
discovery_source: 'google',
});
assert.deepEqual(classifyReferrerHost('chatgpt.com'), {
discovery_channel: 'geo',
discovery_source: 'chatgpt',
});
});
test('resolveAdminCatalogPublicUrl normalizes relative public urls', () => {
assert.equal(
resolveAdminCatalogPublicUrl('/u/john/pages/demo'),
'https://m.tkmind.cn/u/john/pages/demo',
);
});
test('listAdminSeoGeoPublicationCatalog merges zero-traffic pages with view stats', async () => {
const calls = [];
const pool = {
async query(sql, params = []) {
calls.push({ sql, params });
const normalized = String(sql).replace(/\s+/g, ' ').trim();
if (normalized.startsWith('SELECT COUNT(*) AS total')) {
return [[{ total: 2 }]];
}
if (normalized.includes('FROM h5_publish_records pr') && normalized.includes('JOIN h5_users')) {
return [[
{
publicationId: 'pub-1',
pageId: 'page-1',
userId: 'user-1',
publicUrl: '/u/john/pages/demo',
accessMode: 'public',
status: 'online',
userConfirmedAt: 1000,
expiresAt: null,
publishedAt: 2000,
lifetimeViewCount: 12,
pageTitle: 'Demo',
pageSummary: 'Summary',
username: 'john',
displayName: 'John',
},
{
publicationId: 'pub-2',
pageId: 'page-2',
userId: 'user-2',
publicUrl: '/u/jane/pages/empty',
accessMode: 'public',
status: 'online',
userConfirmedAt: null,
expiresAt: null,
publishedAt: 1500,
lifetimeViewCount: 0,
pageTitle: 'Empty',
pageSummary: '',
username: 'jane',
displayName: 'Jane',
},
]];
}
if (normalized.includes('FROM h5_publication_views')) {
return [[
{
publicationId: 'pub-1',
device_type: 'desktop',
referrer_host: 'www.google.com',
views: 3,
},
{
publicationId: 'pub-1',
device_type: 'bot',
referrer_host: null,
views: 2,
},
]];
}
return [[]];
},
};
const result = await listAdminSeoGeoPublicationCatalog(pool, {
page: 1,
pageSize: 10,
startAt: 1,
endAt: 9_999_999_999_999,
sortBy: 'totalViews',
sortOrder: 'desc',
});
assert.equal(result.total, 2);
assert.equal(result.data.length, 2);
assert.equal(result.data[0].publicationId, 'pub-1');
assert.equal(result.data[0].seoViews, 3);
assert.equal(result.data[0].crawlerViews, 2);
assert.equal(result.data[0].totalViews, 5);
assert.equal(result.data[0].indexable, true);
assert.equal(result.data[1].publicationId, 'pub-2');
assert.equal(result.data[1].totalViews, 0);
assert.equal(result.data[1].indexable, true);
assert.match(result.data[1].publicUrl, /^https:\/\/m\.tkmind\.cn\//);
});