@@ -825,6 +825,117 @@ describe('#compileMethodsToDynamodb()', () => {
825
825
} )
826
826
} )
827
827
} )
828
+
829
+ describe ( '#private' , ( ) => {
830
+ it ( 'should create corresponding resources when a dynamodb proxy is given with private' , ( ) => {
831
+ serverlessApigatewayServiceProxy . validated = {
832
+ events : [
833
+ {
834
+ serviceName : 'dynamodb' ,
835
+ http : {
836
+ path : 'dynamodb' ,
837
+ method : 'post' ,
838
+ action : 'PutItem' ,
839
+ tableName : {
840
+ Ref : 'MyTable'
841
+ } ,
842
+ key : 'key' ,
843
+ private : true ,
844
+ auth : { authorizationType : 'NONE' }
845
+ }
846
+ }
847
+ ]
848
+ }
849
+ serverlessApigatewayServiceProxy . apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'
850
+ serverlessApigatewayServiceProxy . apiGatewayResources = {
851
+ dynamodb : {
852
+ name : 'dynamodb' ,
853
+ resourceLogicalId : 'ApiGatewayResourceDynamodb'
854
+ }
855
+ }
856
+
857
+ serverlessApigatewayServiceProxy . compileMethodsToDynamodb ( )
858
+ expect ( serverless . service . provider . compiledCloudFormationTemplate . Resources ) . to . deep . equal ( {
859
+ ApiGatewayMethoddynamodbPost : {
860
+ Type : 'AWS::ApiGateway::Method' ,
861
+ Properties : {
862
+ HttpMethod : 'POST' ,
863
+ RequestParameters : { } ,
864
+ AuthorizationScopes : undefined ,
865
+ AuthorizerId : undefined ,
866
+ AuthorizationType : 'NONE' ,
867
+ ApiKeyRequired : true ,
868
+ ResourceId : { Ref : 'ApiGatewayResourceDynamodb' } ,
869
+ RestApiId : { Ref : 'ApiGatewayRestApi' } ,
870
+ Integration : {
871
+ IntegrationHttpMethod : 'POST' ,
872
+ Type : 'AWS' ,
873
+ Credentials : { 'Fn::GetAtt' : [ 'ApigatewayToDynamodbRole' , 'Arn' ] } ,
874
+ Uri : {
875
+ 'Fn::Sub' : [
876
+ 'arn:aws:apigateway:${AWS::Region}:dynamodb:action/${action}' ,
877
+ { action : 'PutItem' }
878
+ ]
879
+ } ,
880
+ PassthroughBehavior : 'NEVER' ,
881
+ RequestTemplates : {
882
+ 'application/json' : {
883
+ 'Fn::Sub' : [
884
+ '{"TableName": "${TableName}","Item": {\n #set ($body = $util.parseJson($input.body))\n #foreach( $key in $body.keySet())\n #set ($item = $body.get($key))\n #foreach( $type in $item.keySet())\n "$key":{"$type" : "$item.get($type)"}\n #if($foreach.hasNext()),#end\n #end\n #if($foreach.hasNext()),#end\n #end\n }\n }' ,
885
+ { TableName : { Ref : 'MyTable' } }
886
+ ]
887
+ } ,
888
+ 'application/x-www-form-urlencoded' : {
889
+ 'Fn::Sub' : [
890
+ '{"TableName": "${TableName}","Item": {\n #set ($body = $util.parseJson($input.body))\n #foreach( $key in $body.keySet())\n #set ($item = $body.get($key))\n #foreach( $type in $item.keySet())\n "$key":{"$type" : "$item.get($type)"}\n #if($foreach.hasNext()),#end\n #end\n #if($foreach.hasNext()),#end\n #end\n }\n }' ,
891
+ { TableName : { Ref : 'MyTable' } }
892
+ ]
893
+ }
894
+ } ,
895
+ IntegrationResponses : [
896
+ {
897
+ StatusCode : 200 ,
898
+ SelectionPattern : '2\\d{2}' ,
899
+ ResponseParameters : { } ,
900
+ ResponseTemplates : { }
901
+ } ,
902
+ {
903
+ StatusCode : 400 ,
904
+ SelectionPattern : '4\\d{2}' ,
905
+ ResponseParameters : { } ,
906
+ ResponseTemplates : { }
907
+ } ,
908
+ {
909
+ StatusCode : 500 ,
910
+ SelectionPattern : '5\\d{2}' ,
911
+ ResponseParameters : { } ,
912
+ ResponseTemplates : { }
913
+ }
914
+ ]
915
+ } ,
916
+ MethodResponses : [
917
+ {
918
+ ResponseParameters : { } ,
919
+ ResponseModels : { } ,
920
+ StatusCode : 200
921
+ } ,
922
+ {
923
+ ResponseParameters : { } ,
924
+ ResponseModels : { } ,
925
+ StatusCode : 400
926
+ } ,
927
+ {
928
+ ResponseParameters : { } ,
929
+ ResponseModels : { } ,
930
+ StatusCode : 500
931
+ }
932
+ ]
933
+ }
934
+ }
935
+ } )
936
+ } )
937
+ } )
938
+
828
939
describe ( '#authorization' , ( ) => {
829
940
const testAuthorization = ( auth ) => {
830
941
const param = {
0 commit comments