From 13e72c5e0a2aad8228eab8dcd4e15d6a96ae1f20 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 1 Feb 2025 15:00:47 +0100 Subject: [PATCH] test(server/utils): add basic test for toObject --- src/services/utils.spec.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/services/utils.spec.ts b/src/services/utils.spec.ts index ef4745517..98cc5bfab 100644 --- a/src/services/utils.spec.ts +++ b/src/services/utils.spec.ts @@ -120,7 +120,20 @@ describe("#unescapeHtml", () => { }); }); -describe.todo("#toObject", () => {}); +describe("#toObject", () => { + it("should return an object with keys and value being set from the supplied Function", () => { + type TestListEntry = { testPropA: string, testPropB: string }; + type TestListFn = (testListEntry: TestListEntry) => [string, string]; + const testList: [TestListEntry, TestListEntry] = [{ testPropA: "keyA", testPropB: "valueA" }, { testPropA: "keyB", testPropB: "valueB" }]; + const fn: TestListFn = (testListEntry: TestListEntry) => [testListEntry.testPropA + "_fn", testListEntry.testPropB + "_fn"]; + + const result = utils.toObject(testList, fn); + expect(result).toStrictEqual({ + "keyA_fn": "valueA_fn", + "keyB_fn": "valueB_fn" + }); + }); +}); describe("#stripTags", () => {