-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Thank you very much for the nestedObjectAssign function. It helps me to update data into aws dynamodb.
describe("array object", () => {
it("should add text to empty comments array", () => {
const dbData = {comments: []}
const requestData = {comments: ["foo"]}
nestedObjectAssign(dbData, requestData);
expect(dbData).toStrictEqual({comments: ["foo"]});
});
it("should NOT add text duplicates", () => {
const dbData = {comments: ["foo"]}
const requestData = {comments: ["foo"]}
nestedObjectAssign(dbData, requestData);
expect(dbData).toStrictEqual({comments: ["foo"]});
});
it("should NOT change existing properties in db, if they not updated via request", () => {
const dbData = {comments: ["bar", "foo"]}
const requestData = {comments: ["foo"]}
nestedObjectAssign(dbData, requestData);
expect(dbData).toStrictEqual({comments: ["bar", "foo"]});
});
});
To realize green tests i changed the function to typescript and
changed line 23 to target[key] = [...new Set([...target[key], ...source[key]])]
Hopefully it helps someone.
Metadata
Metadata
Assignees
Labels
No labels