@@ -129,6 +129,7 @@ describe('apigw', () => {
129129 } ;
130130 const apigw = new Apigw ( credentials , process . env . REGION ) ;
131131 let outputs : ApigwDeployOutputs ;
132+ let outputsWithId : ApigwDeployOutputs ;
132133
133134 test ( '[Environment UsagePlan] should deploy a apigw success' , async ( ) => {
134135 const apigwInputs = deepClone ( inputs ) ;
@@ -360,7 +361,7 @@ describe('apigw', () => {
360361 expect ( detail ) . toBeNull ( ) ;
361362 } ) ;
362363
363- test ( '[Apigw CustomDomain] Bind CustomDomain success' , async ( ) => {
364+ test ( '[Apigw CustomDomain] bind CustomDomain success' , async ( ) => {
364365 const apigwInputs = deepClone ( inputs ) ;
365366
366367 apigwInputs . usagePlan = undefined ;
@@ -391,6 +392,7 @@ describe('apigw', () => {
391392 } ,
392393 ] ;
393394 outputs = await apigw . deploy ( apigwInputs ) ;
395+
394396 expect ( outputs . customDomains ) . toEqual ( [
395397 {
396398 isBinded : true ,
@@ -408,15 +410,15 @@ describe('apigw', () => {
408410 } ,
409411 ] ) ;
410412
411- const d = await apigw . getCurrentCustomDomainsDict ( outputs . serviceId ) ;
413+ const d = await apigw . customDomain . getCurrentDict ( outputs . serviceId ) ;
412414 expect ( d [ domains [ 0 ] ] ) . toBeDefined ( ) ;
413415 expect ( d [ domains [ 1 ] ] ) . toBeDefined ( ) ;
414416 } ) ;
415417
416- let oldState : ApigwDeployOutputs ;
417-
418418 test ( '[Apigw CustomDomain] rebind customDomain success (skipped)' , async ( ) => {
419419 const apigwInputs = deepClone ( inputs ) ;
420+ apigwInputs . oldState = outputs ;
421+
420422 apigwInputs . usagePlan = undefined ;
421423 apigwInputs . serviceId = outputs . serviceId ;
422424 apigwInputs . customDomains = [
@@ -447,7 +449,7 @@ describe('apigw', () => {
447449 ] ;
448450
449451 outputs = await apigw . deploy ( apigwInputs ) ;
450- oldState = outputs ;
452+
451453 expect ( outputs . customDomains ) . toEqual ( [
452454 {
453455 isBinded : true ,
@@ -465,23 +467,25 @@ describe('apigw', () => {
465467 } ,
466468 ] ) ;
467469
468- const d = await apigw . getCurrentCustomDomainsDict ( outputs . serviceId ) ;
470+ const d = await apigw . customDomain . getCurrentDict ( outputs . serviceId ) ;
469471 expect ( d [ domains [ 0 ] ] ) . toBeDefined ( ) ;
470472 expect ( d [ domains [ 1 ] ] ) . toBeDefined ( ) ;
471473 } ) ;
472474
473475 test ( '[Apigw CustomDomain] unbind customDomain success' , async ( ) => {
474476 const apigwInputs = deepClone ( inputs ) ;
477+ apigwInputs . oldState = outputs ;
475478
476- apigwInputs . usagePlan = undefined ;
477479 apigwInputs . serviceId = outputs . serviceId ;
480+ apigwInputs . usagePlan = undefined ;
478481 apigwInputs . customDomains = undefined ;
479- apigwInputs . oldState = oldState ;
480482
481483 outputs = await apigw . deploy ( apigwInputs ) ;
484+
482485 expect ( outputs . customDomains ) . toBeUndefined ( ) ;
483486
484- const d = await apigw . getCurrentCustomDomainsDict ( outputs . serviceId ) ;
487+ const d = await apigw . customDomain . getCurrentDict ( outputs . serviceId ) ;
488+
485489 expect ( d [ domains [ 0 ] ] ) . toBeUndefined ( ) ;
486490 expect ( d [ domains [ 1 ] ] ) . toBeUndefined ( ) ;
487491 } ) ;
@@ -509,4 +513,114 @@ describe('apigw', () => {
509513 } ) ;
510514 expect ( detail ) . toBeNull ( ) ;
511515 } ) ;
516+
517+ test ( '[isInputServiceId] should deploy a apigw success' , async ( ) => {
518+ const apigwInputs = deepClone ( inputs ) ;
519+ apigwInputs . serviceId = 'service-mh4w4xnm' ;
520+ apigwInputs . isInputServiceId = true ;
521+ delete apigwInputs . usagePlan ;
522+ delete apigwInputs . auth ;
523+
524+ outputsWithId = await apigw . deploy ( apigwInputs ) ;
525+ expect ( outputsWithId ) . toEqual ( {
526+ created : false ,
527+ serviceId : expect . stringContaining ( 'service-' ) ,
528+ serviceName : 'serverless_unit_test' ,
529+ subDomain : expect . stringContaining ( '.apigw.tencentcs.com' ) ,
530+ protocols : 'http&https' ,
531+ environment : 'release' ,
532+ apiList : [
533+ {
534+ path : '/' ,
535+ internalDomain : expect . any ( String ) ,
536+ method : 'GET' ,
537+ apiName : 'index' ,
538+ apiId : expect . stringContaining ( 'api-' ) ,
539+ created : true ,
540+ authType : 'NONE' ,
541+ businessType : 'NORMAL' ,
542+ isBase64Encoded : true ,
543+ } ,
544+ {
545+ path : '/mo' ,
546+ method : 'GET' ,
547+ apiName : 'mo' ,
548+ internalDomain : expect . any ( String ) ,
549+ apiId : expect . stringContaining ( 'api-' ) ,
550+ created : true ,
551+ authType : 'NONE' ,
552+ businessType : 'NORMAL' ,
553+ isBase64Encoded : false ,
554+ } ,
555+ {
556+ path : '/auto' ,
557+ method : 'GET' ,
558+ apiName : 'auto-http' ,
559+ internalDomain : expect . any ( String ) ,
560+ apiId : expect . stringContaining ( 'api-' ) ,
561+ created : true ,
562+ authType : 'NONE' ,
563+ businessType : 'NORMAL' ,
564+ isBase64Encoded : false ,
565+ } ,
566+ {
567+ path : '/ws' ,
568+ method : 'GET' ,
569+ apiName : 'ws-test' ,
570+ internalDomain : expect . any ( String ) ,
571+ apiId : expect . stringContaining ( 'api-' ) ,
572+ authType : 'NONE' ,
573+ businessType : 'NORMAL' ,
574+ created : true ,
575+ isBase64Encoded : false ,
576+ } ,
577+ {
578+ path : '/wsf' ,
579+ method : 'GET' ,
580+ apiName : 'ws-scf' ,
581+ internalDomain : expect . stringContaining (
582+ 'http://set-websocket.cb-common.apigateway.tencentyun.com' ,
583+ ) ,
584+ apiId : expect . stringContaining ( 'api-' ) ,
585+ authType : 'NONE' ,
586+ businessType : 'NORMAL' ,
587+ created : true ,
588+ isBase64Encoded : false ,
589+ } ,
590+ {
591+ path : '/oauth' ,
592+ method : 'GET' ,
593+ apiName : 'oauthapi' ,
594+ apiId : expect . stringContaining ( 'api-' ) ,
595+ created : true ,
596+ authType : 'OAUTH' ,
597+ businessType : 'OAUTH' ,
598+ internalDomain : expect . any ( String ) ,
599+ isBase64Encoded : false ,
600+ } ,
601+ {
602+ path : '/oauthwork' ,
603+ method : 'GET' ,
604+ apiName : 'business' ,
605+ apiId : expect . stringContaining ( 'api-' ) ,
606+ created : true ,
607+ authType : 'OAUTH' ,
608+ businessType : 'NORMAL' ,
609+ authRelationApiId : expect . stringContaining ( 'api-' ) ,
610+ internalDomain : expect . any ( String ) ,
611+ isBase64Encoded : false ,
612+ } ,
613+ ] ,
614+ } ) ;
615+ } ) ;
616+
617+ test ( '[isInputServiceId] should remove apigw success' , async ( ) => {
618+ await apigw . remove ( outputsWithId ) ;
619+ const detail = await apigw . service . getById ( outputsWithId . serviceId ) ;
620+ expect ( detail ) . toBeDefined ( ) ;
621+ expect ( detail . serviceName ) . toBe ( 'serverless_unit_test' ) ;
622+ expect ( detail . serviceDesc ) . toBe ( 'Created By Serverless' ) ;
623+ const apiList = await apigw . api . getList ( outputsWithId . serviceId ) ;
624+ expect ( apiList . length ) . toBe ( 0 ) ;
625+ } ) ;
512626} ) ;
0 commit comments