@@ -1829,7 +1829,7 @@ describe('#validateServiceProxies()', () => {
1829
1829
)
1830
1830
} )
1831
1831
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' , ( ) => {
1833
1833
serverlessApigatewayServiceProxy . serverless . service . custom = {
1834
1834
apiGatewayServiceProxies : [
1835
1835
{
@@ -1847,7 +1847,7 @@ describe('#validateServiceProxies()', () => {
1847
1847
}
1848
1848
1849
1849
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 ]]]'
1851
1851
)
1852
1852
} )
1853
1853
@@ -1915,7 +1915,7 @@ describe('#validateServiceProxies()', () => {
1915
1915
expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . not . throw ( )
1916
1916
} )
1917
1917
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' , ( ) => {
1919
1919
serverlessApigatewayServiceProxy . serverless . service . custom = {
1920
1920
apiGatewayServiceProxies : [
1921
1921
{
@@ -1925,7 +1925,8 @@ describe('#validateServiceProxies()', () => {
1925
1925
method : 'post' ,
1926
1926
action : 'PutItem' ,
1927
1927
hashKey : {
1928
- pathParam : 'id' ,
1928
+ keyName : 'id' ,
1929
+ attributeValue : '${input.params().path.id1}_${input.params().path.id2}' ,
1929
1930
attributeType : 'S'
1930
1931
}
1931
1932
}
@@ -1992,7 +1993,27 @@ describe('#validateServiceProxies()', () => {
1992
1993
}
1993
1994
1994
1995
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]]'
1996
2017
)
1997
2018
} )
1998
2019
@@ -2018,7 +2039,7 @@ describe('#validateServiceProxies()', () => {
2018
2039
}
2019
2040
2020
2041
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 ]]]'
2022
2043
)
2023
2044
} )
2024
2045
@@ -2098,6 +2119,31 @@ describe('#validateServiceProxies()', () => {
2098
2119
expect ( ( ) => serverlessApigatewayServiceProxy . validateServiceProxies ( ) ) . to . not . throw ( )
2099
2120
} )
2100
2121
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
+
2101
2147
it ( 'should throw error if the "rangeKey" is not a string or an object' , ( ) => {
2102
2148
serverlessApigatewayServiceProxy . serverless . service . custom = {
2103
2149
apiGatewayServiceProxies : [
@@ -2164,7 +2210,28 @@ describe('#validateServiceProxies()', () => {
2164
2210
}
2165
2211
2166
2212
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]]'
2168
2235
)
2169
2236
} )
2170
2237
0 commit comments