Skip to content

Commit

Permalink
add test for a write transaction with failing conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mindler-olli committed May 30, 2024
1 parent fff584a commit bf2994d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`WriteTransactionBuilder > handles transaction with failing conditions 1`] = `[TransactionCanceledException: Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]]`;

exports[`WriteTransactionBuilder > handles transaction with puts 1`] = `
[
{
Expand Down
23 changes: 23 additions & 0 deletions src/queryBuilders/writeTransactionBuilder.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,27 @@ describe("WriteTransactionBuilder", () => {

expect(result).toMatchSnapshot();
});

it("handles transaction with failing conditions", async () => {
// Create a conflicting entry
await tsynamoClient
.putItem("myTable")
.item({ userId: "1", dataTimestamp: 2 })
.execute();

const trx = tsynamoClient.createWriteTransaction();

trx.addItem({
Put: tsynamoClient
.putItem("myTable")
.item({
userId: "1",
dataTimestamp: 2,
someBoolean: true,
})
.conditionExpression("userId", "attribute_not_exists"),
});

expect(trx.execute()).rejects.toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion src/queryBuilders/writeTransactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { UpdateItemQueryBuilder } from "./updateItemQueryBuilder";

export interface WriteTransactionBuilderInterface<DDB> {
/**
* TODO: ConditionCheck
* @todo add support for ConditionCheck items
*/
addItem(item: {
Put?: PutItemQueryBuilder<DDB, any, any>;
Expand Down

0 comments on commit bf2994d

Please sign in to comment.