I am mocking DynamoDB query using aws-sdk-mock
. It seems what ever query params I pass it will always match. For example looking at the implementation:
const AWS = require("aws-sdk");
...
const dynamoDB = new AWS.DynamoDB.DocumentClient();
await dynamoDB
.query({
TableName: dynamoDBTableName,
IndexName: gsiIndexName,
KeyConditionExpression: "active = :active and reference_id = :ref_id",
ExpressionAttributeValues: {
":ref_id": referenceID,
":active": 1,
},
})
.promise()
.then((returnData) => (data = returnData))
.catch(console.error);
And my test file mocks this call like so:
const dynamoDBQueryParams = {
TableName: "TABLE_NAME",
IndexName: "INDEX_NAME",
KeyConditionExpression: "active = :active and reference_id = :ref_id",
ExpressionAttributeValues: {
":ref_id": event.pathParameters.referenceDataID,
":active": 1,
},
}
AWS.mock('DynamoDB.DocumentClient', 'query', function(dynamoDBQueryParams, callback) {
callback(null, dynamoDBExpectedReturnValues);
});
No matter what the dynamoDBTableName
and gsiIndexName
are when running the test it always will return the dynamoDBExpectedReturnValues
. Surely if these params dont patch the mocked response should not be returned but it is. How can I assure that the matching logic is correct? Or have I implemented the mock incorrectly?
Thank you very much in advance.