forked from twilio/twilio-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster_test.spec.ts
94 lines (82 loc) · 2.71 KB
/
cluster_test.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
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
87
88
89
90
91
92
93
94
jest.setTimeout(15000);
import twilio from "./lib/";
const fromNumber = process.env.TWILIO_FROM_NUMBER;
const toNumber = process.env.TWILIO_TO_NUMBER;
const apiKey = process.env.TWILIO_API_KEY;
const apiSecret = process.env.TWILIO_API_SECRET;
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const testClient = twilio(apiKey, apiSecret, { accountSid });
const twiml = new twilio.twiml.VoiceResponse();
test("Should send a text", () => {
return testClient.messages
.create({
body: "hello world",
to: toNumber,
from: fromNumber,
})
.then((msg) => {
expect(msg.sid).not.toBeUndefined();
expect(msg.to).toBe(toNumber);
expect(msg.from).toBe(fromNumber);
expect(msg.body).toBe("hello world");
});
});
test("Should list incoming numbers", () => {
return testClient.incomingPhoneNumbers.list().then((incomingPhoneNumbers) => {
expect(incomingPhoneNumbers).not.toBeNull();
expect(incomingPhoneNumbers.length).toBeGreaterThanOrEqual(2);
});
});
test("Should list a incoming number", () => {
return testClient.incomingPhoneNumbers
.list({ limit: 1 })
.then((incomingPhoneNumbers) => {
expect(incomingPhoneNumbers).not.toBeUndefined();
expect(incomingPhoneNumbers.length).toEqual(1);
});
});
test("Should allow special characters for friendly and identity name", async () => {
const friendlyName = "service|friendly&name";
const identityName = "user|identity&string";
const conversation = await testClient.conversations.v1.conversations.create({
friendlyName: friendlyName,
});
const participant = await testClient.conversations.v1
.conversations(conversation.sid)
.participants.create({ identity: identityName });
expect(conversation).not.toBeNull();
expect(participant).not.toBeNull();
expect(conversation.friendlyName).toBe(friendlyName);
expect(participant.identity).toBe(identityName);
const removeConversation = await testClient.conversations.v1
.conversations(conversation.sid)
.remove();
expect(removeConversation).toBeTruthy();
});
test("Should list available numbers", () => {
return testClient
.availablePhoneNumbers("US")
.tollFree.list({ limit: 2 })
.then((tollFree) => {
expect(tollFree).not.toBeNull();
expect(tollFree.length).toEqual(2);
});
});
test("Should call with twiml string", () => {
return testClient.calls
.create({
twiml: twiml.toString(),
to: toNumber,
from: fromNumber,
})
.then((call) => expect(call.sid).toBeDefined());
});
test("Should call with twiml object", () => {
return testClient.calls
.create({
twiml: twiml,
to: toNumber,
from: fromNumber,
})
.then((call) => expect(call.sid).toBeDefined());
});