aboutsummaryrefslogtreecommitdiff
path: root/modules/test/test-download-url.js
blob: 63cabdea1ddb9466cf4fe6b8c1d8cc0532fa6d88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// node modules/test/test-download-url.js
// Regression guard for the download/share URL space (2026-10-21).
// The URL must follow the WebDAV config (the logged-in user's space), NOT the
// page path — /spaces/newos4/ is the app, not the user.
const cases = [
  { page: '/spaces/newos4/', cfg: 'https://webx11.duckdns.org/spaces/agando/', want: 'agando' },
  { page: '/spaces/newos4/', cfg: 'https://webx11.duckdns.org/spaces/mindtech/', want: 'mindtech' },
  { page: '/spaces/agando/', cfg: 'https://webx11.duckdns.org/spaces/agando/', want: 'agando' },
  { page: '/spaces/newos4/', cfg: '', want: 'newos4' }, // no config → fall back to the page space
];

function detectSpaceName(path) {
  const parts = path.split('/').filter(Boolean);
  const i = parts.indexOf('spaces');
  return (i >= 0 && i + 1 < parts.length) ? parts[i + 1] : '';
}
function extractSpaceNameFromUrl(url) {
  if (!url) return '';
  const parts = new URL(url).pathname.split('/').filter(Boolean);
  const i = parts.indexOf('spaces');
  return (i >= 0 && i + 1 < parts.length) ? parts[i + 1] : '';
}

let bad = 0;
for (const c of cases) {
  const got = extractSpaceNameFromUrl(c.cfg) || detectSpaceName(c.page);
  const ok = got === c.want;
  if (!ok) bad++;
  console.log((ok ? 'PASS' : 'FAIL'), c.page, 'cfg=' + (c.cfg || '(none)'), '→', got, '(want', c.want + ')');
}
console.log(bad ? `\n${bad} FAILED` : `\n${cases.length} PASS`);
process.exit(bad ? 1 : 0);