Skip to content

Commit 69bf854

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

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,14 @@ describe("utils", () => {
146146
});
147147
});
148148
});
149+
150+
describe("object with function property", () => {
151+
const notAttrValue = { NotAttrValue: "NotAttrValue" };
152+
const keyNodes = { Item: {} };
153+
const nativeAttrObj = { Item: { id: 1, func: () => {} }, ...notAttrValue };
154+
const attrObj = { Item: { id: { N: "1" } }, ...notAttrValue };
155+
156+
it(marshallInput.name, () => {
157+
expect(marshallInput(nativeAttrObj, keyNodes, { convertTopLevelContainer: true })).toEqual(attrObj);
158+
});
159+
});

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)