Skip to content

Commit

Permalink
add test for updateItemQueryBuilder compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
mindler-olli committed Apr 10, 2024
1 parent 66003d0 commit e56b09a
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 9 deletions.
110 changes: 110 additions & 0 deletions src/queryCompiler/__snapshots__/queryCompiler.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,113 @@ QueryCommand {
},
}
`;

exports[`QueryQueryBuilder > updateItemQueryBuilder can be compiled 1`] = `
UpdateCommand {
"clientCommand": UpdateItemCommand {
"deserialize": [Function],
"input": {
"ConditionExpression": undefined,
"ExpressionAttributeNames": {
"#nested": "nested",
"#nestedBoolean": "nestedBoolean",
"#nestedSet": "nestedSet",
"#someBoolean": "someBoolean",
"#someSet": "someSet",
},
"ExpressionAttributeValues": {
":addUpdateExpressionValue1": Set {
"1",
"2",
},
":deleteUpdateExpressionValue2": Set {
"a",
},
":setUpdateExpressionValue0": true,
},
"Key": {
"dataTimestamp": 2,
"userId": "1",
},
"ReturnValues": undefined,
"TableName": "myTable",
"UpdateExpression": "SET #nested.#nestedBoolean = :setUpdateExpressionValue0 REMOVE #someBoolean ADD #someSet :addUpdateExpressionValue1 DELETE #nested.#nestedSet :deleteUpdateExpressionValue2",
},
"middlewareStack": {
"add": [Function],
"addRelativeTo": [Function],
"applyToStack": [Function],
"clone": [Function],
"concat": [Function],
"identify": [Function],
"identifyOnResolve": [Function],
"remove": [Function],
"removeByTag": [Function],
"resolve": [Function],
"use": [Function],
},
"serialize": [Function],
},
"input": {
"ConditionExpression": undefined,
"ExpressionAttributeNames": {
"#nested": "nested",
"#nestedBoolean": "nestedBoolean",
"#nestedSet": "nestedSet",
"#someBoolean": "someBoolean",
"#someSet": "someSet",
},
"ExpressionAttributeValues": {
":addUpdateExpressionValue1": Set {
"1",
"2",
},
":deleteUpdateExpressionValue2": Set {
"a",
},
":setUpdateExpressionValue0": true,
},
"Key": {
"dataTimestamp": 2,
"userId": "1",
},
"ReturnValues": undefined,
"TableName": "myTable",
"UpdateExpression": "SET #nested.#nestedBoolean = :setUpdateExpressionValue0 REMOVE #someBoolean ADD #someSet :addUpdateExpressionValue1 DELETE #nested.#nestedSet :deleteUpdateExpressionValue2",
},
"inputKeyNodes": {
"AttributeUpdates": {
"*": {
"Value": null,
},
},
"Expected": {
"*": {
"AttributeValueList": [],
"Value": null,
},
},
"ExpressionAttributeValues": {},
"Key": {},
},
"middlewareStack": {
"add": [Function],
"addRelativeTo": [Function],
"applyToStack": [Function],
"clone": [Function],
"concat": [Function],
"identify": [Function],
"identifyOnResolve": [Function],
"remove": [Function],
"removeByTag": [Function],
"resolve": [Function],
"use": [Function],
},
"outputKeyNodes": {
"Attributes": {},
"ItemCollectionMetrics": {
"ItemCollectionKey": {},
},
},
}
`;
32 changes: 23 additions & 9 deletions src/queryCompiler/queryCompiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe("QueryQueryBuilder", () => {
});
});

it("queryQueryBuilder can be compiled", async () => {
const data = await tsynamoClient
it("queryQueryBuilder can be compiled", () => {
const data = tsynamoClient
.query("myTable")
.keyCondition("userId", "=", "123")
.filterExpression("someBoolean", "=", true)
Expand All @@ -25,8 +25,8 @@ describe("QueryQueryBuilder", () => {
expect(data).toMatchSnapshot();
});

it("putItemQueryBuilder can be compiled", async () => {
const data = await tsynamoClient
it("putItemQueryBuilder can be compiled", () => {
const data = tsynamoClient
.putItem("myTable")
.item({
userId: "333",
Expand All @@ -38,8 +38,8 @@ describe("QueryQueryBuilder", () => {
expect(data).toMatchSnapshot();
});

it("getItemQueryBuilder can be compiled", async () => {
const data = await tsynamoClient
it("getItemQueryBuilder can be compiled", () => {
const data = tsynamoClient
.getItem("myTable")
.keys({
userId: TEST_DATA[1].userId,
Expand All @@ -50,8 +50,8 @@ describe("QueryQueryBuilder", () => {
expect(data).toMatchSnapshot();
});

it("deleteItemQueryBuilder can be compiled", async () => {
const data = await tsynamoClient
it("deleteItemQueryBuilder can be compiled", () => {
const data = tsynamoClient
.deleteItem("myTable")
.keys({
userId: "1",
Expand All @@ -63,5 +63,19 @@ describe("QueryQueryBuilder", () => {
expect(data).toMatchSnapshot();
});

it.todo("updateItemQueryBuilder can be compiled");
it("updateItemQueryBuilder can be compiled", () => {
const data = tsynamoClient
.updateItem("myTable")
.keys({
userId: "1",
dataTimestamp: 2,
})
.add("someSet", new Set(["1", "2"]))
.set("nested.nestedBoolean", "=", true)
.remove("someBoolean")
.delete("nested.nestedSet", new Set(["a"]))
.compile();

expect(data).toMatchSnapshot();
});
});

0 comments on commit e56b09a

Please sign in to comment.