@@ -13,7 +13,7 @@ const { getListOfFunctionsAndAssets } = require('@twilio-labs/serverless-api/dis
1313const path = require ( 'path' ) ;
1414const { stdout } = require ( 'stdout-stderr' ) ;
1515
16- const mockDeployProject = jest . fn ( ( ) => Promise . resolve ( ) ) ;
16+ const mockDeployProject = jest . fn ( ( ) => Promise . resolve ( { serviceSid : 'mockServiceSid' } ) ) ;
1717
1818jest . mock ( '@twilio-labs/serverless-api' , ( ) => ( {
1919 TwilioServerlessApiClient : function ( ) {
@@ -38,10 +38,14 @@ jest.mock('@twilio-labs/serverless-api/dist/utils/fs', () => ({
3838function getMockTwilioInstance ( options ) {
3939 const mockTwilioClient = {
4040 serverless : { } ,
41+ username : options . username ,
42+ password : options . password ,
4143 } ;
4244
4345 const mockAppInstance = {
4446 assets : { list : ( ) => Promise . resolve ( options . hasAssets ? [ { } ] : [ ] ) } ,
47+ functions : { } ,
48+ update : jest . fn ( ( ) => Promise . resolve ( ) ) ,
4549 } ;
4650
4751 mockAppInstance . environments = jest . fn ( ( ) => ( {
@@ -55,8 +59,9 @@ function getMockTwilioInstance(options) {
5559 } ,
5660 } ) ) ;
5761 mockAppInstance . environments . list = ( ) =>
58- Promise . resolve ( [ { sid : 'env' , domainName : `${ APP_NAME } -1234-5678-dev.twil.io` } ] ) ;
59- mockTwilioClient . serverless . services = jest . fn ( ( ) => Promise . resolve ( mockAppInstance ) ) ;
62+ Promise . resolve ( [ { sid : 'environmentSid' , domainName : `${ APP_NAME } -1234-5678-dev.twil.io` } ] ) ;
63+ mockAppInstance . functions . list = ( ) => Promise . resolve ( [ { sid : 'tokenFunctionSid' , friendlyName : 'token' } ] ) ;
64+ mockTwilioClient . serverless . services = jest . fn ( ( ) => mockAppInstance ) ;
6065 mockTwilioClient . serverless . services . list = ( ) =>
6166 Promise . resolve ( [
6267 {
@@ -178,6 +183,8 @@ describe('the getAppInfo function', () => {
178183 } ) ;
179184 expect ( result ) . toEqual ( {
180185 expiry : 'Wed May 20 2020 18:40:00 GMT+0000' ,
186+ environmentSid : 'environmentSid' ,
187+ functionSid : 'tokenFunctionSid' ,
181188 hasAssets : false ,
182189 passcode : '12345612345678' ,
183190 sid : 'appSid' ,
@@ -192,6 +199,8 @@ describe('the getAppInfo function', () => {
192199 } ) ;
193200 expect ( result ) . toEqual ( {
194201 expiry : 'Wed May 20 2020 18:40:00 GMT+0000' ,
202+ environmentSid : 'environmentSid' ,
203+ functionSid : 'tokenFunctionSid' ,
195204 hasAssets : true ,
196205 passcode : '12345612345678' ,
197206 sid : 'appSid' ,
@@ -220,6 +229,7 @@ describe('the displayAppInfo function', () => {
220229 "Passcode: 123 456 1234 5678
221230 Expires: Wed May 20 2020 18:40:00 GMT+0000
222231 Room Type: group
232+ Edit your token server at: https://www.twilio.com/console/functions/editor/appSid/environment/environmentSid/function/tokenFunctionSid
223233 "
224234 ` ) ;
225235 } ) ;
@@ -233,6 +243,7 @@ describe('the displayAppInfo function', () => {
233243 Passcode: 123 456 1234 5678
234244 Expires: Wed May 20 2020 18:40:00 GMT+0000
235245 Room Type: group
246+ Edit your token server at: https://www.twilio.com/console/functions/editor/appSid/environment/environmentSid/function/tokenFunctionSid
236247 "
237248 ` ) ;
238249 } ) ;
@@ -242,19 +253,16 @@ describe('the displayAppInfo function', () => {
242253 twilioClient : getMockTwilioInstance ( { exists : false } ) ,
243254 } ) ;
244255 expect ( stdout . output ) . toMatchInlineSnapshot ( `
245- "There is no deployed app
246- "
247- ` ) ;
256+ "There is no deployed app
257+ "
258+ `) ;
248259 } ) ;
249260} ) ;
250261
251262describe ( 'the deploy function' , ( ) => {
252263 it ( 'should set serviceSid when appInfo exists' , async ( ) => {
253264 await deploy . call ( {
254- twilioClient : {
255- username : '' ,
256- password : '' ,
257- } ,
265+ twilioClient : getMockTwilioInstance ( { username : '' , password : '' } ) ,
258266 appInfo : {
259267 sid : '1234' ,
260268 } ,
@@ -267,16 +275,41 @@ describe('the deploy function', () => {
267275
268276 it ( 'should set serviceName when appInfo doesnt exist' , async ( ) => {
269277 await deploy . call ( {
270- twilioClient : {
271- username : '' ,
272- password : '' ,
273- } ,
278+ twilioClient : getMockTwilioInstance ( { username : '' , password : '' } ) ,
274279 flags : { } ,
275280 } ) ;
276281 expect ( mockDeployProject . mock . calls [ 0 ] [ 0 ] . serviceSid ) . toBe ( undefined ) ;
277282 expect ( mockDeployProject . mock . calls [ 0 ] [ 0 ] . serviceName ) . toMatch ( new RegExp ( `${ APP_NAME } -(\\d{4})` ) ) ;
278283 } ) ;
279284
285+ it ( 'should set ui-editable to false when the flag is false' , async ( ) => {
286+ const mockTwilioClient = getMockTwilioInstance ( { username : '' , password : '' } ) ;
287+ await deploy . call ( {
288+ twilioClient : mockTwilioClient ,
289+ flags : {
290+ 'ui-editable' : false ,
291+ } ,
292+ } ) ;
293+ expect ( mockTwilioClient . serverless . services ( ) . update ) . toHaveBeenCalledWith ( {
294+ includeCredentials : true ,
295+ uiEditable : false ,
296+ } ) ;
297+ } ) ;
298+
299+ it ( 'should set ui-editable to true when the flag is true' , async ( ) => {
300+ const mockTwilioClient = getMockTwilioInstance ( { username : '' , password : '' } ) ;
301+ await deploy . call ( {
302+ twilioClient : mockTwilioClient ,
303+ flags : {
304+ 'ui-editable' : true ,
305+ } ,
306+ } ) ;
307+ expect ( mockTwilioClient . serverless . services ( ) . update ) . toHaveBeenCalledWith ( {
308+ includeCredentials : true ,
309+ uiEditable : true ,
310+ } ) ;
311+ } ) ;
312+
280313 it ( 'should display an error when the API key is not provided' , ( ) => {
281314 return expect (
282315 deploy . call ( {
@@ -288,17 +321,17 @@ describe('the deploy function', () => {
288321 flags : { } ,
289322 } )
290323 ) . rejects . toMatchInlineSnapshot ( `
291- [Error: No API Key found.
324+ [Error: No API Key found.
292325
293- Please login to the Twilio CLI to create an API key:
326+ Please login to the Twilio CLI to create an API key:
294327
295- twilio login
328+ twilio login
296329
297- Alternatively, the Twilio CLI can use credentials stored in these environment variables:
330+ Alternatively, the Twilio CLI can use credentials stored in these environment variables:
298331
299- TWILIO_ACCOUNT_SID = your Account SID from twil.io/console
300- TWILIO_API_KEY = an API Key created at twil.io/get-api-key
301- TWILIO_API_SECRET = the secret for the API Key]
302- ` ) ;
332+ TWILIO_ACCOUNT_SID = your Account SID from twil.io/console
333+ TWILIO_API_KEY = an API Key created at twil.io/get-api-key
334+ TWILIO_API_SECRET = the secret for the API Key]
335+ `) ;
303336 } ) ;
304337} ) ;
0 commit comments