@@ -4,10 +4,15 @@ const DeployCommand = require('../../src/commands/rtc/apps/video/deploy');
44const ViewCommand = require ( '../../src/commands/rtc/apps/video/view' ) ;
55
66const jwt = require ( 'jsonwebtoken' ) ;
7+ const { nanoid } = require ( 'nanoid' ) ;
78const path = require ( 'path' ) ;
89const { stdout } = require ( 'stdout-stderr' ) ;
910const 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 ( / W e b A p p U R L : .+ \n P a s s c o d e : \d { 3 } \d { 3 } \d { 4 } \d { 4 } \n E x p i r e s : .+ / ) ;
124+ expect ( stdout . output ) . toMatch (
125+ / W e b A p p U R L : .+ \n P a s s c o d e : \d { 3 } \d { 3 } \d { 4 } \d { 4 } \n E x p i r e s : .+ \n R o o m T y p e : g r o u p /
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 ( / P a s s c o d e : \d { 3 } \d { 3 } \d { 4 } \d { 4 } \n E x p i r e s : .+ / ) ;
235+ expect ( stdout . output ) . toMatch ( / P a s s c o d e : \d { 3 } \d { 3 } \d { 4 } \d { 4 } \n E x p i r e s : .+ \n R o o m T y p e : p e e r - t o - p e e r / ) ;
222236 expect ( stdout . output ) . not . toMatch ( / W e b A p p U R L : / ) ;
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