@@ -1829,7 +1829,7 @@ describe('#validateServiceProxies()', () => {
18291829 )
18301830 } )
18311831
1832- it ( 'should throw error if the "hashKey" is object and missing "pathParam" or "queryStringParam " properties' , ( ) => {
1832+ it ( 'should throw error if the "hashKey" is object and missing "pathParam", "queryStringParam" or "keyName " properties' , ( ) => {
18331833 serverlessApigatewayServiceProxy . serverless . service . custom = {
18341834 apiGatewayServiceProxies : [
18351835 {
@@ -1847,7 +1847,7 @@ describe('#validateServiceProxies()', () => {
18471847 }
18481848
18491849 expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . throw (
1850- 'child "dynamodb" fails because [child "hashKey" fails because ["hashKey" must contain at least one of [pathParam, queryStringParam]]]'
1850+ 'child "dynamodb" fails because [child "hashKey" fails because ["hashKey" must contain at least one of [pathParam, queryStringParam, keyName ]]]'
18511851 )
18521852 } )
18531853
@@ -1915,7 +1915,7 @@ describe('#validateServiceProxies()', () => {
19151915 expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . not . throw ( )
19161916 } )
19171917
1918- it ( 'should not throw error if the "hashKey" is object and has both "pathParam " and "attributeType" properties' , ( ) => {
1918+ it ( 'should not throw error if the "hashKey" is object and has both "keyName " and "attributeType" properties' , ( ) => {
19191919 serverlessApigatewayServiceProxy . serverless . service . custom = {
19201920 apiGatewayServiceProxies : [
19211921 {
@@ -1925,7 +1925,8 @@ describe('#validateServiceProxies()', () => {
19251925 method : 'post' ,
19261926 action : 'PutItem' ,
19271927 hashKey : {
1928- pathParam : 'id' ,
1928+ keyName : 'id' ,
1929+ attributeValue : '${input.params().path.id1}_${input.params().path.id2}' ,
19291930 attributeType : 'S'
19301931 }
19311932 }
@@ -1992,7 +1993,27 @@ describe('#validateServiceProxies()', () => {
19921993 }
19931994
19941995 expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . throw (
1995- 'child "dynamodb" fails because [child "hashKey" fails because [key must contain "pathParam" or "queryStringParam" and only one]]'
1996+ 'child "dynamodb" fails because [child "hashKey" fails because [key must contain "pathParam" or "queryStringParam" or "keyName" and only one]]'
1997+ )
1998+ } )
1999+
2000+ it ( 'should throw error if the "hashKey" is a pathParam and a keyName at the same time' , ( ) => {
2001+ serverlessApigatewayServiceProxy . serverless . service . custom = {
2002+ apiGatewayServiceProxies : [
2003+ {
2004+ dynamodb : {
2005+ tableName : 'yourStream' ,
2006+ path : 'dynamodb' ,
2007+ method : 'put' ,
2008+ action : 'PutItem' ,
2009+ hashKey : { pathParam : 'id' , keyName : 'id' , attributeType : 'S' }
2010+ }
2011+ }
2012+ ]
2013+ }
2014+
2015+ expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . throw (
2016+ 'child "dynamodb" fails because [child "hashKey" fails because [key must contain "pathParam" or "queryStringParam" or "keyName" and only one]]'
19962017 )
19972018 } )
19982019
@@ -2018,7 +2039,7 @@ describe('#validateServiceProxies()', () => {
20182039 }
20192040
20202041 expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . throw (
2021- 'child "dynamodb" fails because [child "rangeKey" fails because ["rangeKey" must contain at least one of [pathParam, queryStringParam]]]'
2042+ 'child "dynamodb" fails because [child "rangeKey" fails because ["rangeKey" must contain at least one of [pathParam, queryStringParam, keyName ]]]'
20222043 )
20232044 } )
20242045
@@ -2098,6 +2119,31 @@ describe('#validateServiceProxies()', () => {
20982119 expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . not . throw ( )
20992120 } )
21002121
2122+ it ( 'should not throw error if the "rangeKey" is object and has both "keyName" and "attributeType" properties' , ( ) => {
2123+ serverlessApigatewayServiceProxy . serverless . service . custom = {
2124+ apiGatewayServiceProxies : [
2125+ {
2126+ dynamodb : {
2127+ tableName : 'yourTable' ,
2128+ path : 'dynamodb' ,
2129+ method : 'post' ,
2130+ action : 'PutItem' ,
2131+ hashKey : {
2132+ keyName : 'id' ,
2133+ attributeType : 'S'
2134+ } ,
2135+ hashKey : {
2136+ keyName : 'sort' ,
2137+ attributeType : 'S'
2138+ }
2139+ }
2140+ }
2141+ ]
2142+ }
2143+
2144+ expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . not . throw ( )
2145+ } )
2146+
21012147 it ( 'should throw error if the "rangeKey" is not a string or an object' , ( ) => {
21022148 serverlessApigatewayServiceProxy . serverless . service . custom = {
21032149 apiGatewayServiceProxies : [
@@ -2164,7 +2210,28 @@ describe('#validateServiceProxies()', () => {
21642210 }
21652211
21662212 expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . throw (
2167- 'child "dynamodb" fails because [child "rangeKey" fails because [key must contain "pathParam" or "queryStringParam" and only one]]'
2213+ 'child "dynamodb" fails because [child "rangeKey" fails because [key must contain "pathParam" or "queryStringParam" or "keyName" and only one]]'
2214+ )
2215+ } )
2216+
2217+ it ( 'should throw error if the "rangeKey" is a pathParam and a keyName at the same time' , ( ) => {
2218+ serverlessApigatewayServiceProxy . serverless . service . custom = {
2219+ apiGatewayServiceProxies : [
2220+ {
2221+ dynamodb : {
2222+ tableName : 'yourStream' ,
2223+ path : 'dynamodb' ,
2224+ method : 'put' ,
2225+ action : 'PutItem' ,
2226+ hashKey : { pathParam : 'id' , attributeType : 'S' } ,
2227+ rangeKey : { pathParam : 'id' , keyName : 'id' , attributeType : 'S' }
2228+ }
2229+ }
2230+ ]
2231+ }
2232+
2233+ expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . throw (
2234+ 'child "dynamodb" fails because [child "rangeKey" fails because [key must contain "pathParam" or "queryStringParam" or "keyName" and only one]]'
21682235 )
21692236 } )
21702237
0 commit comments