Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mindler-olli committed Mar 19, 2024
1 parent 5635176 commit b57b68a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`PutItemQueryBuilder > handles 'contains' ConditionExpression 1`] = `
{
"dataTimestamp": 212,
"tags": [
"cats",
],
"userId": "333",
}
`;
70 changes: 67 additions & 3 deletions src/queryBuilders/putItemQueryBuilder.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DDB, TEST_DATA } from "../../test/testFixture";
import { DDB } from "../../test/testFixture";
import { getDDBClientFor, startDDBTestContainer } from "../../test/testUtil";
import { Tsynamo } from "./../index";

describe("GetItemQueryBuilder", () => {
describe("PutItemQueryBuilder", () => {
let tsynamoClient: Tsynamo<DDB>;

const itemToPut = {
Expand Down Expand Up @@ -78,5 +78,69 @@ describe("GetItemQueryBuilder", () => {
);
});

it.todo("handles 'contains' ConditionExpression");
it("handles 'contains' ConditionExpression", async () => {
await tsynamoClient
.putItem("myTable")
.item({
userId: "333",
dataTimestamp: 212,
tags: ["cats"],
})
.execute();

const oldValues = await tsynamoClient
.putItem("myTable")
.item({
userId: "333",
dataTimestamp: 212,
tags: ["cats"],
})
.conditionExpression("tags", "contains", "cats")
.returnValues("ALL_OLD")
.execute();

expect(oldValues).toBeTruthy();
expect(oldValues).toMatchSnapshot();

expect(
tsynamoClient
.putItem("myTable")
.item({
userId: "333",
dataTimestamp: 212,
})
.conditionExpression("NOT", (qb) =>
qb.expression("tags", "contains", "cats")
)
.execute()
).rejects.toMatchInlineSnapshot(
`[ConditionalCheckFailedException: The conditional request failed]`
);
});

it("Handles nested ConditionExpressions", async () => {
await tsynamoClient
.putItem("myTable")
.item({
userId: "333",
dataTimestamp: 212,
nested: {
nestedBoolean: false,
},
})
.execute();

expect(
tsynamoClient
.putItem("myTable")
.item({
userId: "333",
dataTimestamp: 212,
})
.conditionExpression("nested.nestedBoolean", "=", true)
.execute()
).rejects.toMatchInlineSnapshot(
`[ConditionalCheckFailedException: The conditional request failed]`
);
});
});

0 comments on commit b57b68a

Please sign in to comment.