import { OwlBoardClient } from '../../src/lib/client'; import { ApiError, ValidationError } 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(`Number of entries in response: ${data.length}`); 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 if (err instanceof ValidationError) { console.error('\n--- Local Validation Error ---'); console.error(`Error Field: ${err.field}`); console.error(`Message: ${err.reason}`); console.error(`Request not sent`); } else { console.error(`Unknown Error: ${err}`) } } } // Test PIS Code { const code = 5001; console.log(`Querying PIS Code: ${code}`); try { const {data, producedAt} = await api.pis.getByCode(code.toString()); console.log("\n--- Response Success ---"); console.log(`Data produced at: ${producedAt.toLocaleString()}`); console.log(`Number of results: ${data.length}`); 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 if (err instanceof ValidationError) { console.error('\n--- Local Validation Error ---'); console.error(`Error Field: ${err.field}`); console.error(`Message: ${err.reason}`); console.error(`Request not sent`); } else { console.error(`Unknown Error: ${err}`) } } } }; main();