feat(prduct, utils, types): Create soft delete pattern for link module (#4649)

* feat(prouct, utils, types): Create soft delete pattern for link module

* add comment

* add comment

* finalise

* remove linkable keys

* cleanup and tests

* cleanup

* add some comments and renaming

* re work

* fix tests

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
Adrien de Peretti
2023-08-02 19:29:01 +02:00
committed by GitHub
co-authored by Riqwan Thamir
parent fc6c9df035
commit ce3326c5fb
17 changed files with 448 additions and 166 deletions
@@ -0,0 +1,43 @@
import { mapObjectTo, MapToConfig } from "../map-object-to"
const input = {
a: [{ id: "1" }, { id: "2" }],
b: [{ id: "3" }, { id: "4", handle: "handle1" }],
c: [{ id: "5", sku: "sku1" }, { id: "6" }],
}
const mapToConfig: MapToConfig = {
a: [{ mapTo: "a.id", valueFrom: "id" }],
b: [
{ mapTo: "b.id", valueFrom: "id" },
{ mapTo: "b.handle", valueFrom: "handle" },
],
c: [
{ mapTo: "c.id", valueFrom: "id" },
{ mapTo: "c.sku", valueFrom: "sku" },
],
}
describe("mapObjectTo", function () {
it("should return a new object with the keys remapped and the values picked from the original object based on the map config", function () {
const remappedObject = mapObjectTo(input, mapToConfig)
expect(remappedObject).toEqual({
"a.id": ["1", "2"],
"b.id": ["3", "4"],
"b.handle": ["handle1"],
"c.id": ["5", "6"],
"c.sku": ["sku1"],
})
})
it("should return a new object with only the picked properties", function () {
const remappedObject = mapObjectTo(input, mapToConfig, {
pick: ["a.id"],
})
expect(remappedObject).toEqual({
"a.id": ["1", "2"],
})
})
})