1
1
const proxyquire = require ( 'proxyquire' ) ;
2
2
3
- describe ( 'ServerlessAWSDocumentation' , function ( ) {
3
+ describe ( 'ServerlessAWSDocumentation' , function ( ) {
4
4
const awsMock = {
5
5
APIGateway : { }
6
6
} ;
@@ -60,20 +60,20 @@ describe('ServerlessAWSDocumentation', function() {
60
60
} ,
61
61
} ;
62
62
63
- this . serverlessMock . providers . aws . naming . getMethodLogicalId . and . callFake ( ( resourcename , method ) => {
64
- return `${ resourcename } _${ method } ` ;
65
- } ) ;
63
+ this . serverlessMock . providers . aws . naming . getMethodLogicalId . and . callFake ( ( resourcename , method ) => {
64
+ return `${ resourcename } _${ method } ` ;
65
+ } ) ;
66
66
67
- this . serverlessMock . providers . aws . naming . normalizePath . and . callFake ( ( path ) => {
68
- return path . replace ( / \/ / g, '' ) ;
69
- } ) ;
67
+ this . serverlessMock . providers . aws . naming . normalizePath . and . callFake ( ( path ) => {
68
+ return path . replace ( / \/ / g, '' ) ;
69
+ } ) ;
70
70
71
- this . optionsMock = { } ;
71
+ this . optionsMock = { } ;
72
72
73
- this . plugin = new ServerlessAWSDocumentation ( this . serverlessMock , this . optionsMock ) ;
73
+ this . plugin = new ServerlessAWSDocumentation ( this . serverlessMock , this . optionsMock ) ;
74
74
} ) ;
75
75
76
- describe ( 'before deploy' , function ( ) {
76
+ describe ( 'before deploy' , function ( ) {
77
77
78
78
it ( 'should init' , function ( ) {
79
79
delete this . serverlessMock . variables . service . custom ;
@@ -305,6 +305,89 @@ describe('ServerlessAWSDocumentation', function() {
305
305
} ) ;
306
306
} ) ;
307
307
308
+ it ( 'should only add response methods whith existence MethodResponses to ApiGateway methods' , function ( ) {
309
+ this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
310
+ this . serverlessMock . service . _functionNames = [ 'test' ] ;
311
+ this . serverlessMock . service . _functions = {
312
+ test : {
313
+ events : [ {
314
+ http : {
315
+ path : 'some/path' ,
316
+ method : 'post' ,
317
+ cors : true ,
318
+ private : true ,
319
+ documentation : {
320
+ methodResponses : [
321
+ {
322
+ statusCode : 200 ,
323
+ responseModels : {
324
+ 'application/json' : 'CreateResponse' ,
325
+ } ,
326
+ } ,
327
+ {
328
+ statusCode : 404 ,
329
+ responseModels : {
330
+ 'application/json' : 'ErrorResponse'
331
+ } ,
332
+ } ,
333
+ ] ,
334
+ }
335
+ } ,
336
+ } ] ,
337
+ } ,
338
+ } ;
339
+
340
+ const resources = this . serverlessMock . service . provider . compiledCloudFormationTemplate . Resources ;
341
+ resources . somepath_post = {
342
+ some : 'configuration' ,
343
+ Properties : {
344
+ MethodResponses : [ {
345
+ StatusCode : 200 ,
346
+ } ,
347
+ {
348
+ StatusCode : 404 ,
349
+ } ] ,
350
+ } ,
351
+ } ;
352
+
353
+ this . plugin . beforeDeploy ( ) ;
354
+
355
+ expect ( this . serverlessMock . service . provider . compiledCloudFormationTemplate ) . toEqual ( {
356
+ Resources : {
357
+ ExistingResource : {
358
+ with : 'configuration' ,
359
+ } ,
360
+ somepath_post : {
361
+ some : 'configuration' ,
362
+ DependsOn : [ 'CreateResponseModel' , 'ErrorResponseModel' ] ,
363
+ Properties : {
364
+ MethodResponses : [ {
365
+ StatusCode : 200 ,
366
+ ResponseModels : {
367
+ 'application/json' : 'CreateResponse' ,
368
+ } ,
369
+ } ,
370
+ {
371
+ StatusCode : 404 ,
372
+ ResponseModels : {
373
+ 'application/json' : 'ErrorResponse'
374
+ } ,
375
+ } ] ,
376
+ } ,
377
+ } ,
378
+ } ,
379
+ Outputs : {
380
+ AwsDocApiId : {
381
+ Description : 'API ID' ,
382
+ Value : {
383
+ Ref : 'ApiGatewayRestApi' ,
384
+ } ,
385
+ }
386
+ } ,
387
+ } ) ;
388
+ } ) ;
389
+
390
+
308
391
it ( 'should only add response methods with response headers to ApiGateway methods' , function ( ) {
309
392
this . serverlessMock . variables . service . custom . documentation . models = [ ] ;
310
393
this . serverlessMock . service . _functionNames = [ 'test' , 'blub' ] ;
@@ -808,7 +891,7 @@ describe('ServerlessAWSDocumentation', function() {
808
891
} ) ;
809
892
} ) ;
810
893
811
- describe ( 'after deploy' , function ( ) {
894
+ describe ( 'after deploy' , function ( ) {
812
895
beforeEach ( function ( ) {
813
896
this . apiGatewayMock = jasmine . createSpyObj ( [
814
897
'getDocumentationParts' ,
@@ -835,10 +918,10 @@ describe('ServerlessAWSDocumentation', function() {
835
918
it ( 'should get stack description' , function ( ) {
836
919
this . optionsMock . stage = 'megastage' ;
837
920
this . optionsMock . region = 'hyperregion' ;
838
- this . serverlessMock . providers . aws . request . and . returnValue ( new Promise ( ( ) => { } ) ) ;
921
+ this . serverlessMock . providers . aws . request . and . returnValue ( new Promise ( ( ) => { } ) ) ;
839
922
this . serverlessMock . providers . aws . naming . getStackName . and . returnValue ( 'superstack' ) ;
840
923
this . plugin . afterDeploy ( ) ;
841
- expect ( this . serverlessMock . providers . aws . request ) . toHaveBeenCalledWith ( 'CloudFormation' , 'describeStacks' , { StackName : 'superstack' } , 'megastage' , 'hyperregion' ) ;
924
+ expect ( this . serverlessMock . providers . aws . request ) . toHaveBeenCalledWith ( 'CloudFormation' , 'describeStacks' , { StackName : 'superstack' } , 'megastage' , 'hyperregion' ) ;
842
925
} ) ;
843
926
844
927
it ( 'should build documentation with deploying and upload to api gateway' , function ( done ) {
0 commit comments