Skip to content

Commit c7c851d

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

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/http.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.Unauthorized).toBe(401)
11+
expect(HttpCode.LargePayload).toBe(413)
12+
expect(HttpCode.ServerError).toBe(500)
13+
})
14+
})
15+
16+
describe("HttpError", () => {
17+
it("should work as expected", () => {
18+
const message = "Bad request from client"
19+
const httpError = new HttpError(message, HttpCode.BadRequest)
20+
21+
expect(httpError.message).toBe(message)
22+
expect(httpError.status).toBe(400)
23+
expect(httpError.details).toBeUndefined()
24+
})
25+
it("should have details if provided", () => {
26+
const details = {
27+
message: "User needs to be signed-in in order to perform action",
28+
}
29+
const message = "Unauthorized"
30+
const httpError = new HttpError(message, HttpCode.BadRequest, details)
31+
32+
expect(httpError.details).toStrictEqual(details)
33+
})
34+
})
35+
})

0 commit comments

Comments
 (0)