@@ -6,7 +6,7 @@ const _ = require('lodash')
66const {
77 deployWithRandomStage,
88 removeService,
9- getDynamodbItem ,
9+ getDynamodbItemWithHashKeyAndRangeKey ,
1010 putDynamodbItem,
1111 cleanUpDynamodbItems
1212} = require ( '../../../utils' )
@@ -16,7 +16,9 @@ describe('Multiple Dynamodb Proxies Integration Test', () => {
1616 let stage
1717 const tableName = 'MyMuTestTable'
1818 const hashKeyAttribute = 'id'
19+ const rangeKeyAttribute = 'sort'
1920 const hashKey = { S : 'myid' }
21+ const sortKey = { S : 'mykey' }
2022 const config = '__tests__/integration/dynamodb/multiple-integrations/service/serverless.yml'
2123
2224 beforeAll ( async ( ) => {
@@ -31,11 +33,11 @@ describe('Multiple Dynamodb Proxies Integration Test', () => {
3133 } )
3234
3335 afterEach ( async ( ) => {
34- await cleanUpDynamodbItems ( tableName , hashKeyAttribute )
36+ await cleanUpDynamodbItems ( tableName , hashKeyAttribute , rangeKeyAttribute )
3537 } )
3638
3739 it ( 'should get correct response from dynamodb PutItem action endpoint' , async ( ) => {
38- const putEndpoint = `${ endpoint } /dynamodb/${ hashKey . S } `
40+ const putEndpoint = `${ endpoint } /dynamodb/${ hashKey . S } / ${ sortKey . S } `
3941
4042 const putResponse = await fetch ( putEndpoint , {
4143 method : 'PUT' ,
@@ -45,10 +47,17 @@ describe('Multiple Dynamodb Proxies Integration Test', () => {
4547 expect ( putResponse . headers . get ( 'access-control-allow-origin' ) ) . to . deep . equal ( '*' )
4648 expect ( putResponse . status ) . to . be . equal ( 200 )
4749
48- const item = await getDynamodbItem ( tableName , hashKeyAttribute , hashKey )
50+ const item = await getDynamodbItemWithHashKeyAndRangeKey (
51+ tableName ,
52+ hashKeyAttribute ,
53+ hashKey ,
54+ rangeKeyAttribute ,
55+ sortKey
56+ )
4957 expect ( item ) . to . be . deep . equal ( {
5058 Item : {
5159 [ hashKeyAttribute ] : hashKey ,
60+ [ rangeKeyAttribute ] : sortKey ,
5261 message : { S : 'test' }
5362 }
5463 } )
@@ -57,9 +66,13 @@ describe('Multiple Dynamodb Proxies Integration Test', () => {
5766 it ( 'should get correct response from dynamodb GetItem action endpoint' , async ( ) => {
5867 await putDynamodbItem (
5968 tableName ,
60- _ . merge ( { } , { [ hashKeyAttribute ] : hashKey } , { message : { S : 'testtest' } } )
69+ _ . merge (
70+ { } ,
71+ { [ hashKeyAttribute ] : hashKey , [ rangeKeyAttribute ] : sortKey } ,
72+ { message : { S : 'testtest' } }
73+ )
6174 )
62- const getEndpoint = `${ endpoint } /dynamodb?id=${ hashKey . S } `
75+ const getEndpoint = `${ endpoint } /dynamodb?id=${ hashKey . S } &sort= ${ sortKey . S } `
6376
6477 const getResponse = await fetch ( getEndpoint , {
6578 method : 'GET' ,
@@ -71,67 +84,21 @@ describe('Multiple Dynamodb Proxies Integration Test', () => {
7184 const item = await getResponse . json ( )
7285 expect ( item ) . to . be . deep . equal ( {
7386 id : hashKey . S ,
87+ sort : sortKey . S ,
7488 message : 'testtest'
7589 } )
7690 } )
7791
78- it ( 'should get correct response from dynamodb UpdateItem action endpoint' , async ( ) => {
79- await putDynamodbItem (
80- tableName ,
81- _ . merge ( { } , { [ hashKeyAttribute ] : hashKey } , { message : { S : 'testtesttest' } } )
82- )
83- const updateEndpoint = `${ endpoint } /dynamodb/${ hashKey . S } `
84-
85- const updateResponse1 = await fetch ( updateEndpoint , {
86- method : 'POST' ,
87- headers : { 'Content-Type' : 'application/json' } ,
88- body : JSON . stringify ( {
89- UpdateExpression : 'ADD QuantityOnHand :q' ,
90- ExpressionAttributeValues : { ':q' : { N : '5' } }
91- } )
92- } )
93- expect ( updateResponse1 . headers . get ( 'access-control-allow-origin' ) ) . to . deep . equal ( '*' )
94- expect ( updateResponse1 . status ) . to . be . equal ( 200 )
95-
96- const item1 = await getDynamodbItem ( tableName , hashKeyAttribute , hashKey )
97- expect ( item1 ) . to . be . deep . equal ( {
98- Item : {
99- [ hashKeyAttribute ] : hashKey ,
100- QuantityOnHand : { N : '5' } ,
101- message : { S : 'testtesttest' }
102- }
103- } )
104-
105- const updateResponse2 = await fetch ( updateEndpoint , {
106- method : 'POST' ,
107- headers : { 'Content-Type' : 'application/json' } ,
108- body : JSON . stringify ( {
109- UpdateExpression : 'SET #n = :newName' ,
110- ExpressionAttributeValues : { ':newName' : { S : 'myname' } } ,
111- ExpressionAttributeNames : {
112- '#n' : 'name'
113- }
114- } )
115- } )
116- expect ( updateResponse2 . headers . get ( 'access-control-allow-origin' ) ) . to . deep . equal ( '*' )
117- expect ( updateResponse2 . status ) . to . be . equal ( 200 )
118- const item2 = await getDynamodbItem ( tableName , hashKeyAttribute , hashKey )
119- expect ( item2 ) . to . be . deep . equal ( {
120- Item : {
121- [ hashKeyAttribute ] : hashKey ,
122- QuantityOnHand : { N : '5' } ,
123- name : { S : 'myname' } ,
124- message : { S : 'testtesttest' }
125- }
126- } )
127- } )
128-
12992 it ( 'should get correct response from dynamodb DeleteItem action endpoint' , async ( ) => {
13093 await putDynamodbItem (
13194 tableName ,
132- _ . merge ( { } , { [ hashKeyAttribute ] : hashKey } , { message : { S : 'test' } } )
95+ _ . merge (
96+ { } ,
97+ { [ hashKeyAttribute ] : hashKey , [ rangeKeyAttribute ] : sortKey } ,
98+ { message : { S : 'test' } }
99+ )
133100 )
134- const deleteEndpoint = `${ endpoint } /dynamodb/${ hashKey . S } `
101+ const deleteEndpoint = `${ endpoint } /dynamodb/${ hashKey . S } ?sort= ${ sortKey . S } `
135102
136103 const deleteResponse = await fetch ( deleteEndpoint , {
137104 method : 'DELETE' ,
@@ -140,7 +107,13 @@ describe('Multiple Dynamodb Proxies Integration Test', () => {
140107 expect ( deleteResponse . headers . get ( 'access-control-allow-origin' ) ) . to . deep . equal ( '*' )
141108 expect ( deleteResponse . status ) . to . be . equal ( 200 )
142109
143- const item = await getDynamodbItem ( tableName , hashKeyAttribute , hashKey )
110+ const item = await getDynamodbItemWithHashKeyAndRangeKey (
111+ tableName ,
112+ hashKeyAttribute ,
113+ hashKey ,
114+ rangeKeyAttribute ,
115+ sortKey
116+ )
144117 expect ( item ) . to . be . empty
145118 } )
146119} )
0 commit comments