From c7c851dd0198d1e00d5b18558b7aad7485e53224 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 9 Feb 2021 10:57:05 -0700 Subject: [PATCH] feat: add tests for src/common/http --- test/http.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/http.test.ts diff --git a/test/http.test.ts b/test/http.test.ts new file mode 100644 index 000000000..234fca0dd --- /dev/null +++ b/test/http.test.ts @@ -0,0 +1,35 @@ +import { HttpCode, HttpError } from "../src/common/http" + +describe("http", () => { + describe("HttpCode", () => { + it("should return the correct HTTP codes", () => { + expect(HttpCode.Ok).toBe(200) + expect(HttpCode.Redirect).toBe(302) + expect(HttpCode.NotFound).toBe(404) + expect(HttpCode.BadRequest).toBe(400) + expect(HttpCode.Unauthorized).toBe(401) + expect(HttpCode.LargePayload).toBe(413) + expect(HttpCode.ServerError).toBe(500) + }) + }) + + describe("HttpError", () => { + it("should work as expected", () => { + const message = "Bad request from client" + const httpError = new HttpError(message, HttpCode.BadRequest) + + expect(httpError.message).toBe(message) + expect(httpError.status).toBe(400) + expect(httpError.details).toBeUndefined() + }) + it("should have details if provided", () => { + const details = { + message: "User needs to be signed-in in order to perform action", + } + const message = "Unauthorized" + const httpError = new HttpError(message, HttpCode.BadRequest, details) + + expect(httpError.details).toStrictEqual(details) + }) + }) +})