Files
meshcore-analyzer/tests/unit/test-issue-1836-crossnav-case-normalization.js
Alex B 893773338e chore(tests): move root test-*.js into tests/unit and tests/e2e (#2036)
Moves 290 root test-*.js into tests/unit (177, listed in test-all.sh) and tests/e2e (113, classified in scripts/non-unit-tests.json), per #1981 and PR-D of #1385. Root goes from 348 entries to 48. test-all.sh and test-fixtures/ stay put. The inventory guard now fails if a test reappears in the root or sits in the wrong folder.

Verified independently of the diff: the invoked sets are unchanged (test-all.sh 177 before and after, deploy.yml 96 before and after, both identical as sets), and a full local run of test-all.sh on master and on the branch produced 4702 output lines each whose only differences are absolute paths, stack-trace line numbers shifted by the REPO_ROOT line, the inventory wording and two perf ratios. The guard was mutation-checked: a test back in the root, a unit suite in tests/e2e, and a suite dropped from test-all.sh each make it exit 1. CI run 35246304316 ran 97 suites from tests/e2e and is green.

Follow-up 9335c51d finished the instruction files: no bare root test command is left in AGENTS.md, the squad charters, .github or docs, and every tests/ path they name resolves.

Merged by the interim maintainer without a second human reviewer: CI and the local runs above are the independent checks.

Known and deliberately out of scope: 18 of the 113 files in tests/e2e are invoked by no runner at all, and one of them cannot run anywhere because it requires jsdom, which is not a declared dependency. Tracked separately.
2026-09-17 19:06:07 +02:00

47 lines
1.9 KiB
JavaScript

/* test-issue-1836-crossnav-case-normalization.js — Issue #1836 regression test.
*
* The cross-navigation links introduced in PR #1826 return 404 because pubkeys
* are stored lowercase in the `nodes` table and uppercase in the `observers`
* table, and the backend WHERE clauses are case-sensitive. The frontend link
* builders must normalize the case of the pubkey/id when linking across.
*
* - public/observer-detail.js: observer → node link must lowercase currentId.
* - public/nodes.js: node → observer link must uppercase n.public_key.
*
* Static-source test (grep the file text). No server, no DOM.
*/
'use strict';
const REPO_ROOT = require('path').resolve(__dirname, '..', '..');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
let passed = 0, failed = 0;
function test(name, fn) {
try { fn(); passed++; console.log(` \u2713 ${name}`); }
catch (e) { failed++; console.log(` \u2717 ${name}\n ${e.message}`); }
}
console.log('\u2500\u2500 Cross-nav case normalization (#1836) \u2500\u2500');
const obsSrc = fs.readFileSync(path.join(REPO_ROOT, 'public', 'observer-detail.js'), 'utf8');
const nodesSrc = fs.readFileSync(path.join(REPO_ROOT, 'public', 'nodes.js'), 'utf8');
test('observer-detail.js observer→node href lowercases currentId', () => {
assert.ok(
/href="#\/nodes\/\$\{encodeURIComponent\(currentId\.toLowerCase\(\)\)\}"/.test(obsSrc),
'expected href="#/nodes/${encodeURIComponent(currentId.toLowerCase())}" in observer-detail.js'
);
});
test('nodes.js node→observer href uppercases n.public_key', () => {
assert.ok(
/href="#\/observers\/\$\{encodeURIComponent\(n\.public_key\.toUpperCase\(\)\)\}"/.test(nodesSrc),
'expected href="#/observers/${encodeURIComponent(n.public_key.toUpperCase())}" in nodes.js'
);
});
console.log(`\n${passed} passed, ${failed} failed`);
process.exit(failed ? 1 : 0);