-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfax.spec.ts
56 lines (53 loc) · 2.19 KB
/
fax.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
import type CreateFaxMessageRequest from "@rc-ex/core/definitions/CreateFaxMessageRequest";
import type Attachment from "@rc-ex/core/definitions/Attachment";
import type FaxResponse from "@rc-ex/core/definitions/FaxResponse";
import Utils from "@rc-ex/core/Utils";
import fs from "fs";
import path from "path";
import { describe, expect, test } from "vitest";
import ReusableRestClient from "./reusable-rest-client";
describe("fax", () => {
test("send fax", async () => {
const rc = await ReusableRestClient.getInstance();
const createFaxMessageRequest: CreateFaxMessageRequest = {};
createFaxMessageRequest.to = [{
phoneNumber: process.env.RINGCENTRAL_RECEIVER,
}];
const attachment1: Attachment = {};
attachment1.filename = "text.txt";
attachment1.content = "hello world";
attachment1.contentType = "text/plain";
const attachment2: Attachment = {};
attachment2.filename = "text.png";
attachment2.content = fs.createReadStream(path.join(__dirname, "test.png"));
attachment2.contentType = "image/png";
createFaxMessageRequest.attachments = [attachment1, attachment2];
const messageInfo = await rc.restapi().account().extension().fax().post(
createFaxMessageRequest,
);
expect(messageInfo).not.toBeUndefined();
expect(messageInfo.id).not.toBeUndefined();
});
test("send fax - low level api", async () => {
const rc = await ReusableRestClient.getInstance();
const attachment1: Attachment = {};
attachment1.filename = "text.txt";
attachment1.content = "hello world";
attachment1.contentType = "text/plain";
const attachment2: Attachment = {};
attachment2.filename = "text.png";
attachment2.content = fs.createReadStream(path.join(__dirname, "test.png"));
attachment2.contentType = "image/png";
const formData = await Utils.getFormData({
attachments: [attachment1, attachment2],
to: [{ phoneNumber: process.env.RINGCENTRAL_RECEIVER, name: "To Name" }],
});
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();
});
});