Skip to content

Commit

Permalink
test: fix config
Browse files Browse the repository at this point in the history
  • Loading branch information
lizozom committed Mar 6, 2024
1 parent 6a6d5ec commit 1a62ae8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 17 additions & 9 deletions src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@ import { test } from '@jest/globals';

import config from './config';

const serverDefaults = {
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',
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
};

jest.mock('./serverConfig', () => (serverDefaults));

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',
...serverDefaults,
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
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const additionalBindings: Record<string, IAppBinding> = {}; // additional functi
let serverConfig: IConfig = { ...defaultConfig };

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

if (!fhirServerBase || isStatelessMode) {
if (!fhirServerBase || fhirServerBase === '' || isStatelessMode) {
fhirServerBase = '';
isStatelessMode = true;
} else {
Expand Down

0 comments on commit 1a62ae8

Please sign in to comment.