From edca2698a75845c045894da19ae464d80d923e87 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 21 Feb 2026 11:17:01 +0000 Subject: [PATCH] Add manual test for PIS endpoint --- package.json | 3 ++- src/lib/base.ts | 13 ++++++++++++ src/modules/pis.ts | 2 +- tests/manual/pis.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/manual/pis.ts diff --git a/package.json b/package.json index ae8433c..980c2b6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "tsc" + "build": "tsc", + "test-pis": "NODE_TLS_REJECT_UNAUTHORIZED=0 tsx tests/manual/pis.ts" }, "repository": { "type": "git", diff --git a/src/lib/base.ts b/src/lib/base.ts index a7c0902..5cf190a 100644 --- a/src/lib/base.ts +++ b/src/lib/base.ts @@ -20,11 +20,24 @@ export class BaseClient { : `${root}/api/v3`; } + public async ping(): Promise { + try { + await fetch(this.baseUrl, { + method: 'HEAD', + signal: AbortSignal.timeout(3000) + }); + return true + } catch (err) { + return false; + } + } + /** * Handles the Envelope logic */ public async request(path: string, options: RequestInit = {}): Promise> { const url = `${this.baseUrl}${path}`; + console.debug(`[API DEBUG] Calling: ${url}`); const headers = new Headers(options.headers); headers.set('Content-Type', 'application/json'); diff --git a/src/modules/pis.ts b/src/modules/pis.ts index 46f8137..4a15973 100644 --- a/src/modules/pis.ts +++ b/src/modules/pis.ts @@ -5,7 +5,7 @@ export class PisModule { constructor(private client: BaseClient) {} async getByStartEndCrs(startCrs: string, endCrs: string): Promise> { - const path = `/pis/route/${encodeURIComponent(startCrs.toUpperCase())}/${encodeURIComponent(endCrs.toUpperCase())}`; + const path = `/pis/route/${encodeURIComponent(startCrs.toLowerCase())}/${encodeURIComponent(endCrs.toLowerCase())}`; return this.client.request(path, { method: 'GET', diff --git a/tests/manual/pis.ts b/tests/manual/pis.ts new file mode 100644 index 0000000..6554b51 --- /dev/null +++ b/tests/manual/pis.ts @@ -0,0 +1,49 @@ +import { OwlBoardClient } from '../../src/lib/client'; +import { ApiError } from '../../src/lib/errors'; + +console.log("Manual PIS Tests are running") + +const TEST_SERVER: string = "https://owlboard.rke2-gw.svc.fjla.net" +console.log(`Using TEST_SERVER: ${TEST_SERVER}`) + +const api = new OwlBoardClient(TEST_SERVER); + +async function main() { +// Test server reachability +console.log("Testing server reachability") +if (!(await api.ping())) { + console.error('Server not reachable. Check it is running and is reachable at the provided address') + process.exit(1); +} + +console.log("Server is reachable. Running tests...") + +// Run code here. + +{ + // Test PIS Route + const start = 'bri'; + const end = 'svb'; + + console.log(`Querying PIS Route: ${start} > ${end}...`); + try { + const {data, producedAt} = await api.pis.getByStartEndCrs(start, end); + console.log('\n---Response Success---'); + console.log(`Data Produced At: ${producedAt.toLocaleTimeString()}`); + + console.log(JSON.stringify(data)); + } catch (err) { + if (err instanceof ApiError) { + console.error('\n--- API Error ---'); + console.error(`Code: ${err.code}`); + console.error(`Msg: ${err.message}`); + console.error(`Status: ${err.status}`); + } else { + console.error(`Unknown Error: ${err}`) + } + } +} + +}; + +main(); \ No newline at end of file