Skip to content

Commit 7055dba

Browse files
committed
feat: add tests for src/common/http
1 parent a2a6122 commit 7055dba

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/http.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { HttpCode, HttpError } from "../src/common/http"
2+
3+
describe("http", () => {
4+
describe("HttpCode", () => {
5+
it("should return the correct HTTP codes", () => {
6+
expect(HttpCode.Ok).toBe(200)
7+
expect(HttpCode.Redirect).toBe(302)
8+
expect(HttpCode.NotFound).toBe(404)
9+
expect(HttpCode.BadRequest).toBe(400)
10+
expect(HttpCode.BadRequest).toBe(400)
11+
expect(HttpCode.Unauthorized).toBe(401)
12+
expect(HttpCode.LargePayload).toBe(413)
13+
expect(HttpCode.ServerError).toBe(500)
14+
})
15+
})
16+
17+
describe("HttpError", () => {
18+
it("should work as expected", () => {
19+
const message = "Bad request from client"
20+
const httpError = new HttpError(message, HttpCode.BadRequest)
21+
22+
expect(httpError.message).toBe(message)
23+
expect(httpError.status).toBe(400)
24+
expect(httpError.details).toBeUndefined()
25+
})
26+
it("should have details if provided", () => {
27+
const details = {
28+
message: "User needs to be signed-in in order to perform action",
29+
}
30+
const message = "Unauthorized"
31+
const httpError = new HttpError(message, HttpCode.BadRequest, details)
32+
33+
expect(httpError.details).toStrictEqual(details)
34+
})
35+
})
36+
})

0 commit comments

Comments
 (0)