From e56b09a200b7c5a0a342c07d23c2ff5cf54be103 Mon Sep 17 00:00:00 2001 From: Olli Warro Date: Wed, 10 Apr 2024 11:40:46 +0300 Subject: [PATCH] add test for updateItemQueryBuilder compilation --- .../__snapshots__/queryCompiler.test.ts.snap | 110 ++++++++++++++++++ src/queryCompiler/queryCompiler.test.ts | 32 +++-- 2 files changed, 133 insertions(+), 9 deletions(-) diff --git a/src/queryCompiler/__snapshots__/queryCompiler.test.ts.snap b/src/queryCompiler/__snapshots__/queryCompiler.test.ts.snap index adbf467..0a40dd2 100644 --- a/src/queryCompiler/__snapshots__/queryCompiler.test.ts.snap +++ b/src/queryCompiler/__snapshots__/queryCompiler.test.ts.snap @@ -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": {}, + }, + }, +} +`; diff --git a/src/queryCompiler/queryCompiler.test.ts b/src/queryCompiler/queryCompiler.test.ts index e61f75b..08fdb84 100644 --- a/src/queryCompiler/queryCompiler.test.ts +++ b/src/queryCompiler/queryCompiler.test.ts @@ -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) @@ -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", @@ -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, @@ -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", @@ -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(); + }); });