Skip to content

Commit

Permalink
feat: add tests for src/common/http
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjoeio committed Feb 9, 2021
1 parent a2a6122 commit c7c851d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 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)
})
})
})

0 comments on commit c7c851d

Please sign in to comment.