feat: finalize mindspace service extraction phase a
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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: 'mm.tkmind.cn', forwardedProto: 'http', protocol: 'http' }),
|
||||
'https://mm.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://mm.tkmind.cn',
|
||||
requestPath: '/MindSpace/user-1/public/report.html?x=1',
|
||||
filePath: '/tmp/MindSpace/user-1/public/report.html',
|
||||
});
|
||||
assert.equal(direct.pageUrl, 'https://mm.tkmind.cn/MindSpace/user-1/public/report.html');
|
||||
assert.equal(direct.pageDirUrl, 'https://mm.tkmind.cn/MindSpace/user-1/public/');
|
||||
|
||||
const implicit = buildPublishedHtmlViewContext({
|
||||
origin: 'https://mm.tkmind.cn',
|
||||
requestPath: '/MindSpace/user-1/public/report',
|
||||
filePath: '/tmp/MindSpace/user-1/public/index.html',
|
||||
});
|
||||
assert.equal(implicit.pageUrl, 'https://mm.tkmind.cn/MindSpace/user-1/public/report/');
|
||||
assert.equal(implicit.pageDirUrl, 'https://mm.tkmind.cn/MindSpace/user-1/public/report/');
|
||||
});
|
||||
|
||||
test('buildPublishedHtmlViewContext adds thumbnail png fallback when svg sibling exists', () => {
|
||||
const context = buildPublishedHtmlViewContext({
|
||||
origin: 'https://mm.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://mm.tkmind.cn/MindSpace/user-1/public/report.thumbnail.png',
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user