How do I mock dynamoDB.DocumentClient batchWrite? "Requested resource not found"
This is my pattern on all, works for 'get' 'put' 'delete' and so on. But when I try to mock batchWrite it doesn't find my mockup. Have also tried 'batchWriteItem' does not work.
AWS.mock('DynamoDB.DocumentClient', 'batchWrite', (params: any, callback: any) => callback(null, {}));
Anyone know how?
The method you're looking for is probably batchWriteItem. batchWrite doesn't seem to be a method exposed by AWS SDK.
The method you're looking for is probably
batchWriteItem.batchWritedoesn't seem to be a method exposed by AWS SDK.
No, for DocumentClient it is really called batchWrite: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#batchWrite-property
Was there ever an answer for this? I am encountering the same issue. In my case I got past the error by providing params that validly represent a real dynamoDB table. Then it was clear that the mock was not working because the non-mocked PutItem actually completed and wrote the item to the specified table.
Here is my code: `describe('Tweet handling', function() { describe('Handle tweet with reference', function() { it('should write a single request', function() { var AWS = require("aws-sdk");
awsMock.mock('DynamoDB.DocumentClient', 'batchWrite', function(params, callback){
callback(null, 'test');
});
var docClient = new AWS.DynamoDB.DocumentClient();
var batchWriteJSON =
{
RequestItems: {
'TestTable': [
{
PutRequest: {
Item: {
id: '1',
a: 'b',
b: 'c'
}
}
}
]
}
};
docClient.batchWrite(batchWriteJSON, function(err, data){
assert.equal(data, 'test');
awsMock.restore('DynamoDB.DocumentClient', 'batchWrite');
});
});
}); }); `
When I created a TestTable, the test created the item with the specified properties.
Is there any plans to mock batchWrite on DynamoDB.DocumentClient
from the aws docs:
Puts or deletes multiple items in one or more tables by delegating to AWS.DynamoDB.batchWriteItem().
so @kevinrambaud was right, i was able to mock using a sinon stub doing this:
const dynamoBatchWriteStub = sinon.stub().resolves(WHATEVER)
AWS.mock('DynamoDB', 'batchWriteItem', dynamoBatchWriteStub)
fwiw, this will only apply to dynamoDb.DocumentClient.batchWrite().promise()