-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexceptions.spec.ts
41 lines (38 loc) · 1.13 KB
/
exceptions.spec.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
import type { RestResponse } from "@rc-ex/core/types";
import RestException from "@rc-ex/core/RestException";
import { describe, expect, test } from "vitest";
import ReusableRestClient from "./reusable-rest-client";
describe("Exceptions", () => {
test("400", async () => {
const rc = await ReusableRestClient.getInstance();
let exception = false;
try {
// no to number
await rc.restapi().account().extension().sms().post({
text: "Hello world",
});
} catch (e) {
exception = true;
const re = e as { response: RestResponse };
expect(re.response.status).toBe(400);
} finally {
expect(exception).toBeTruthy();
}
});
test("404", async () => {
const rc = await ReusableRestClient.getInstance();
let exception = false;
try {
await rc.post(
`${rc.restapi().account().extension().path(true)}/does-not-exist`,
{ text: "Hello world" },
);
} catch (e) {
exception = true;
const re = e as { response: RestResponse };
expect(re.response.status).toBe(404);
} finally {
expect(exception).toBeTruthy();
}
});
});