Merge pull request #2702 from cdr/add-unit-tests-http

feat(testing): add unit tests for src/common/http
This commit is contained in:
Joe Previte 2021-02-10 10:57:16 -07:00 committed by GitHub
commit f1337d53c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

35
test/http.test.ts Normal file
View File

@ -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)
})
})
})