@@ -84,11 +84,12 @@ describe('update',()=>{
8484 it ( 'creates default update' , ( ) => {
8585 let { TableName, Key, UpdateExpression, ExpressionAttributeNames, ExpressionAttributeValues } = TestEntity . updateParams ( { pk : 'test-pk' , sk : 'test-sk' } )
8686
87- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et)' )
88- expect ( ExpressionAttributeNames ) . toEqual ( { '#_md' : '_md' , '#_ct' : '_ct' , '#test_string' : 'test_string' , '#_et' : '_et' } )
87+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et)' )
88+ expect ( ExpressionAttributeNames ) . toEqual ( { '#_md' : '_md' , '#_ct' : '_ct' , '#test_string' : 'test_string' , '#test_number_coerce' : 'test_number_coerce' , '# _et' : '_et' } )
8989 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
9090 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
9191 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':test_string' )
92+ expect ( ExpressionAttributeValues ) . toHaveProperty ( ':test_number_coerce' )
9293 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_et' )
9394 expect ( ExpressionAttributeValues [ ':_et' ] ) . toBe ( 'TestEntity' )
9495 expect ( Key ) . toEqual ( { pk : 'test-pk' , sk : 'test-sk' } )
@@ -102,13 +103,14 @@ describe('update',()=>{
102103 sk : 'test-sk' ,
103104 test_string : 'test string'
104105 } )
105- expect ( UpdateExpression ) . toBe ( 'SET #test_string = :test_string, #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et)' )
106- expect ( ExpressionAttributeNames ) . toEqual ( { '#_md' : '_md' , '#_ct' : '_ct' , '#test_string' : 'test_string' , '#_et' : '_et' } )
106+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = :test_string, #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et)' )
107+ expect ( ExpressionAttributeNames ) . toEqual ( { '#_md' : '_md' , '#_ct' : '_ct' , '#test_string' : 'test_string' , '#test_number_coerce' : 'test_number_coerce' , '# _et' : '_et' } )
107108 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
108109 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
109110 expect ( ExpressionAttributeValues ) . not . toHaveProperty ( ':pk' )
110111 expect ( ExpressionAttributeValues ) . not . toHaveProperty ( ':sk' )
111112 expect ( ExpressionAttributeValues [ ':test_string' ] ) . toBe ( 'test string' )
113+ expect ( ExpressionAttributeValues ) . toHaveProperty ( ':test_number_coerce' )
112114 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_et' )
113115 expect ( ExpressionAttributeValues [ ':_et' ] ) . toBe ( 'TestEntity' )
114116 expect ( Key ) . toEqual ( { pk : 'test-pk' , sk : 'test-sk' } )
@@ -265,8 +267,8 @@ describe('update',()=>{
265267 test_number : { $add : 10 } ,
266268 test_number_set_type : { $add : [ 1 , 2 , 3 ] }
267269 } )
268- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) ADD #test_number :test_number, #test_number_set_type :test_number_set_type' )
269- expect ( ExpressionAttributeNames ) . toEqual ( { '#_md' : '_md' , '#_ct' : '_ct' , '#test_string' : 'test_string' , '#_et' : '_et' , '#test_number' : 'test_number' , '#test_number_set_type' : 'test_number_set_type' } )
270+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) ADD #test_number :test_number, #test_number_set_type :test_number_set_type' )
271+ expect ( ExpressionAttributeNames ) . toEqual ( { '#_md' : '_md' , '#_ct' : '_ct' , '#test_string' : 'test_string' , '#_et' : '_et' , '#test_number' : 'test_number' , '#test_number_set_type' : 'test_number_set_type' , '#test_number_coerce' : 'test_number_coerce' } )
270272 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
271273 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
272274 expect ( ExpressionAttributeValues ) . not . toHaveProperty ( ':pk' )
@@ -287,14 +289,15 @@ describe('update',()=>{
287289 test_string_set_type : { $delete : [ '1' , '2' , '3' ] } ,
288290 test_number_set_type : { $delete : [ 1 , 2 , 3 ] }
289291 } )
290- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) DELETE #test_string_set_type :test_string_set_type, #test_number_set_type :test_number_set_type' )
292+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) DELETE #test_string_set_type :test_string_set_type, #test_number_set_type :test_number_set_type' )
291293 expect ( ExpressionAttributeNames ) . toEqual ( {
292294 '#test_string' : 'test_string' ,
293295 '#_et' : '_et' ,
294296 '#_ct' : '_ct' ,
295297 '#_md' : '_md' ,
296298 '#test_string_set_type' : 'test_string_set_type' ,
297- '#test_number_set_type' : 'test_number_set_type'
299+ '#test_number_set_type' : 'test_number_set_type' ,
300+ '#test_number_coerce' : 'test_number_coerce'
298301 } )
299302 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
300303 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
@@ -315,13 +318,14 @@ describe('update',()=>{
315318 sk : 'test-sk' ,
316319 test_list : { $remove : [ 2 , 3 , 8 ] }
317320 } )
318- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) REMOVE #test_list[2], #test_list[3], #test_list[8]' )
321+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) REMOVE #test_list[2], #test_list[3], #test_list[8]' )
319322 expect ( ExpressionAttributeNames ) . toEqual ( {
320323 '#test_string' : 'test_string' ,
321324 '#_et' : '_et' ,
322325 '#_ct' : '_ct' ,
323326 '#_md' : '_md' ,
324- '#test_list' : 'test_list'
327+ '#test_list' : 'test_list' ,
328+ '#test_number_coerce' : 'test_number_coerce'
325329 } )
326330 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
327331 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
@@ -339,13 +343,14 @@ describe('update',()=>{
339343 sk : 'test-sk' ,
340344 test_list : { 2 : 'Test2' , 5 : 'Test5' }
341345 } )
342- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_list[2] = :test_list_2, #test_list[5] = :test_list_5' )
346+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_list[2] = :test_list_2, #test_list[5] = :test_list_5' )
343347 expect ( ExpressionAttributeNames ) . toEqual ( {
344348 '#test_string' : 'test_string' ,
345349 '#_et' : '_et' ,
346350 '#_ct' : '_ct' ,
347351 '#_md' : '_md' ,
348- '#test_list' : 'test_list'
352+ '#test_list' : 'test_list' ,
353+ '#test_number_coerce' : 'test_number_coerce'
349354 } )
350355 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
351356 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
@@ -367,14 +372,15 @@ describe('update',()=>{
367372 test_list : { $append : [ 1 , 2 , 3 ] } ,
368373 test_list_coerce : { $prepend : [ 1 , 2 , 3 ] }
369374 } )
370- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_list = list_append(#test_list,:test_list), #test_list_coerce = list_append(:test_list_coerce,#test_list_coerce)' )
375+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_list = list_append(#test_list,:test_list), #test_list_coerce = list_append(:test_list_coerce,#test_list_coerce)' )
371376 expect ( ExpressionAttributeNames ) . toEqual ( {
372377 '#test_string' : 'test_string' ,
373378 '#_et' : '_et' ,
374379 '#_ct' : '_ct' ,
375380 '#_md' : '_md' ,
376381 '#test_list' : 'test_list' ,
377- '#test_list_coerce' : 'test_list_coerce'
382+ '#test_list_coerce' : 'test_list_coerce' ,
383+ '#test_number_coerce' : 'test_number_coerce'
378384 } )
379385 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_md' )
380386 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_ct' )
@@ -401,7 +407,7 @@ describe('update',()=>{
401407 'prop5' : [ 1 , 2 , 3 ]
402408 } }
403409 } )
404- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_map.#test_map_prop1 = :test_map_prop1, #test_map.#test_map_prop2[1] = :test_map_prop2_1, #test_map.#test_map_prop2[4] = :test_map_prop2_4, #test_map.#test_map_prop3.#test_map_prop3_prop4 = :test_map_prop3_prop4, #test_map.#test_map_prop5 = :test_map_prop5' )
410+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_map.#test_map_prop1 = :test_map_prop1, #test_map.#test_map_prop2[1] = :test_map_prop2_1, #test_map.#test_map_prop2[4] = :test_map_prop2_4, #test_map.#test_map_prop3.#test_map_prop3_prop4 = :test_map_prop3_prop4, #test_map.#test_map_prop5 = :test_map_prop5' )
405411 expect ( ExpressionAttributeNames ) . toEqual ( {
406412 '#_et' : '_et' ,
407413 '#_ct' : '_ct' ,
@@ -412,7 +418,8 @@ describe('update',()=>{
412418 '#test_map_prop3' : 'prop3' ,
413419 '#test_map_prop3_prop4' : 'prop4' ,
414420 '#test_map_prop5' : 'prop5' ,
415- '#test_map' : 'test_map'
421+ '#test_map' : 'test_map' ,
422+ '#test_number_coerce' : 'test_number_coerce'
416423 } )
417424 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_et' )
418425 expect ( ExpressionAttributeValues [ ':_et' ] ) . toBe ( 'TestEntity' )
@@ -434,14 +441,15 @@ describe('update',()=>{
434441 count : { $add : 10 } ,
435442 contents : { a : 1 , b : 2 }
436443 } )
437- expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_map = :test_map ADD #test_number :test_number' )
444+ expect ( UpdateExpression ) . toBe ( 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = :test_number_coerce, # _ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et), #test_map = :test_map ADD #test_number :test_number' )
438445 expect ( ExpressionAttributeNames ) . toEqual ( {
439446 '#_et' : '_et' ,
440447 '#_ct' : '_ct' ,
441448 '#_md' : '_md' ,
442449 '#test_string' : 'test_string' ,
443450 '#test_number' : 'test_number' ,
444- '#test_map' : 'test_map'
451+ '#test_map' : 'test_map' ,
452+ '#test_number_coerce' : 'test_number_coerce'
445453 } )
446454 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':_et' )
447455 expect ( ExpressionAttributeValues [ ':_et' ] ) . toBe ( 'TestEntity' )
@@ -622,7 +630,8 @@ describe('update',()=>{
622630 '#_ct' : '_ct' ,
623631 '#_md' : '_md' ,
624632 '#_et' : '_et' ,
625- '#attr1' : 'pk'
633+ '#attr1' : 'pk' ,
634+ '#test_number_coerce' : 'test_number_coerce'
626635 } )
627636 expect ( ExpressionAttributeValues ) . toHaveProperty ( ':attr1' )
628637 expect ( ConditionExpression ) . toBe ( '#attr1 > :attr1' )
0 commit comments