From 44c138ef75d30d3108e25941491e099ef981c4f8 Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Wed, 26 Oct 2022 11:07:03 +0900 Subject: [PATCH 1/3] Add failing test for 'in (false)' condition expr --- test/updateItem.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/updateItem.js b/test/updateItem.js index d1b811e..894cc6f 100644 --- a/test/updateItem.js +++ b/test/updateItem.js @@ -1450,6 +1450,11 @@ describe('updateItem', function() { UpdateExpression: 'SET #b = :b', ExpressionAttributeNames: {'#a': 'active', '#b': 'active'}, ExpressionAttributeValues: {':a': {BOOL: false}, ':b': {BOOL: true}}, + }, { + ConditionExpression: '#a IN (:a)', + UpdateExpression: 'SET #a = :b', + ExpressionAttributeNames: {'#a': 'active'}, + ExpressionAttributeValues: {':a': {BOOL: false}, ':b': {BOOL: true}}, }], function(updateOpts, cb) { var item = {a: {S: helpers.randomString()}, active: {BOOL: false}} request(helpers.opts('PutItem', {TableName: helpers.testHashTable, Item: item}), function(err, res) { From 974b891f6f32bb2d81d3975d3005211113da16d3 Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Wed, 26 Oct 2022 14:02:20 +0900 Subject: [PATCH 2/3] fix 'in' condition expression --- db/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/db/index.js b/db/index.js index 03f29d4..5236176 100644 --- a/db/index.js +++ b/db/index.js @@ -692,7 +692,6 @@ function compare(comp, val, compVals) { break case 'IN': case 'in': - if (!attrVal) return false if (!compVals.some(function(compVal) { compType = Object.keys(compVal)[0] compVal = compVal[compType] From 13efc3cafc0f3ffbb46ed0fe85138b231d463e71 Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Wed, 26 Oct 2022 14:42:10 +0900 Subject: [PATCH 3/3] add test for update item with conditions checking for falsey values --- test/updateItem.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/updateItem.js b/test/updateItem.js index 894cc6f..9e18f53 100644 --- a/test/updateItem.js +++ b/test/updateItem.js @@ -1474,6 +1474,31 @@ describe('updateItem', function() { }, done) }) + it('should update when falsey in condition matches', function(done) { + async.forEach([{BOOL:false}, {S:""}, {N: "0.0"}, {"N": "0"}, {NULL: true}], function(value, cb) { + var item = {a: {S: helpers.randomString()}, updated: {BOOL: false}, value: value} + request(helpers.opts('PutItem', {TableName: helpers.testHashTable, Item: item}), function(err, res) { + if (err) return cb(err) + res.statusCode.should.equal(200) + res.body.should.eql({}) + request(opts({ + TableName: helpers.testHashTable, + Key: {a: item.a}, + ReturnValues: 'UPDATED_NEW', + UpdateExpression: 'SET #u = :t', + ConditionExpression: '#v in (:v)', + ExpressionAttributeNames: {'#u': 'updated', '#v': 'value'}, + ExpressionAttributeValues: {':t': {BOOL: true}, ':v': value}, + }), function(err, res) { + if (err) return cb(err) + res.statusCode.should.equal(200, `Update failed when checking for {${Object.keys(value)[0]}:${Object.values(value)[0]}}`) + res.body.should.eql({Attributes: {updated: {BOOL: true}}}) + cb() + }) + }) + }, done) + }) + it('should update values from other attributes', function(done) { var key = {a: {S: helpers.randomString()}} request(opts({