Skip to content

Commit

Permalink
test: config (stateless, fhir base, defaults)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizozom committed Mar 6, 2024
1 parent f3f2002 commit a8b6fc9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
65 changes: 65 additions & 0 deletions src/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* © Copyright Outburn Ltd. 2022-2023 All Rights Reserved
* Project name: FUME
*/

import { test } from '@jest/globals';

import config from './config';

describe('setServerConfig', () => {
test('Uses defaults', async () => {
config.setServerConfig({});
expect(config.getServerConfig()).toEqual({
EXCLUDE_FHIR_PACKAGES: '',
FHIR_PACKAGES: '[email protected],[email protected],[email protected],laniado.test.fhir.r4',
FHIR_SERVER_AUTH_TYPE: 'NONE',
FHIR_SERVER_BASE: '',
FHIR_SERVER_PW: '',
FHIR_SERVER_TIMEOUT: 10000,
FHIR_SERVER_UN: '',
FHIR_VERSION: '4.0.1',
SEARCH_BUNDLE_PAGE_SIZE: 20,
SERVER_PORT: 42420,
SERVER_STATELESS: true
});
});

test('Uses defaults, with FHIR_SERVER_BASE, sets stateless to false', async () => {
config.setServerConfig({
FHIR_SERVER_BASE: 'http://hapi-fhir.outburn.co.il/fhir-test '
});
expect(config.getServerConfig()).toEqual({
EXCLUDE_FHIR_PACKAGES: '',
FHIR_PACKAGES: '[email protected],[email protected],[email protected],laniado.test.fhir.r4',
FHIR_SERVER_AUTH_TYPE: 'NONE',
FHIR_SERVER_BASE: 'http://hapi-fhir.outburn.co.il/fhir-test',
FHIR_SERVER_PW: '',
FHIR_SERVER_TIMEOUT: 10000,
FHIR_SERVER_UN: '',
FHIR_VERSION: '4.0.1',
SEARCH_BUNDLE_PAGE_SIZE: 20,
SERVER_PORT: 42420,
SERVER_STATELESS: false
});
});

test('Uses defaults, without FHIR_SERVER_BASE, sets stateless to true', async () => {
config.setServerConfig({
SERVER_STATELESS: false
});
expect(config.getServerConfig()).toEqual({
EXCLUDE_FHIR_PACKAGES: '',
FHIR_PACKAGES: '[email protected],[email protected],[email protected],laniado.test.fhir.r4',
FHIR_SERVER_AUTH_TYPE: 'NONE',
FHIR_SERVER_BASE: '',
FHIR_SERVER_PW: '',
FHIR_SERVER_TIMEOUT: 10000,
FHIR_SERVER_UN: '',
FHIR_VERSION: '4.0.1',
SEARCH_BUNDLE_PAGE_SIZE: 20,
SERVER_PORT: 42420,
SERVER_STATELESS: true
});
});
});
10 changes: 6 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import type { IAppBinding, IConfig } from './types';
const additionalBindings: Record<string, IAppBinding> = {}; // additional functions to bind when running transformations
let serverConfig: IConfig = { ...defaultConfig };

const setServerConfig = <ConfigType extends IConfig>(config: ConfigType) => {
let fhirServerBase: string = config.FHIR_SERVER_BASE;
let isStatelessMode: boolean = config.SERVER_STATELESS;
const setServerConfig = <ConfigType extends IConfig>(config: Partial<ConfigType>) => {
let fhirServerBase: string | undefined = config.FHIR_SERVER_BASE?.trim();
let isStatelessMode: boolean | undefined = config.SERVER_STATELESS;

if (!fhirServerBase || fhirServerBase.trim() === '' || isStatelessMode) {
if (!fhirServerBase || isStatelessMode) {
fhirServerBase = '';
isStatelessMode = true;
} else {
isStatelessMode = false;
};
serverConfig = {
...defaultConfig,
Expand Down

0 comments on commit a8b6fc9

Please sign in to comment.