From 0ccf91721d71060808c0a21c67b8ce885cae51a1 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 18 Jan 2025 19:12:50 +0100 Subject: [PATCH] test(services/data_dir): simplify getPlatformAppDataDir use the new available mocks to make tests a tiny bit more simpler :-) --- spec-es6/data_dir.spec.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/spec-es6/data_dir.spec.ts b/spec-es6/data_dir.spec.ts index ded078cb8..57abac8d3 100644 --- a/spec-es6/data_dir.spec.ts +++ b/spec-es6/data_dir.spec.ts @@ -61,27 +61,28 @@ describe("data_dir.ts unit tests", async () => { }; describe("#getPlatformAppDataDir()", () => { - type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters, expectedValueFn: (val: ReturnType) => boolean]; + type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters, expectedValue: string | null, osHomedirMockValue: string | null]; + const testCases: TestCaseGetPlatformAppDataDir[] = [ - ["w/ unsupported OS it should return 'null'", ["aix", undefined], (val) => val === null], + ["w/ unsupported OS it should return 'null'", ["aix", undefined], null, null], - ["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], (val) => val === null], + ["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], null, null], - ["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], (val) => val === "AppData"], + ["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], "AppData", null], - ["w/ linux it should return '/.local/share'", ["linux", undefined], (val) => val !== null && val.endsWith("/.local/share")], + ["w/ linux it should return '~/.local/share'", ["linux", undefined], "/home/mock/.local/share", "/home/mock"], - ["w/ linux and wrongly set APPDATA it should ignore APPDATA and return /.local/share", ["linux", "FakeAppData"], (val) => val !== null && val.endsWith("/.local/share")], + ["w/ linux and wrongly set APPDATA it should ignore APPDATA and return '~/.local/share'", ["linux", "FakeAppData"], "/home/mock/.local/share", "/home/mock"], - ["w/ darwin it should return /Library/Application Support", ["darwin", undefined], (val) => val !== null && val.endsWith("/Library/Application Support")] + ["w/ darwin it should return '~/Library/Application Support'", ["darwin", undefined], "/Users/mock/Library/Application Support", "/Users/mock"] ]; testCases.forEach((testCase) => { - const [testDescription, value, isExpected] = testCase; + const [testDescription, fnValues, expected, osHomedirMockValue] = testCase; return it(testDescription, () => { - const actual = getPlatformAppDataDir(...value); - const result = isExpected(actual); - expect(result).toBeTruthy(); + mockFn.osHomedirMock.mockReturnValue(osHomedirMockValue); + const actual = getPlatformAppDataDir(...fnValues); + expect(actual).toEqual(expected); }); }); });