Skip to content

Commit 89114ef

Browse files
author
Tim Mendoza
committed
Update e2e tests
1 parent 29d715e commit 89114ef

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"jest": "^25.1.0",
3737
"lint-staged": "^10.0.8",
3838
"prettier": "^1.19.1",
39-
"superagent": "^5.2.2"
39+
"superagent": "^5.2.2",
40+
"twilio": "^3.48.2"
4041
},
4142
"eslintConfig": {
4243
"extends": "eslint:recommended",

test/e2e/e2e.test.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ const DeployCommand = require('../../src/commands/rtc/apps/video/deploy');
44
const ViewCommand = require('../../src/commands/rtc/apps/video/view');
55

66
const jwt = require('jsonwebtoken');
7+
const { nanoid } = require('nanoid');
78
const path = require('path');
89
const { stdout } = require('stdout-stderr');
910
const superagent = require('superagent');
1011

12+
const twilioClient = require('twilio')(process.env.TWILIO_API_KEY, process.env.TWILIO_API_SECRET, {
13+
accountSid: process.env.TWILIO_ACCOUNT_SID,
14+
});
15+
1116
// Uncomment to see output from CLI
1217
// stdout.print = true;
1318

@@ -116,16 +121,23 @@ describe('the RTC Twilio-CLI Plugin', () => {
116121
stdout.start();
117122
await ViewCommand.run([]);
118123
stdout.stop();
119-
expect(stdout.output).toMatch(/Web App URL: .+\nPasscode: \d{3} \d{3} \d{4} \d{4}\nExpires: .+/);
124+
expect(stdout.output).toMatch(
125+
/Web App URL: .+\nPasscode: \d{3} \d{3} \d{4} \d{4}\nExpires: .+\nRoom Type: group/
126+
);
120127
});
121128
});
122129

123-
describe('the deploy command', () => {
124-
it('should return a video token when the correct passcode is provided', async () => {
130+
describe('the serverless deployment', () => {
131+
it('should create a group room and return a video token when the correct passcode is provided', async () => {
132+
const ROOM_NAME = nanoid();
125133
const { body } = await superagent
126134
.post(`${URL}/token`)
127-
.send({ passcode, room_name: 'test-room', user_identity: 'test user' });
128-
expect(jwt.decode(body.token).grants).toEqual({ identity: 'test user', video: { room: 'test-room' } });
135+
.send({ passcode, room_name: ROOM_NAME, user_identity: 'test user' });
136+
expect(jwt.decode(body.token).grants).toEqual({ identity: 'test user', video: { room: ROOM_NAME } });
137+
expect(body.room_type).toEqual('group');
138+
139+
const room = await twilioClient.video.rooms(ROOM_NAME).fetch();
140+
expect(room.type).toEqual('group');
129141
});
130142

131143
it('should return a 401 error when an incorrect passcode is provided', () => {
@@ -145,7 +157,9 @@ describe('the RTC Twilio-CLI Plugin', () => {
145157
const { text } = await superagent.get(webAppURL + '/login');
146158
expect(text).toEqual('<html>test</html>');
147159
});
160+
});
148161

162+
describe('the deploy command', () => {
149163
it('should not redeploy the app when no --override flag is passed', async () => {
150164
stdout.start();
151165
await DeployCommand.run([
@@ -193,14 +207,14 @@ describe('the RTC Twilio-CLI Plugin', () => {
193207
});
194208
});
195209

196-
describe('after deploying a token server', () => {
210+
describe('after deploying a token server (with peer-to-peer rooms)', () => {
197211
let URL;
198212
let passcode;
199213
let webAppURL;
200214

201215
beforeAll(async done => {
202216
stdout.start();
203-
await DeployCommand.run(['--authentication', 'passcode']);
217+
await DeployCommand.run(['--authentication', 'passcode', '--room-type', 'peer-to-peer']);
204218
stdout.stop();
205219
passcode = getPasscode(stdout.output);
206220
URL = getURL(stdout.output);
@@ -218,17 +232,22 @@ describe('the RTC Twilio-CLI Plugin', () => {
218232
stdout.start();
219233
await ViewCommand.run([]);
220234
stdout.stop();
221-
expect(stdout.output).toMatch(/Passcode: \d{3} \d{3} \d{4} \d{4}\nExpires: .+/);
235+
expect(stdout.output).toMatch(/Passcode: \d{3} \d{3} \d{4} \d{4}\nExpires: .+\nRoom Type: peer-to-peer/);
222236
expect(stdout.output).not.toMatch(/Web App URL:/);
223237
});
224238
});
225239

226-
describe('the deploy command', () => {
227-
it('should return a video token when the correct passcode is provided', async () => {
240+
describe('the serverless deployment', () => {
241+
it('should create a peer-to-peer room and return a video token when the correct passcode is provided', async () => {
242+
const ROOM_NAME = nanoid();
228243
const { body } = await superagent
229244
.post(`${URL}/token`)
230-
.send({ passcode, room_name: 'test-room', user_identity: 'test user' });
231-
expect(jwt.decode(body.token).grants).toEqual({ identity: 'test user', video: { room: 'test-room' } });
245+
.send({ passcode, room_name: ROOM_NAME, user_identity: 'test user' });
246+
expect(jwt.decode(body.token).grants).toEqual({ identity: 'test user', video: { room: ROOM_NAME } });
247+
expect(body.room_type).toEqual('peer-to-peer');
248+
249+
const room = await twilioClient.video.rooms(ROOM_NAME).fetch();
250+
expect(room.type).toEqual('peer-to-peer');
232251
});
233252

234253
it('should return a 401 error when an incorrect passcode is provided', () => {
@@ -245,7 +264,9 @@ describe('the RTC Twilio-CLI Plugin', () => {
245264
it('should return a 404 from "/"', () => {
246265
superagent.get(`${URL}`).catch(e => expect(e.status).toBe(404));
247266
});
267+
});
248268

269+
describe('the deploy command', () => {
249270
it('should redeploy the token server when --override flag is passed', async () => {
250271
stdout.start();
251272
await DeployCommand.run(['--authentication', 'passcode', '--override']);

0 commit comments

Comments
 (0)