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 23, 2024
1 parent c58b50b commit 69bf854
Show file tree
Hide file tree
Showing 3 changed files with 28 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
11 changes: 11 additions & 0 deletions lib/lib-dynamodb/src/commands/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ describe("utils", () => {
});
});
});

describe("object with function property", () => {
const notAttrValue = { NotAttrValue: "NotAttrValue" };
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);
});
});
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 69bf854

Please sign in to comment.