Skip to content

Instantly share code, notes, and snippets.

@intech
Created April 18, 2019 21:18
Show Gist options
  • Select an option

  • Save intech/e2e47310a8a48c766c1472272c5ba802 to your computer and use it in GitHub Desktop.

Select an option

Save intech/e2e47310a8a48c766c1472272c5ba802 to your computer and use it in GitHub Desktop.
describe("Test route.path and aliases", () => {
let broker;
let app;
let service;
let nextHandler = jest.fn((req, res) => res.sendStatus(200));
beforeAll(() => {
broker = new ServiceBroker({ logger: false });
service = broker.createService(ApiGateway, {
settings: {
path: "/api",
routes: [{
path: "/te",
aliases: {
"GET test"(req, res) {
res.end("/api/te/test");
}
}
},{
path: "",
aliases: {
"GET test"(req, res) {
res.end("/api/test");
}
}
}]
}
});
return broker.start();
});
afterAll(() => {
return broker.stop();
});
it("GET /api/te/test", () => {
return request(service.server)
.get("/api/te/test")
.then(res => {
console.log(res.body);
expect(res.statusCode).toBe(200);
expect(res.text).toBe("/api/te/test");
expect(nextHandler).toHaveBeenCalledTimes(0);
});
});
it("GET /api/test", () => {
return request(service.server)
.get("/api/test")
.then(res => {
console.log(res.body);
expect(res.statusCode).toBe(200);
expect(res.text).toBe("/api/test");
expect(nextHandler).toHaveBeenCalledTimes(0);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment