@@ -305,7 +305,7 @@ describe('ServerlessAWSDocumentation', function () {
305
305
} ) ;
306
306
} ) ;
307
307
308
- it ( 'should only add response methods whith existence MethodResponses to ApiGateway methods' , function ( ) {
308
+ it ( 'should only add response methods with existing MethodResponses to ApiGateway methods' , function ( ) {
309
309
this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
310
310
this . serverlessMock . service . _functionNames = [ 'test' ] ;
311
311
this . serverlessMock . service . _functions = {
@@ -343,15 +343,179 @@ describe('ServerlessAWSDocumentation', function () {
343
343
Properties : {
344
344
MethodResponses : [ {
345
345
StatusCode : 200 ,
346
+ id : 9001 ,
346
347
} ,
347
348
{
348
349
StatusCode : 404 ,
350
+ id : 9002 ,
349
351
} ] ,
350
352
} ,
351
353
} ;
352
354
353
355
this . plugin . beforeDeploy ( ) ;
354
356
357
+ expect ( this . serverlessMock . service . provider . compiledCloudFormationTemplate ) . toEqual ( {
358
+ Resources : {
359
+ ExistingResource : {
360
+ with : 'configuration' ,
361
+ } ,
362
+ somepath_post : {
363
+ some : 'configuration' ,
364
+ DependsOn : [ 'CreateResponseModel' , 'ErrorResponseModel' ] ,
365
+ Properties : {
366
+ MethodResponses : [ {
367
+ StatusCode : 200 ,
368
+ id : 9001 ,
369
+ ResponseModels : {
370
+ 'application/json' : 'CreateResponse' ,
371
+ } ,
372
+ } ,
373
+ {
374
+ StatusCode : 404 ,
375
+ id : 9002 ,
376
+ ResponseModels : {
377
+ 'application/json' : 'ErrorResponse'
378
+ } ,
379
+ } ] ,
380
+ } ,
381
+ } ,
382
+ } ,
383
+ Outputs : {
384
+ AwsDocApiId : {
385
+ Description : 'API ID' ,
386
+ Value : {
387
+ Ref : 'ApiGatewayRestApi' ,
388
+ } ,
389
+ }
390
+ } ,
391
+ } ) ;
392
+ } ) ;
393
+
394
+ it ( 'should only add response methods with existing and new MethodResponses to ApiGateway methods' , function ( ) {
395
+ this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
396
+ this . serverlessMock . service . _functionNames = [ 'test' ] ;
397
+ this . serverlessMock . service . _functions = {
398
+ test : {
399
+ events : [ {
400
+ http : {
401
+ path : 'some/path' ,
402
+ method : 'post' ,
403
+ cors : true ,
404
+ private : true ,
405
+ documentation : {
406
+ methodResponses : [
407
+ {
408
+ statusCode : 200 ,
409
+ should : 'not be included' ,
410
+ responseModels : {
411
+ 'application/json' : 'CreateResponse' ,
412
+ } ,
413
+ } ,
414
+ {
415
+ statusCode : 404 ,
416
+ should : 'not be included' ,
417
+ responseModels : {
418
+ 'application/json' : 'ErrorResponse'
419
+ } ,
420
+ } ,
421
+ ] ,
422
+ }
423
+ } ,
424
+ } ] ,
425
+ } ,
426
+ } ;
427
+
428
+ const resources = this . serverlessMock . service . provider . compiledCloudFormationTemplate . Resources ;
429
+ resources . somepath_post = {
430
+ some : 'configuration' ,
431
+ Properties : {
432
+ MethodResponses : [ {
433
+ StatusCode : 200 ,
434
+ id : 9001 ,
435
+ } , ] ,
436
+ } ,
437
+ } ;
438
+
439
+ this . plugin . beforeDeploy ( ) ;
440
+
441
+ expect ( this . serverlessMock . service . provider . compiledCloudFormationTemplate ) . toEqual ( {
442
+ Resources : {
443
+ ExistingResource : {
444
+ with : 'configuration' ,
445
+ } ,
446
+ somepath_post : {
447
+ some : 'configuration' ,
448
+ DependsOn : [ 'CreateResponseModel' , 'ErrorResponseModel' ] ,
449
+ Properties : {
450
+ MethodResponses : [ {
451
+ StatusCode : 200 ,
452
+ id : 9001 ,
453
+ ResponseModels : {
454
+ 'application/json' : 'CreateResponse' ,
455
+ } ,
456
+ } ,
457
+ {
458
+ StatusCode : 404 ,
459
+ ResponseModels : {
460
+ 'application/json' : 'ErrorResponse'
461
+ } ,
462
+ } ] ,
463
+ } ,
464
+ } ,
465
+ } ,
466
+ Outputs : {
467
+ AwsDocApiId : {
468
+ Description : 'API ID' ,
469
+ Value : {
470
+ Ref : 'ApiGatewayRestApi' ,
471
+ } ,
472
+ }
473
+ } ,
474
+ } ) ;
475
+ } ) ;
476
+
477
+ it ( 'should only add response methods with existing empty MethodResponses to ApiGateway methods' , function ( ) {
478
+ this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
479
+ this . serverlessMock . service . _functionNames = [ 'test' ] ;
480
+ this . serverlessMock . service . _functions = {
481
+ test : {
482
+ events : [ {
483
+ http : {
484
+ path : 'some/path' ,
485
+ method : 'post' ,
486
+ cors : true ,
487
+ private : true ,
488
+ documentation : {
489
+ methodResponses : [
490
+ {
491
+ statusCode : 200 ,
492
+ responseModels : {
493
+ 'application/json' : 'CreateResponse' ,
494
+ } ,
495
+ } ,
496
+ {
497
+ statusCode : 404 ,
498
+ responseModels : {
499
+ 'application/json' : 'ErrorResponse'
500
+ } ,
501
+ } ,
502
+ ] ,
503
+ }
504
+ } ,
505
+ } ] ,
506
+ } ,
507
+ } ;
508
+
509
+ const resources = this . serverlessMock . service . provider . compiledCloudFormationTemplate . Resources ;
510
+ resources . somepath_post = {
511
+ some : 'configuration' ,
512
+ Properties : {
513
+ MethodResponses : [ ] ,
514
+ } ,
515
+ } ;
516
+
517
+ this . plugin . beforeDeploy ( ) ;
518
+
355
519
expect ( this . serverlessMock . service . provider . compiledCloudFormationTemplate ) . toEqual ( {
356
520
Resources : {
357
521
ExistingResource : {
0 commit comments