FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(testing): add unit tests for src/common/http by jsjoeio · Pull Request #2702 · coder/code-server · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
35 changes: 35 additions & 0 deletions test/http.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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)
})
})
})

Back | FazBrowse Home | New Git URL