-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlow-level-api.spec.ts
57 lines (55 loc) · 1.72 KB
/
low-level-api.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Utils from "@rc-ex/core/Utils";
import type FaxResponse from "@rc-ex/core/definitions/FaxResponse";
import type GetSMSMessageInfoResponse from "@rc-ex/core/definitions/GetSMSMessageInfoResponse";
import fs from "fs";
import path from "path";
import { describe, expect, test } from "vitest";
import ReusableRestClient from "./reusable-rest-client";
describe("low level API", () => {
test("sms", async () => {
const rc = await ReusableRestClient.getInstance();
const r = await rc.post<GetSMSMessageInfoResponse>(
"/restapi/v1.0/account/~/extension/~/sms",
{
from: {
phoneNumber: process.env.RINGCENTRAL_SENDER!,
},
to: [
{
phoneNumber: process.env.RINGCENTRAL_RECEIVER,
},
],
text: "hello world",
},
);
const messageInfo = r.data;
expect(messageInfo).not.toBeUndefined();
expect(messageInfo.id).not.toBeUndefined();
});
test("fax", async () => {
const rc = await ReusableRestClient.getInstance();
const requestBody = {
to: [{ phoneNumber: process.env.RINGCENTRAL_RECEIVER }],
attachments: [
{
filename: "test.txt",
content: "hello world",
contentType: "text/plain",
},
{
filename: "test.png",
content: fs.createReadStream(path.join(__dirname, "test.png")),
contentType: "image/png",
},
],
};
const formData = await Utils.getFormData(requestBody);
const r = await rc.post<FaxResponse>(
"/restapi/v1.0/account/~/extension/~/fax",
formData,
);
const messageInfo = r.data;
expect(messageInfo).not.toBeUndefined();
expect(messageInfo.id).not.toBeUndefined();
});
});