@@ -5,7 +5,10 @@ const TestTable = new Table({
55 name : 'test-table' ,
66 partitionKey : 'pk' ,
77 sortKey : 'sk' ,
8- DocumentClient
8+ DocumentClient,
9+ indexes : {
10+ GSI1 : { partitionKey : 'GSI1pk' }
11+ }
912} )
1013
1114const TestEntity = new Entity ( {
@@ -78,6 +81,20 @@ const TestEntity3 = new Entity({
7881 table : TestTable3
7982} )
8083
84+ const TestEntityGSI = new Entity ( {
85+ name : 'TestEntityGSI' ,
86+ autoExecute : false ,
87+ attributes : {
88+ email : { type : 'string' , partitionKey : true } ,
89+ sk : { type : 'string' , sortKey : true } ,
90+ test : { type : 'string' } ,
91+ test2 : { type : 'string' } ,
92+ GSI1pk : { partitionKey : 'GSI1' }
93+ } ,
94+ timestamps : false ,
95+ table : TestTable
96+ } )
97+
8198
8299describe ( 'update' , ( ) => {
83100
@@ -96,6 +113,11 @@ describe('update',()=>{
96113 expect ( TableName ) . toBe ( 'test-table' )
97114 } )
98115
116+ it ( 'creates update with GSI' , ( ) => {
117+ let { TableName, Key, UpdateExpression, ExpressionAttributeNames, ExpressionAttributeValues } = TestEntityGSI . updateParams ( { pk : 'test-pk' , sk : 'test-sk' , GSI1pk : 'test' } )
118+ expect ( UpdateExpression ) . toBe ( 'SET #_et = if_not_exists(#_et,:_et), #GSI1pk = :GSI1pk' )
119+ } )
120+
99121
100122 it ( 'creates update with multiple fields (default types)' , ( ) => {
101123 let { TableName, Key, UpdateExpression, ExpressionAttributeNames, ExpressionAttributeValues } = TestEntity . updateParams ( {
0 commit comments