@@ -21,23 +21,26 @@ describe('sinks/dynamodb.js', () => {
2121
2222 it ( 'should calculate updateExpression' , ( ) => {
2323 expect ( updateExpression ( {
24- id : '2f8ac025-d9e3-48f9-ba80-56487ddf0b89' ,
25- name : 'Thing One' ,
26- description : 'This is thing one.' ,
27- status : undefined ,
28- status2 : null ,
29- discriminator : 'thing' ,
30- latched : true ,
31- ttl : ttl ( 1540454400000 , 30 ) ,
32- timestamp : 1540454400000 ,
24+ 'id' : '2f8ac025-d9e3-48f9-ba80-56487ddf0b89' ,
25+ 'name' : 'Thing One' ,
26+ 'description' : 'This is thing one.' ,
27+ 'status' : undefined ,
28+ 'status2' : null ,
29+ 'discriminator' : 'thing' ,
30+ 'latched' : true ,
31+ 'ttl' : ttl ( 1540454400000 , 30 ) ,
32+ 'timestamp' : 1540454400000 ,
33+ 'some unsafe att name' : true ,
34+ 'some unsafe att name to delete' : null ,
3335 } ) ) . to . deep . equal ( {
3436 ExpressionAttributeNames : {
3537 '#description' : 'description' ,
3638 '#discriminator' : 'discriminator' ,
3739 '#id' : 'id' ,
3840 '#latched' : 'latched' ,
3941 '#name' : 'name' ,
40- // '#status': 'status',
42+ '#some_x20_unsafe_x20_att_x20_name' : 'some unsafe att name' ,
43+ '#some_x20_unsafe_x20_att_x20_name_x20_to_x20_delete' : 'some unsafe att name to delete' ,
4144 '#status2' : 'status2' ,
4245 '#timestamp' : 'timestamp' ,
4346 '#ttl' : 'ttl' ,
@@ -48,12 +51,11 @@ describe('sinks/dynamodb.js', () => {
4851 ':id' : '2f8ac025-d9e3-48f9-ba80-56487ddf0b89' ,
4952 ':latched' : true ,
5053 ':name' : 'Thing One' ,
51- // ':status': undefined,
52- // ':status2': null,
54+ ':some_x20_unsafe_x20_att_x20_name' : true ,
5355 ':timestamp' : 1540454400000 ,
5456 ':ttl' : 1543046400 ,
5557 } ,
56- UpdateExpression : 'SET #id = :id, #name = :name, #description = :description, #discriminator = :discriminator, #latched = :latched, #ttl = :ttl, #timestamp = :timestamp REMOVE #status2' ,
58+ UpdateExpression : 'SET #id = :id, #name = :name, #description = :description, #discriminator = :discriminator, #latched = :latched, #ttl = :ttl, #timestamp = :timestamp, #some_x20_unsafe_x20_att_x20_name = :some_x20_unsafe_x20_att_x20_name REMOVE #status2, #some_x20_unsafe_x20_att_x20_name_x20_to_x20_delete ' ,
5759 ReturnValues : 'ALL_NEW' ,
5860 } ) ;
5961 } ) ;
@@ -92,6 +94,35 @@ describe('sinks/dynamodb.js', () => {
9294 } ) ;
9395 } ) ;
9496
97+ it ( 'should calculate updateExpression removing values from a set when attribute names have illegal characters if used as an alias' , ( ) => {
98+ const result = updateExpression ( {
99+ 'some|tags_delete' : new Set ( [ 'x' , 'y' ] ) ,
100+ 'a-b' : true ,
101+ 'a--b' : false ,
102+ 'a|b' : 1 ,
103+ } ) ;
104+
105+ expect ( normalizeObj ( result ) ) . to . deep . equal ( {
106+ ExpressionAttributeNames : {
107+ '#some_x7c_tags' : 'some|tags' ,
108+ '#a_x2d_b' : 'a-b' ,
109+ '#a_x2d__x2d_b' : 'a--b' ,
110+ '#a_x7c_b' : 'a|b' ,
111+ } ,
112+ ExpressionAttributeValues : {
113+ ':some_x7c_tags_delete' : [
114+ 'x' ,
115+ 'y' ,
116+ ] ,
117+ ':a_x2d_b' : true ,
118+ ':a_x2d__x2d_b' : false ,
119+ ':a_x7c_b' : 1 ,
120+ } ,
121+ UpdateExpression : 'SET #a_x2d_b = :a_x2d_b, #a_x2d__x2d_b = :a_x2d__x2d_b, #a_x7c_b = :a_x7c_b DELETE #some_x7c_tags :some_x7c_tags_delete' ,
122+ ReturnValues : 'ALL_NEW' ,
123+ } ) ;
124+ } ) ;
125+
95126 it ( 'should wrap calculate updateExpression wrapping a delete set value in a set' , ( ) => {
96127 const result = updateExpression ( {
97128 tags_delete : 'x' ,
0 commit comments