UNPKG

fume-fhir-converter

Version:

FHIR-Utilized Mapping Engine - Community

63 lines 2.42 kB
"use strict"; /** * © Copyright Outburn Ltd. 2022-2024 All Rights Reserved * Project name: FUME-COMMUNITY */ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const globals_1 = require("@jest/globals"); const fs = tslib_1.__importStar(require("fs")); const os_1 = tslib_1.__importDefault(require("os")); const path_1 = tslib_1.__importDefault(require("path")); const getCachePath_1 = require("./getCachePath"); jest.mock('fs'); describe('Cache paths', () => { afterEach(() => { jest.resetAllMocks(); }); (0, globals_1.test)('Creates the getCachePath folder if it does not exist', async () => { let counter = 0; fs.existsSync.mockImplementation(() => { if (counter === 0) { counter++; return false; } return true; }); fs.mkdirSync.mockReturnValue(true); fs.readdirSync.mockReturnValue([]); await (0, getCachePath_1.getCachePath)(); expect(fs.mkdirSync).toHaveBeenCalledTimes(1); expect(fs.mkdirSync).toHaveBeenCalledWith(path_1.default.join(os_1.default.homedir(), '.fhir'), { recursive: true }); }); (0, globals_1.test)('Doesnt create the cache folder if it exists', async () => { fs.existsSync.mockReturnValue(true); fs.mkdirSync.mockReturnValue(true); fs.readdirSync.mockReturnValue([]); (0, getCachePath_1.getCachePath)(); expect(fs.mkdirSync).toHaveBeenCalledTimes(0); }); // test('empty getCachedPackageDirs', async () => { // (fs.readdirSync as jest.Mock).mockReturnValue([]); // const dirs = getCachedPackageDirs(); // expect(dirs).toHaveLength(0); // }); // test('getCachedPackageDirs with folders', async () => { // (fs.readdirSync as jest.Mock).mockReturnValue([{ // isDirectory: () => true, // name: 'test' // }]); // const dirs = getCachedPackageDirs(); // expect(dirs).toHaveLength(1); // expect(dirs[0]).toBe('test'); // }); // test('getCachedPackageDirs with non folder', async () => { // (fs.readdirSync as jest.Mock).mockReturnValue([{ // isDirectory: () => false, // name: 'test' // }]); // const dirs = getCachedPackageDirs(); // expect(dirs).toHaveLength(0); // }); }); //# sourceMappingURL=getCachePath.test.js.map