Skip to content

Commit

Permalink
Merge pull request #18 from valentinbeggi/create-toExistInDynamoTable…
Browse files Browse the repository at this point in the history
…-assertion

feat: create toExistInDynamoTable assertion
  • Loading branch information
Alexander White authored Jan 4, 2022
2 parents 90aa586 + 09c5a5e commit 1c4e4ef
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/assertions/toExistInDynamoTable/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { AWSClient } from "../../helpers/general";

export default {
async toExistInDynamoTable({ PK, SK }, tableName) {
const docClient = new AWSClient.DynamoDB.DocumentClient();

if (!docClient) {
return {
message: () => "expected table to contain document client",
pass: false,
};
}

if (!SK) {
const queryParams = {
TableName: tableName,
KeyConditionExpression: "#pk = :pk",
ExpressionAttributeNames: {
"#pk": "PK",
},
ExpressionAttributeValues: {
":pk": PK,
},
Limit: 1,
};

const result = await docClient.query(queryParams).promise();
return {
message: () => `expected to find ${PK} in ${tableName}`,
pass: result.Count === 1,
};
}

const getParams = {
TableName: tableName,
Key: {
PK,
SK,
},
};
const result = await docClient.get(getParams).promise();
return {
message: () => `expected to find ${PK} in ${tableName}`,
pass: result.Item !== undefined,
};
},
};

0 comments on commit 1c4e4ef

Please sign in to comment.