Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): add unit tests for src/common/http #2702

Merged
merged 1 commit into from Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
})
})