// tests/paloalto.urls.test.js // // Pure unit tests for integrations/paloalto/urls.js — no HTTP, no // mocks. The builders here feed deep-link markdown into user-facing // output, so any silent format change would show up as broken links // in production. The tests spell out both the exact URL shape and // the boundary conditions (null ids, base-URL env override). import test from 'node:test'; import assert from 'node:assert/strict'; import { getPrismaUiBaseUrl, buildAppDetailsUrl, } from '../integrations/paloalto/urls.js'; function withEnv(kvs, fn) { const prev = {}; for (const k of Object.keys(kvs)) prev[k] = process.env[k]; try { for (const [k, v] of Object.entries(kvs)) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } return fn(); } finally { for (const [k, v] of Object.entries(prev)) { if (v === undefined) delete process.env[k]; else process.env[k] = v; } } } test('getPrismaUiBaseUrl: defaults to the production SCM hostname', () => { withEnv({ PRISMA_UI_BASE_URL: undefined }, () => { assert.equal(getPrismaUiBaseUrl(), 'https://stratacloudmanager.paloaltonetworks.com'); }); }); test('getPrismaUiBaseUrl: PRISMA_UI_BASE_URL override is honored', () => { withEnv({ PRISMA_UI_BASE_URL: 'https://scm.partner.example.com' }, () => { assert.equal(getPrismaUiBaseUrl(), 'https://scm.partner.example.com'); }); }); test('getPrismaUiBaseUrl: trailing slashes are stripped so `${base}/x` concats cleanly', () => { // A trailing slash would produce "//insights/…" which some routers // treat as a different route from "/insights/…". Normalize. withEnv({ PRISMA_UI_BASE_URL: 'https://scm.example.com///' }, () => { assert.equal(getPrismaUiBaseUrl(), 'https://scm.example.com'); }); }); test('getPrismaUiBaseUrl: empty / whitespace env falls back to default', () => { withEnv({ PRISMA_UI_BASE_URL: ' ' }, () => { assert.equal(getPrismaUiBaseUrl(), 'https://stratacloudmanager.paloaltonetworks.com'); }); }); test('buildAppDetailsUrl: builds the exact SCM Application Path Details URL', () => { // Ground truth from the user (CG00127 + rtp-base app). withEnv({ PRISMA_UI_BASE_URL: undefined }, () => { const url = buildAppDetailsUrl('16190109915660160', '15932000365560116'); assert.equal( url, 'https://stratacloudmanager.paloaltonetworks.com/insights/operational/sdwan-applications/15932000365560116/site/16190109915660160/details', ); }); }); test('buildAppDetailsUrl: null / missing ids → null (renderers no-op on falsy)', () => { assert.equal(buildAppDetailsUrl(null, '15932000365560116'), null); assert.equal(buildAppDetailsUrl('16190109915660160', null), null); assert.equal(buildAppDetailsUrl(null, null), null); assert.equal(buildAppDetailsUrl('', ''), null); }); test('buildAppDetailsUrl: numeric ids coerced to strings in the URL (Prisma ids are int-like)', () => { withEnv({ PRISMA_UI_BASE_URL: 'https://scm.example.com' }, () => { const url = buildAppDetailsUrl(16190109915660160n, 15932000365560116n); assert.match(url, /15932000365560116\/site\/16190109915660160\/details$/); }); });