@@ -224,4 +224,39 @@ describe('delete',()=>{
224224 expect ( ( ) => TestEntity . deleteBatch ( ) ) . toThrow ( `'pk' or 'email' is required` )
225225 } )
226226
227+
228+ // Adding this for regression testing
229+ it ( 'Non-Key Index Generated on Delete #74' , async ( ) => {
230+ const FoosTable = new Table ( {
231+ name : 'test-table' ,
232+ partitionKey : 'pk' ,
233+ sortKey : 'sk' ,
234+ indexes : {
235+ 'GSI-1' : { partitionKey : 'gsi1pk' , sortKey : 'gsi1sk' } ,
236+ } ,
237+ DocumentClient,
238+ } ) ;
239+ const Foos = new Entity ( {
240+ name : 'Foo' ,
241+ table : FoosTable ,
242+ timestamps : true ,
243+ attributes : {
244+ pk : { hidden : true , partitionKey : true , default : ( data ) => ( `FOO#${ data . id } ` ) } ,
245+ sk : { hidden : true , sortKey : true , default : ( data ) => ( `FOO#${ data . id } ` ) } ,
246+
247+ // This next `default` gets executed on delete() and fails with "Cannot read property 'tenant' of undefined"
248+ gsi1pk : { hidden : true , default : ( data ) => ( `TENANT#${ data . meta . tenant } ` ) } ,
249+
250+ gsi1sk : { hidden : true , default : ( data ) => ( `FOO#${ data . id } ` ) } ,
251+ id : { required : 'always' } ,
252+ meta : { type : 'map' , required : 'always' } ,
253+ __context__ : { hidden : true } ,
254+ } ,
255+ } ) ;
256+
257+ const key = { id : 'xyz' }
258+ let result = Foos . deleteParams ( key ) // Fails with v0.2.0-beta. Fine with v0.2.0-alpha
259+ expect ( result ) . toEqual ( { TableName : 'test-table' , Key : { pk : 'FOO#xyz' , sk : 'FOO#xyz' } } )
260+ } )
261+
227262} )
0 commit comments