UNPKG

fume-fhir-converter

Version:

FHIR-Utilized Mapping Engine - Community

152 lines 6.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); /** * © Copyright Outburn Ltd. 2022-2024 All Rights Reserved * Project name: FUME-COMMUNITY */ const globals_1 = require("@jest/globals"); const jest_mock_axios_1 = tslib_1.__importDefault(require("jest-mock-axios")); const config_1 = tslib_1.__importDefault(require("../../config")); const client_1 = require("./client"); const mockConfig = { FHIR_SERVER_BASE: 'test.com', FHIR_SERVER_TIMEOUT: 1000, SERVER_PORT: 111, FHIR_SERVER_AUTH_TYPE: '', FHIR_SERVER_UN: '', FHIR_SERVER_PW: '', SERVER_STATELESS: false, FHIR_VERSION: '4.0.1', SEARCH_BUNDLE_PAGE_SIZE: 200, FHIR_PACKAGES: '' }; describe('FhirClient', () => { let mockAxiosInstance; afterEach(() => { jest.resetAllMocks(); jest_mock_axios_1.default.reset(); }); beforeEach(() => { mockAxiosInstance = { get: jest.fn(), post: jest.fn(), put: jest.fn(), delete: jest.fn() }; jest_mock_axios_1.default.create.mockReturnValue(mockAxiosInstance); }); (0, globals_1.test)('constructor uses config, no auth, stateless = false', async () => { config_1.default.setServerConfig(mockConfig); /* eslint-disable no-new */ new client_1.FhirClient(); expect(jest_mock_axios_1.default.create).toHaveBeenCalledWith({ baseURL: mockConfig.FHIR_SERVER_BASE, timeout: mockConfig.FHIR_SERVER_TIMEOUT, headers: { Accept: 'application/fhir+json;fhirVersion=4.0', 'Content-Type': 'application/fhir+json;fhirVersion=4.0', Authorization: undefined } }); }); (0, globals_1.test)('constructor uses config, with BASIC auth, stateless = false', async () => { config_1.default.setServerConfig({ ...mockConfig, FHIR_SERVER_AUTH_TYPE: 'BASIC', FHIR_SERVER_UN: 'user', FHIR_SERVER_PW: 'pw' }); /* eslint-disable no-new */ new client_1.FhirClient(); expect(jest_mock_axios_1.default.create).toHaveBeenCalledWith({ baseURL: mockConfig.FHIR_SERVER_BASE, timeout: mockConfig.FHIR_SERVER_TIMEOUT, headers: { Accept: 'application/fhir+json;fhirVersion=4.0', 'Content-Type': 'application/fhir+json;fhirVersion=4.0', Authorization: 'Basic dXNlcjpwdw==' } }); }); (0, globals_1.test)('constructor uses config, no auth, stateless = false', async () => { config_1.default.setServerConfig({ ...mockConfig, SERVER_STATELESS: true }); /* eslint-disable no-new */ new client_1.FhirClient(); expect(jest_mock_axios_1.default.create).not.toHaveBeenCalled(); }); (0, globals_1.test)('read returns empty in stateless mode', async () => { config_1.default.setServerConfig({ ...mockConfig, SERVER_STATELESS: true }); const client = new client_1.FhirClient(); const url = 'test'; const res = await client.read(url); expect(res).toBeUndefined(); expect(jest_mock_axios_1.default.get).not.toHaveBeenCalled(); }); (0, globals_1.test)('read returns response data', async () => { config_1.default.setServerConfig(mockConfig); const client = new client_1.FhirClient(); const url = 'test-url'; mockAxiosInstance.get.mockResolvedValue({ data: 'test' }); const response = await client.read(url); expect(response).toBe('test'); expect(mockAxiosInstance.get).toHaveBeenCalledWith(url); }); (0, globals_1.test)('search returns empty in stateless mode', async () => { config_1.default.setServerConfig({ ...mockConfig, SERVER_STATELESS: true }); const client = new client_1.FhirClient(); const url = 'test'; const res = await client.search(url); expect(res).toBeUndefined(); expect(jest_mock_axios_1.default.get).not.toHaveBeenCalled(); }); (0, globals_1.test)('search returns response data', async () => { config_1.default.setServerConfig({ ...mockConfig, SEARCH_BUNDLE_PAGE_SIZE: 45 }); const client = new client_1.FhirClient(); const url = 'test-url'; mockAxiosInstance.get.mockResolvedValue({ data: 'test' }); const response = await client.search(url, { test: 'test-param' }); expect(response).toBe('test'); expect(mockAxiosInstance.get).toHaveBeenCalledWith('/test-url', { params: { _count: 45, test: 'test-param' } }); }); (0, globals_1.test)('create throws error in community', async () => { config_1.default.setServerConfig({ ...mockConfig, SERVER_STATELESS: true }); const client = new client_1.FhirClient(); // eslint-disable-next-line @typescript-eslint/no-floating-promises expect(client.create({}, 'test')).rejects.toThrow('Method not implemented.'); }); (0, globals_1.test)('update throws error in community', async () => { config_1.default.setServerConfig({ ...mockConfig, SERVER_STATELESS: true }); const client = new client_1.FhirClient(); // eslint-disable-next-line @typescript-eslint/no-floating-promises expect(client.update('test', 'test', {})).rejects.toThrow('Method not implemented.'); }); (0, globals_1.test)('simpleDelete throws error in community', async () => { config_1.default.setServerConfig({ ...mockConfig, SERVER_STATELESS: true }); const client = new client_1.FhirClient(); // eslint-disable-next-line @typescript-eslint/no-floating-promises expect(client.simpleDelete('test', 'test')).rejects.toThrow('Method not implemented.'); }); }); //# sourceMappingURL=client.test.js.map