Hi Scott!
Yes, you’re right. Sorry for the confusion. I was mixed up between the tests that use notehub-js
vs a direct API call and getRoutes vs getRoute. I do see the route schema when fetching a single route via the API, but unfortunately not via notehub-js
.
Here’s some test code that runs the same tests using notehub-js
and axios
http client.
// const projectUID, email, pwd, routeID = ...;
const notehubjs = require("@blues-inc/notehub-js");
import * as axios from "axios";
describe("Notehub API", () => {
let session_token: string;
beforeAll(async () => { // get an authorization token
let authorizationApi = new notehubjs.AuthorizationApi();
let loginRequest = { "username": email, "password": pwd };
const result = await authorizationApi.login(loginRequest);
expect(result).toHaveProperty("session_token");
session_token = result.session_token;
expect(session_token).toBeTruthy;
});
function getRouteWithNotehubJS() {
return async function() {
let routeApi = new notehubjs.RouteApi();
let defaultClient = notehubjs.ApiClient.instance;
const session = defaultClient.authentications['api_key'];
session.apiKey = session_token;
const route = await routeApi.getRoute(projectUID, routeUID);
return route;
};
}
function getRouteWithAxios() {
return async function() {
const endpoint = new axios.Axios({
baseURL: `https://api.notefile.net/v1`,
headers: { 'X-Session-Token': `${session_token}` }
});
const response = await endpoint.get(`/projects/${projectUID}/routes/${routeUID}`, {});
const route = JSON.parse(response.data); // todo - axios is supposed to parse json responses
return route;
}
}
describe.each([
["axios", getRouteWithAxios()],
["notehub-js", getRouteWithNotehubJS()]
])
("get route via %s", (name: string, getRoute: any) => {
let route: any;
beforeAll(async () => {
route = await getRoute();
});
describe('should retrieve route data having', () => {
it('"type" http', () => {
expect(route).toHaveProperty("type", "http");
});
it('"http" defined', () => {
expect(route).toHaveProperty("http");
});
it('"schema" not defined', () => {
// "schema" isn't a real property but a placeholder
expect(route).not.toHaveProperty("schema");
});
});
});
});
Running with these dependencies (excerpted):
"@blues-inc/notehub-js": "^1.0.19",
"jest": "^29.7.0",
"ts-jest": "^29.1.2"
The axios tests are green, but notehub-js only returns a response with the same properties as getRoutes
. The http
property for the event schema is missing even though getRoute
is being called.
The last test, checking that schema
doesn’t exist, is there since It wasn’t clear from the API docs that schema
is a placeholder property name rather than an actual property name.
Thanks!