Add manual test for PIS endpoint
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -20,11 +20,24 @@ export class BaseClient {
|
||||
: `${root}/api/v3`;
|
||||
}
|
||||
|
||||
public async ping(): Promise<boolean> {
|
||||
try {
|
||||
await fetch(this.baseUrl, {
|
||||
method: 'HEAD',
|
||||
signal: AbortSignal.timeout(3000)
|
||||
});
|
||||
return true
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the Envelope logic
|
||||
*/
|
||||
public async request<T>(path: string, options: RequestInit = {}): Promise<ApiResult<T>> {
|
||||
const url = `${this.baseUrl}${path}`;
|
||||
console.debug(`[API DEBUG] Calling: ${url}`);
|
||||
|
||||
const headers = new Headers(options.headers);
|
||||
headers.set('Content-Type', 'application/json');
|
||||
|
||||
@@ -5,7 +5,7 @@ export class PisModule {
|
||||
constructor(private client: BaseClient) {}
|
||||
|
||||
async getByStartEndCrs(startCrs: string, endCrs: string): Promise<ApiResult<ApiPisObject.PisObjects>> {
|
||||
const path = `/pis/route/${encodeURIComponent(startCrs.toUpperCase())}/${encodeURIComponent(endCrs.toUpperCase())}`;
|
||||
const path = `/pis/route/${encodeURIComponent(startCrs.toLowerCase())}/${encodeURIComponent(endCrs.toLowerCase())}`;
|
||||
|
||||
return this.client.request<ApiPisObject.PisObjects>(path, {
|
||||
method: 'GET',
|
||||
|
||||
49
tests/manual/pis.ts
Normal file
49
tests/manual/pis.ts
Normal file
@@ -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();
|
||||
Reference in New Issue
Block a user