-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure no undefines in update requests.
- Loading branch information
Showing
6 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"cSpell.words": [ | ||
"atsquad", | ||
"cimpress", | ||
"clonedeep", | ||
"Fqdn", | ||
"microsoftonline", | ||
"nosniff", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Change log | ||
|
||
## 1.0 ## | ||
* Coerce `undefined` expression attribute values to `null`, because dynamoDb can't handle that, and it strips them from the request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { expect } = require('chai'); | ||
const { describe, it, beforeEach, afterEach } = require('mocha'); | ||
const sinon = require('sinon'); | ||
const { DynamoDB: DynamoDbOriginal } = require('aws-sdk'); | ||
|
||
let sandbox; | ||
beforeEach(() => { sandbox = sinon.createSandbox(); }); | ||
afterEach(() => sandbox.restore()); | ||
|
||
const { DynamoDB } = require('../src/dynamoDbSafe'); | ||
const cloneDeep = require('lodash.clonedeep'); | ||
|
||
describe('dynamoDbArmor.js', () => { | ||
describe('namesAndValuesCoercion()', () => { | ||
it('Fixes undefined expressionAttributeValue - Coerce `undefined` expression attribute values to `null`, because dynamoDb cant handle them, and it strips them from the request. nulls are not stripped', async () => { | ||
const testTable = 'Test-TableId'; | ||
const testHash = 'testHash'; | ||
const testRange = 'testRange'; | ||
const params = { | ||
TableName: testTable, | ||
Key: { | ||
hash: testHash, | ||
rang: testRange | ||
}, | ||
UpdateExpression: 'SET #key = :value', | ||
ConditionExpression: 'attribute_exists(hash)', | ||
ExpressionAttributeNames: { | ||
'#key': 'key' | ||
}, | ||
ExpressionAttributeValues: { | ||
':value': undefined | ||
} | ||
}; | ||
try { | ||
const dynamoDbOriginalMock = sandbox.mock(DynamoDbOriginal.DocumentClient.prototype); | ||
|
||
const expectedParams = cloneDeep(params); | ||
expectedParams.ExpressionAttributeValues[':value'] = null; | ||
dynamoDbOriginalMock.expects('update').once().withArgs(expectedParams).returns({ promise() { return Promise.resolve(); } }); | ||
await new DynamoDB().update(params); | ||
dynamoDbOriginalMock.verify(); | ||
} catch (error) { | ||
expect(error.message).to.eql(null, JSON.stringify(error.message, null, 2)); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters