@@ -129,6 +129,7 @@ describe('apigw', () => {
129
129
} ;
130
130
const apigw = new Apigw ( credentials , process . env . REGION ) ;
131
131
let outputs : ApigwDeployOutputs ;
132
+ let outputsWithId : ApigwDeployOutputs ;
132
133
133
134
test ( '[Environment UsagePlan] should deploy a apigw success' , async ( ) => {
134
135
const apigwInputs = deepClone ( inputs ) ;
@@ -360,7 +361,7 @@ describe('apigw', () => {
360
361
expect ( detail ) . toBeNull ( ) ;
361
362
} ) ;
362
363
363
- test ( '[Apigw CustomDomain] Bind CustomDomain success' , async ( ) => {
364
+ test ( '[Apigw CustomDomain] bind CustomDomain success' , async ( ) => {
364
365
const apigwInputs = deepClone ( inputs ) ;
365
366
366
367
apigwInputs . usagePlan = undefined ;
@@ -391,6 +392,7 @@ describe('apigw', () => {
391
392
} ,
392
393
] ;
393
394
outputs = await apigw . deploy ( apigwInputs ) ;
395
+
394
396
expect ( outputs . customDomains ) . toEqual ( [
395
397
{
396
398
isBinded : true ,
@@ -408,15 +410,15 @@ describe('apigw', () => {
408
410
} ,
409
411
] ) ;
410
412
411
- const d = await apigw . getCurrentCustomDomainsDict ( outputs . serviceId ) ;
413
+ const d = await apigw . customDomain . getCurrentDict ( outputs . serviceId ) ;
412
414
expect ( d [ domains [ 0 ] ] ) . toBeDefined ( ) ;
413
415
expect ( d [ domains [ 1 ] ] ) . toBeDefined ( ) ;
414
416
} ) ;
415
417
416
- let oldState : ApigwDeployOutputs ;
417
-
418
418
test ( '[Apigw CustomDomain] rebind customDomain success (skipped)' , async ( ) => {
419
419
const apigwInputs = deepClone ( inputs ) ;
420
+ apigwInputs . oldState = outputs ;
421
+
420
422
apigwInputs . usagePlan = undefined ;
421
423
apigwInputs . serviceId = outputs . serviceId ;
422
424
apigwInputs . customDomains = [
@@ -447,7 +449,7 @@ describe('apigw', () => {
447
449
] ;
448
450
449
451
outputs = await apigw . deploy ( apigwInputs ) ;
450
- oldState = outputs ;
452
+
451
453
expect ( outputs . customDomains ) . toEqual ( [
452
454
{
453
455
isBinded : true ,
@@ -465,23 +467,25 @@ describe('apigw', () => {
465
467
} ,
466
468
] ) ;
467
469
468
- const d = await apigw . getCurrentCustomDomainsDict ( outputs . serviceId ) ;
470
+ const d = await apigw . customDomain . getCurrentDict ( outputs . serviceId ) ;
469
471
expect ( d [ domains [ 0 ] ] ) . toBeDefined ( ) ;
470
472
expect ( d [ domains [ 1 ] ] ) . toBeDefined ( ) ;
471
473
} ) ;
472
474
473
475
test ( '[Apigw CustomDomain] unbind customDomain success' , async ( ) => {
474
476
const apigwInputs = deepClone ( inputs ) ;
477
+ apigwInputs . oldState = outputs ;
475
478
476
- apigwInputs . usagePlan = undefined ;
477
479
apigwInputs . serviceId = outputs . serviceId ;
480
+ apigwInputs . usagePlan = undefined ;
478
481
apigwInputs . customDomains = undefined ;
479
- apigwInputs . oldState = oldState ;
480
482
481
483
outputs = await apigw . deploy ( apigwInputs ) ;
484
+
482
485
expect ( outputs . customDomains ) . toBeUndefined ( ) ;
483
486
484
- const d = await apigw . getCurrentCustomDomainsDict ( outputs . serviceId ) ;
487
+ const d = await apigw . customDomain . getCurrentDict ( outputs . serviceId ) ;
488
+
485
489
expect ( d [ domains [ 0 ] ] ) . toBeUndefined ( ) ;
486
490
expect ( d [ domains [ 1 ] ] ) . toBeUndefined ( ) ;
487
491
} ) ;
@@ -509,4 +513,114 @@ describe('apigw', () => {
509
513
} ) ;
510
514
expect ( detail ) . toBeNull ( ) ;
511
515
} ) ;
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
+ } ) ;
512
626
} ) ;
0 commit comments