Skip to content

Commit

Permalink
add test for update item query with condition expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mindler-olli committed Apr 10, 2024
1 parent db04c7c commit dd6148c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ exports[`UpdateItemQueryBuilder > handles update item query with SET statements
}
`;

exports[`UpdateItemQueryBuilder > handles update item query with condition expressions 2`] = `
{
"dataTimestamp": 2,
"someSet": Set {
"1",
"2",
"3",
},
"somethingElse": 0,
"userId": "1",
}
`;

exports[`UpdateItemQueryBuilder > handles update item query with multiple different operations 1`] = `
{
"dataTimestamp": 2,
Expand Down
31 changes: 30 additions & 1 deletion src/queryBuilders/updateItemQueryBuilder.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,34 @@ describe("UpdateItemQueryBuilder", () => {
expect(foundItem).toMatchSnapshot();
});

it.todo("handles update item query with condition expressions");
it("handles update item query with condition expressions", async () => {
await tsynamoClient
.putItem("myTable")
.item({
userId: "1",
dataTimestamp: 2,
someSet: new Set(["1", "2", "3"]),
somethingElse: 0,
})
.execute();

expect(
tsynamoClient
.updateItem("myTable")
.keys({ userId: "1", dataTimestamp: 2 })
.remove("someSet")
.remove("somethingElse")
.conditionExpression("somethingElse", ">", 0)
.execute()
).rejects.toMatchInlineSnapshot(
`[ConditionalCheckFailedException: The conditional request failed]`
);

const foundItem = await tsynamoClient
.getItem("myTable")
.keys({ userId: "1", dataTimestamp: 2 })
.execute();

expect(foundItem).toMatchSnapshot();

Check failure on line 187 in src/queryBuilders/updateItemQueryBuilder.integration.test.ts

View workflow job for this annotation

GitHub Actions / test

src/queryBuilders/updateItemQueryBuilder.integration.test.ts > UpdateItemQueryBuilder > handles update item query with condition expressions

Error: Snapshot `UpdateItemQueryBuilder > handles update item query with condition expressions 1` mismatched ❯ src/queryBuilders/updateItemQueryBuilder.integration.test.ts:187:23
});
});
1 change: 1 addition & 0 deletions src/queryBuilders/updateItemQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface UpdateItemQueryBuilderInterface<
pk: Keys
): UpdateItemQueryBuilderInterface<DDB, Table, O>;

// TODO: Make it possible to delete a whole object, and not just nested keys
remove<Key extends ObjectKeyPaths<PickNonKeys<DDB[Table]>>>(
attribute: Key
): UpdateItemQueryBuilderInterface<DDB, Table, O>;
Expand Down

0 comments on commit dd6148c

Please sign in to comment.