UNPKG

popsicle-status

Version:

Popsicle middleware for rejecting responses with bad HTTP statuses

46 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const node_1 = require("servie/dist/node"); const index_1 = require("./index"); describe("popsicle status", () => { const req = new node_1.Request("/"); describe("2xx", () => { const transport = async () => new node_1.Response(null, { status: 200 }); it("should resolve by default", async () => { const send = index_1.status(); const res = await send(req, transport); expect(res.status).toEqual(200); }); it("should reject out of bounds responses", async () => { const send = index_1.status(100, 200); try { const res = await send(req, transport); } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.status).toEqual(200); expect(e.code).toEqual("EINVALIDSTATUS"); } expect.hasAssertions(); }); }); describe("5xx", () => { const transport = async () => new node_1.Response(null, { status: 500 }); it("should reject by default", async () => { try { await index_1.status()(req, transport); } catch (e) { expect(e).toBeInstanceOf(Error); expect(e.status).toEqual(500); expect(e.code).toEqual("EINVALIDSTATUS"); } expect.hasAssertions(); }); it("should be accepted when within range", async () => { const res = await index_1.status(200, 600)(req, transport); expect(res.status).toEqual(500); }); }); }); //# sourceMappingURL=index.spec.js.map