fume-fhir-converter
Version:
FHIR-Utilized Mapping Engine - Community
48 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved
* Project name: FUME-COMMUNITY
*/
const globals_1 = require("@jest/globals");
const cache_1 = require("../cache");
const conformance_1 = require("../conformance");
const translateCode_1 = require("./translateCode");
jest.mock('../conformance', () => ({
getTable: jest.fn()
}));
jest.mock('../logger', () => ({
getLogger: jest.fn().mockReturnValue({
info: jest.fn(),
error: jest.fn()
})
}));
describe('translateCode', () => {
let mockGetTable;
beforeEach(() => {
(0, cache_1.initCache)();
mockGetTable = conformance_1.getTable;
mockGetTable.mockResolvedValue({ tableId: { input: [{ code: 1 }] } });
});
afterEach(() => {
conformance_1.getTable.mockRestore();
});
(0, globals_1.test)('returns undefined on error', async () => {
mockGetTable.mockRejectedValueOnce('error');
const res = await (0, translateCode_1.translateCode)('input', 'tableId');
expect(mockGetTable).toHaveBeenCalledTimes(1);
expect(res).toEqual(undefined);
});
(0, globals_1.test)('fetches table if not cached, returns code', async () => {
const res = await (0, translateCode_1.translateCode)('input', 'tableId');
expect(mockGetTable).toHaveBeenCalledTimes(1);
expect(res).toEqual(1);
});
(0, globals_1.test)('uses cached table if exists, returns code', async () => {
await (0, translateCode_1.translateCode)('input', 'tableId');
const res = await (0, translateCode_1.translateCode)('input', 'tableId');
expect(mockGetTable).toHaveBeenCalledTimes(1);
expect(res).toEqual(1);
});
});
//# sourceMappingURL=translateCode.test.js.map