From 90018d5d5719eec03138f5b02e0d71162bb22b85 Mon Sep 17 00:00:00 2001 From: siddsriv Date: Wed, 24 Jan 2024 18:40:12 +0000 Subject: [PATCH] test(lib-dynamodb): adding additional test cases for function properties --- lib/lib-dynamodb/src/commands/utils.spec.ts | 88 ++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/lib/lib-dynamodb/src/commands/utils.spec.ts b/lib/lib-dynamodb/src/commands/utils.spec.ts index 5d203a8f5e535..c6c6fa85e4ad7 100644 --- a/lib/lib-dynamodb/src/commands/utils.spec.ts +++ b/lib/lib-dynamodb/src/commands/utils.spec.ts @@ -152,8 +152,94 @@ describe("object with function property", () => { const keyNodes = { Item: {} }; const nativeAttrObj = { Item: { id: 1, func: () => {} }, ...notAttrValue }; const attrObj = { Item: { id: { N: "1" } }, ...notAttrValue }; - it(marshallInput.name, () => { expect(marshallInput(nativeAttrObj, keyNodes, { convertTopLevelContainer: true })).toEqual(attrObj); }); + + // List of functions + const listOfFunctions = { Item: { id: 1, funcs: [() => {}, () => {}] }, ...notAttrValue }; + it(marshallInput.name, () => { + expect( + marshallInput(listOfFunctions, keyNodes, { convertTopLevelContainer: true, convertClassInstanceToMap: true }) + ).toEqual(attrObj); + }); + + // Nested list of functions + const nestedListOfFunctions = { + Item: { + id: 1, + funcs: [ + [() => {}, () => {}], + [() => {}, () => {}], + ], + }, + ...notAttrValue, + }; + it(marshallInput.name, () => { + expect( + marshallInput(nestedListOfFunctions, keyNodes, { + convertTopLevelContainer: true, + convertClassInstanceToMap: true, + }) + ).toEqual(attrObj); + }); + + // Nested list of functions 3 levels down + const nestedListOfFunctions3Levels = { + Item: { + id: 1, + funcs: [ + [ + [() => {}, () => {}], + [() => {}, () => {}], + ], + [ + [() => {}, () => {}], + [() => {}, () => {}], + ], + ], + }, + ...notAttrValue, + }; + it(marshallInput.name, () => { + expect( + marshallInput(nestedListOfFunctions3Levels, keyNodes, { + convertTopLevelContainer: true, + convertClassInstanceToMap: true, + }) + ).toEqual(attrObj); + }); + + // Map of functions + const mapOfFunctions = { Item: { id: 1, funcs: { func1: () => {}, func2: () => {} } }, ...notAttrValue }; + it(marshallInput.name, () => { + expect( + marshallInput(mapOfFunctions, keyNodes, { convertTopLevelContainer: true, convertClassInstanceToMap: true }) + ).toEqual(attrObj); + }); + + // Map of list of functions + const mapOfListOfFunctions = { + Item: { id: 1, funcs: { funcList1: [() => {}, () => {}], funcList2: [() => {}, () => {}] } }, + ...notAttrValue, + }; + it(marshallInput.name, () => { + expect( + marshallInput(mapOfListOfFunctions, keyNodes, { convertTopLevelContainer: true, convertClassInstanceToMap: true }) + ).toEqual(attrObj); + }); + + // Nested map of functions + const mapOfMapOfFunctions = { + Item: { + id: 1, + funcs: { funcMap1: { func1: () => {}, func2: () => {} }, funcMap2: { func1: () => {}, func2: () => {} } }, + }, + ...notAttrValue, + }; + it(marshallInput.name, () => { + expect( + marshallInput(mapOfMapOfFunctions, keyNodes, { convertTopLevelContainer: true, convertClassInstanceToMap: true }) + ).toEqual(attrObj); + }); });