47 lines
2.0 KiB
JavaScript
47 lines
2.0 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { buildPublishedHtmlViewContext, resolvePublicRequestOrigin } from './mindspace-public-page-context.mjs';
|
|
|
|
test('resolvePublicRequestOrigin prefers https for public hosts and forwarded proto for local hosts', () => {
|
|
assert.equal(
|
|
resolvePublicRequestOrigin({ hostHeader: 'm.tkmind.cn', forwardedProto: 'http', protocol: 'http' }),
|
|
'https://m.tkmind.cn',
|
|
);
|
|
assert.equal(
|
|
resolvePublicRequestOrigin({ hostHeader: '127.0.0.1:8081', forwardedProto: 'http', protocol: 'https' }),
|
|
'http://127.0.0.1:8081',
|
|
);
|
|
});
|
|
|
|
test('buildPublishedHtmlViewContext builds file and directory page urls', () => {
|
|
const direct = buildPublishedHtmlViewContext({
|
|
origin: 'https://m.tkmind.cn',
|
|
requestPath: '/MindSpace/user-1/public/report.html?x=1',
|
|
filePath: '/tmp/MindSpace/user-1/public/report.html',
|
|
});
|
|
assert.equal(direct.pageUrl, 'https://m.tkmind.cn/MindSpace/user-1/public/report.html');
|
|
assert.equal(direct.pageDirUrl, 'https://m.tkmind.cn/MindSpace/user-1/public/');
|
|
|
|
const implicit = buildPublishedHtmlViewContext({
|
|
origin: 'https://m.tkmind.cn',
|
|
requestPath: '/MindSpace/user-1/public/report',
|
|
filePath: '/tmp/MindSpace/user-1/public/index.html',
|
|
});
|
|
assert.equal(implicit.pageUrl, 'https://m.tkmind.cn/MindSpace/user-1/public/report/');
|
|
assert.equal(implicit.pageDirUrl, 'https://m.tkmind.cn/MindSpace/user-1/public/report/');
|
|
});
|
|
|
|
test('buildPublishedHtmlViewContext adds thumbnail png fallback when svg sibling exists', () => {
|
|
const context = buildPublishedHtmlViewContext({
|
|
origin: 'https://m.tkmind.cn',
|
|
requestPath: '/MindSpace/user-1/public/report.html',
|
|
filePath: '/tmp/MindSpace/user-1/public/report.html',
|
|
fileExists: (value) => value.endsWith('.thumbnail.svg'),
|
|
thumbnailPngPathForSvg: (value) => value.replace('.svg', '.png'),
|
|
});
|
|
assert.equal(
|
|
context.fallbackImageUrl,
|
|
'https://m.tkmind.cn/MindSpace/user-1/public/report.thumbnail.png',
|
|
);
|
|
});
|