Skip to content

Commit

Permalink
added test for utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-AI committed Jun 28, 2023
1 parent 3e52e59 commit afb9ae9
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { isUniqueIdentifierTypeForOffline, shouldBlockPatientIdentifierInOfflineMode } from './utils';

function createIdentifierType(options: any = {}) {
return {
uniquenessBehavior: (options.uniquenessBehavior as 'UNIQUE' | 'LOCATION' | 'NON_UNIQUE') || null,
identifierSources: [
{
uuid: 'identifier-source-uuid',
name: 'Identifier Source Name',
autoGenerationOption: {
manualEntryEnabled: (options.manualEntryEnabled as boolean) || false,
automaticGenerationEnabled: (options.automaticGenerationEnabled as boolean) || true,
},
},
],
name: 'Identifier Type Name',
required: true,
uuid: 'identifier-type-uuid',
fieldName: 'identifierFieldName',
format: 'identifierFormat',
isPrimary: true,
};
}

describe('shouldBlockPatientIdentifierInOfflineMode', () => {
it('should return false if identifierType is unique and no manual entry is enabled', () => {
const identifierType = createIdentifierType({ uniquenessBehavior: null });

const result = shouldBlockPatientIdentifierInOfflineMode(identifierType);

expect(result).toBe(false);
});

it('should return false if identifierType is not unique', () => {
const identifierType = createIdentifierType({ uniquenessBehavior: null });

const result = shouldBlockPatientIdentifierInOfflineMode(identifierType);

expect(result).toBe(false);
});

it('should return true if manual entry is enabled and identifierType is unique', () => {
const identifierType = createIdentifierType({ manualEntryEnabled: true, uniquenessBehavior: 'UNIQUE' });

const result = shouldBlockPatientIdentifierInOfflineMode(identifierType);

expect(result).toBe(true);
});
});

describe('isUniqueIdentifierTypeForOffline', () => {
it('should return true if uniquenessBehavior is UNIQUE', () => {
const identifierType = createIdentifierType({ uniquenessBehavior: 'UNIQUE' });

const result = isUniqueIdentifierTypeForOffline(identifierType);

expect(result).toBe(true);
});

it('should return true if uniquenessBehavior is LOCATION', () => {
const identifierType = createIdentifierType({ uniquenessBehavior: 'LOCATION' });

const result = isUniqueIdentifierTypeForOffline(identifierType);

expect(result).toBe(true);
});

it('should return false for other uniqueness behaviors', () => {
const identifierType = createIdentifierType({ uniquenessBehavior: null });

const result = isUniqueIdentifierTypeForOffline(identifierType);

expect(result).toBe(false);
});
});

0 comments on commit afb9ae9

Please sign in to comment.