probot/test/server.test.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Application, NextFunction, Request, Response } from "express";
import request from "supertest";
import { getLog } from "../src/helpers/get-log";
import { createServer } from "../src/server/create-server";
2017-08-01 01:34:28 +08:00
describe("server", () => {
let server: Application;
let webhook: any;
2017-08-01 01:34:28 +08:00
beforeEach(() => {
webhook = jest.fn((req, res, next) => next());
server = createServer({ webhook, logger: getLog() });
// Error handler to avoid printing logs
server.use(
(error: Error, req: Request, res: Response, next: NextFunction) => {
res.status(500).send(error.message);
}
);
});
2017-08-01 01:34:28 +08:00
describe("GET /ping", () => {
it("returns a 200 response", () => {
return request(server).get("/ping").expect(200, "PONG");
});
});
2017-08-01 01:34:28 +08:00
describe("webhook handler", () => {
it("should 500 on a webhook error", () => {
webhook.mockImplementation(
(req: Request, res: Response, callback: NextFunction) =>
callback(new Error("webhook error"))
);
return request(server).post("/").expect(500);
});
});
2017-08-01 01:34:28 +08:00
describe("with an unknown url", () => {
it("responds with 404", () => {
return request(server).get("/lolnotfound").expect(404);
});
});
});