From 271255114ca9c1e0228591626d834bd44a0f3204 Mon Sep 17 00:00:00 2001 From: Iku-turso Date: Mon, 24 Oct 2022 11:39:42 +0300 Subject: [PATCH] Remove some duplication from tests of composite Also make the thrown error suggest how to fix the problem. Co-authored-by: Janne Savolainen Signed-off-by: Iku-turso --- .../get-composite/get-composite.test.ts | 52 ++++++------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/src/common/utils/composite/get-composite/get-composite.test.ts b/src/common/utils/composite/get-composite/get-composite.test.ts index 38f135fe2f..e0d5be228d 100644 --- a/src/common/utils/composite/get-composite/get-composite.test.ts +++ b/src/common/utils/composite/get-composite/get-composite.test.ts @@ -8,12 +8,15 @@ import getCompositeFor from "./get-composite"; import { getCompositePaths } from "../get-composite-paths/get-composite-paths"; import { sortBy } from "lodash/fp"; +interface SomeItem { + id: string; + parentId?: string; + orderNumber?: number; +} + describe("get-composite", () => { it("given items and a specified root id, creates a composite", () => { - const getComposite = getCompositeFor<{ - id: string; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ rootId: "some-root-id", getId: (x) => x.id, getParentId: (x) => x.parentId, @@ -86,10 +89,7 @@ describe("get-composite", () => { const items = [someRootItem, someItem, someNestedItem]; - const getComposite = getCompositeFor<{ - id: string; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ // Notice: no root id // rootId: "some-root-id", getId: (x) => x.id, @@ -136,10 +136,7 @@ describe("get-composite", () => { const items = [someRootItem, someOtherRootItem]; - const getComposite = getCompositeFor<{ - id: string; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, }); @@ -164,10 +161,7 @@ describe("get-composite", () => { const items = [someItem, someOtherItem]; - const getComposite = getCompositeFor<{ - id: string; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, }); @@ -192,10 +186,7 @@ describe("get-composite", () => { const items = [someItem, someItemWithMissingParentId]; - const getComposite = getCompositeFor<{ - id: string; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, }); @@ -230,10 +221,7 @@ Available parent ids are: handleMissingParentIdMock = jest.fn(); - const getComposite = getCompositeFor<{ - id: string; - parentId?: string; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, handleMissingParentIds: handleMissingParentIdMock, @@ -269,10 +257,7 @@ Available parent ids are: const items = [someItem, someRoot]; - const getComposite = getCompositeFor<{ - id: string; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, }); @@ -302,10 +287,7 @@ Available parent ids are: const items = [root, someItem, someOtherItem]; - const getComposite = getCompositeFor<{ - id: any; - parentId: string | undefined; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, }); @@ -354,11 +336,7 @@ Available parent ids are: someChildItem1, ]; - const getComposite = getCompositeFor<{ - id: string; - parentId?: string; - orderNumber?: number; - }>({ + const getComposite = getCompositeFor({ getId: (x) => x.id, getParentId: (x) => x.parentId, transformChildren: (things) =>