forked from smart-on-fhir/client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpError.test.ts
86 lines (78 loc) · 3.06 KB
/
HttpError.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { expect } from "@hapi/code";
import * as Lab from "@hapi/lab";
import HttpError from "../src/HttpError";
export const lab = Lab.script();
const { it, describe } = lab;
describe("HttpError", () => {
it ("create with no args", () => {
const error = HttpError.create();
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Unknown error");
expect(error.statusCode).to.equal(0);
expect(error.status).to.equal(0);
expect(error.statusText).to.equal("Error");
});
it ("create from string", () => {
const error = HttpError.create("Test Error");
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Test Error");
expect(error.statusCode).to.equal(0);
expect(error.status).to.equal(0);
expect(error.statusText).to.equal("Error");
expect(JSON.stringify(error)).to.equal(JSON.stringify({
name : "HttpError",
statusCode: 0,
status : 0,
statusText: "Error",
message : "Test Error"
}));
});
it ("create from Error", () => {
const error = HttpError.create(new Error("Test Error"));
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Test Error");
expect(error.statusCode).to.equal(0);
expect(error.status).to.equal(0);
expect(error.statusText).to.equal("Error");
});
it ("create from response object having error property", () => {
const error = HttpError.create({
error: {
status: 404,
statusText: "Not Found",
responseText: "Test Error"
}
});
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Test Error");
expect(error.statusCode).to.equal(404);
expect(error.status).to.equal(404);
expect(error.statusText).to.equal("Not Found");
});
it ("create from incompatible object", () => {
// @ts-ignore
const error = HttpError.create({ error: "test" });
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Unknown error");
expect(error.statusCode).to.equal(0);
expect(error.status).to.equal(0);
expect(error.statusText).to.equal("Error");
});
it ("create from empty object", () => {
const error = HttpError.create({});
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Unknown error");
expect(error.statusCode).to.equal(0);
expect(error.status).to.equal(0);
expect(error.statusText).to.equal("Error");
});
it ("create from incompatible argument", () => {
// @ts-ignore
const error = HttpError.create(true);
expect(error.name).to.equal("HttpError");
expect(error.message).to.equal("Unknown error");
expect(error.statusCode).to.equal(0);
expect(error.status).to.equal(0);
expect(error.statusText).to.equal("Error");
});
});