Skip to content

Commit

Permalink
test(lib-dynamodb): adding cases for skipping function properties whe…
Browse files Browse the repository at this point in the history
…n processing keys
  • Loading branch information
siddsriv committed Jan 22, 2024
1 parent c58b50b commit bbaaf48
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/lib-dynamodb/src/commands/marshallInput.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ describe("marshallInput and processObj", () => {
}
);
});

it("marshallInput should ignore function properties", () => {
const input = { Items: [() => {}, 1, "test"] };
const inputKeyNodes = { Items: null };
const output = { Items: { L: [{ N: "1" }, { S: "test" }] } };
expect(
marshallInput(input, inputKeyNodes, { convertTopLevelContainer: true, convertClassInstanceToMap: true })
).toEqual(output);
});
});

describe("marshallInput for commands", () => {
Expand Down
6 changes: 6 additions & 0 deletions lib/lib-dynamodb/src/commands/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ describe("utils", () => {
nativeAttrObj: { Item1: nativeAttrValue(1), Item2: nativeAttrValue(2), ...notAttrValue },
attrObj: { Item1: attrValue(1), Item2: attrValue(2), ...notAttrValue },
},
{
testName: "object with function property",
keyNodes: { Item: {} },
nativeAttrObj: { Item: { id: 1, func: () => {} }, ...notAttrValue },
attrObj: { Item: { id: { N: "1" } }, ...notAttrValue },
},
{
testName: "array",
keyNodes: { Items: { "*": {} } },
Expand Down
8 changes: 8 additions & 0 deletions packages/util-dynamodb/src/marshall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ describe("marshall", () => {
expect(convertToAttr).toHaveBeenCalledTimes(1);
expect(convertToAttr).toHaveBeenCalledWith(input, undefined);
});

it("with function properties in input object", () => {
const input = { a: "A", b: "B", func: () => {}, func2: () => {} };
// const expectedOutput = { a: { M: mockOutput }, b: { M: mockOutput } };
expect(marshall(input)).toEqual(mockOutput);
expect(convertToAttr).toHaveBeenCalledTimes(1);
expect(convertToAttr).toHaveBeenCalledWith(input, undefined);
});
});

0 comments on commit bbaaf48

Please sign in to comment.