From 41c96fb2023fad91ec7a18d83a396798cfe2653b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 29 Jan 2025 19:23:09 +0100 Subject: [PATCH] test(server/utils): add tests for envToBoolean --- src/services/utils.spec.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/services/utils.spec.ts b/src/services/utils.spec.ts index 92c70268d..190bfabf4 100644 --- a/src/services/utils.spec.ts +++ b/src/services/utils.spec.ts @@ -145,6 +145,34 @@ describe.todo("#toMap", () => {}); describe.todo("#isString", () => {}); +describe("#envToBoolean", () => { + const testCases: TestCase[] = [ + ["w/ 'true' it should return boolean 'true'", ["true"], true], + ["w/ 'True' it should return boolean 'true'", ["True"], true], + ["w/ 'TRUE' it should return boolean 'true'", ["TRUE"], true], + ["w/ 'true ' it should return boolean 'true'", ["true "], true], + ["w/ 'false' it should return boolean 'false'", ["false"], false], + ["w/ 'False' it should return boolean 'false'", ["False"], false], + ["w/ 'FALSE' it should return boolean 'false'", ["FALSE"], false], + ["w/ 'false ' it should return boolean 'false'", ["false "], false], + ["w/ 'whatever' (non-boolean string) it should return undefined", ["whatever"], undefined], + ["w/ '-' (non-boolean string) it should return undefined", ["-"], undefined], + ["w/ '' (empty string) it should return undefined", [""], undefined], + ["w/ ' ' (white space string) it should return undefined", [" "], undefined], + ["w/ undefined it should return undefined", [undefined], undefined], + //@ts-expect-error - pass wrong type as param + ["w/ number 1 it should return undefined", [1], undefined], + ]; + + testCases.forEach(testCase => { + const [desc, fnParams, expected] = testCase; + it(desc, () => { + const result = utils.envToBoolean(...fnParams); + expect(result).toStrictEqual(expected); + }); + }); +}); + describe.todo("#getResourceDir", () => {}); describe.todo("#isMac", () => {});