Skip to content

Commit bbaaf48

Browse files
committed
test(lib-dynamodb): adding cases for skipping function properties when processing keys
1 parent c58b50b commit bbaaf48

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/lib-dynamodb/src/commands/marshallInput.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ describe("marshallInput and processObj", () => {
1010
}
1111
);
1212
});
13+
14+
it("marshallInput should ignore function properties", () => {
15+
const input = { Items: [() => {}, 1, "test"] };
16+
const inputKeyNodes = { Items: null };
17+
const output = { Items: { L: [{ N: "1" }, { S: "test" }] } };
18+
expect(
19+
marshallInput(input, inputKeyNodes, { convertTopLevelContainer: true, convertClassInstanceToMap: true })
20+
).toEqual(output);
21+
});
1322
});
1423

1524
describe("marshallInput for commands", () => {

lib/lib-dynamodb/src/commands/utils.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ describe("utils", () => {
1919
nativeAttrObj: { Item1: nativeAttrValue(1), Item2: nativeAttrValue(2), ...notAttrValue },
2020
attrObj: { Item1: attrValue(1), Item2: attrValue(2), ...notAttrValue },
2121
},
22+
{
23+
testName: "object with function property",
24+
keyNodes: { Item: {} },
25+
nativeAttrObj: { Item: { id: 1, func: () => {} }, ...notAttrValue },
26+
attrObj: { Item: { id: { N: "1" } }, ...notAttrValue },
27+
},
2228
{
2329
testName: "array",
2430
keyNodes: { Items: { "*": {} } },

packages/util-dynamodb/src/marshall.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ describe("marshall", () => {
6262
expect(convertToAttr).toHaveBeenCalledTimes(1);
6363
expect(convertToAttr).toHaveBeenCalledWith(input, undefined);
6464
});
65+
66+
it("with function properties in input object", () => {
67+
const input = { a: "A", b: "B", func: () => {}, func2: () => {} };
68+
// const expectedOutput = { a: { M: mockOutput }, b: { M: mockOutput } };
69+
expect(marshall(input)).toEqual(mockOutput);
70+
expect(convertToAttr).toHaveBeenCalledTimes(1);
71+
expect(convertToAttr).toHaveBeenCalledWith(input, undefined);
72+
});
6573
});

0 commit comments

Comments
 (0)