UNPKG

@vidal-community/vidal-web-components

Version:

Vidal Web Components

80 lines 5.19 kB
import { Drug } from '../model/drug'; import { assert } from '@open-wc/testing'; import { usePrescribableService } from './prescribables-service'; import { Prescribable } from '../model/prescribable'; import { Package } from '../model/package'; import { Vmp } from '../model/vmp'; import { Product } from '../model/product'; import { Unit } from '../model/unit'; suite('prescribables-service service', () => { test('should get prescribables from UCD', async () => { const prescribables = await usePrescribableService().getPrescribablesFromDrug(new Drug('vidal://ucd/10205', 'ucd test'), () => fetch('../../components/vidal-substitution/test-resources/ucdPrescribablesResult.xml')); const expectedPrescribable = new Prescribable('10251'); assert.lengthOf(prescribables, 1); assert.equal(expectedPrescribable.id, prescribables[0].id); }); test('should get prescribables from package with UCD', async () => { const prescribables = await usePrescribableService().getPrescribablesFromDrug(new Package('vidal://package/10205', 'package test', new Drug('vidal://ucd/10205', 'ucd test')), () => fetch('../../components/vidal-substitution/test-resources/packagePrescribablesResult.xml')); const expectedPrescribable = new Prescribable('729'); assert.lengthOf(prescribables, 1); assert.equal(expectedPrescribable.id, prescribables[0].id); }); test('should get prescribables from package without ucd', async () => { const prescribables = await usePrescribableService().getPrescribablesFromDrug(new Package('vidal://package/10205', 'package test', undefined), () => fetch('../../components/vidal-substitution/test-resources/packagePrescribablesResult.xml')); assert.lengthOf(prescribables, 0); }); test('should get prescribables from VMP', async () => { const prescribables = await usePrescribableService().getPrescribablesFromDrug(new Vmp([], 'vidal://vmp/1383', 'vmp test'), () => fetch('../../components/vidal-substitution/test-resources/vmpPrescribablesResult.xml')); const expectedPrescribable = new Prescribable('37960'); assert.lengthOf(prescribables, 1); assert.equal(expectedPrescribable.id, prescribables[0].id); }); test('should get prescribables from Product', async () => { const prescribables = await usePrescribableService().getPrescribablesFromDrug(new Product([ new Drug('vidal://ucd/10205', 'ucd test'), new Drug('vidal://ucd/39058', 'ucd 2 test'), ], 'vidal://product/3660', 'product test'), () => fetch('../../components/vidal-substitution/test-resources/productPrescribablesResult.xml')); const expectedIdPrescribable = '7412'; assert.lengthOf(prescribables, 2); prescribables.forEach((prescribable) => { assert.equal(prescribable.id, expectedIdPrescribable); }); }); test('should get all UCDs from prescribable', async () => { const drugUcds = await usePrescribableService().getUcdsFromPrescribables('7412', () => fetch('../../components/vidal-substitution/test-resources/ucdsFromPrescribablesResult.xml')); const expectedUcds = [ new Drug('vidal://ucd/12662', 'MAGNESIUM C.10% LAV AB10ML'), new Drug('vidal://ucd/12784', 'MAGNESIUM CHL 10% REN A.B'), new Drug('vidal://ucd/39058', 'MAGNESIUM C.10% LAV AP10ML'), ]; assert.lengthOf(drugUcds, 3); assert.sameDeepMembers(drugUcds, expectedUcds); }); test('should get UCDs prescribable with associated UCDs and ref unit', async () => { const prescribables = await usePrescribableService().associatePrescribablesWithUcd(new Drug('vidal://ucd/10205', 'MAGNESIUM C.10% LAV AB10ML'), (url) => sharedMockDataSupplier(url)); const expectedPrescribables = new Prescribable('10251'); expectedPrescribables.ucds = [ new Drug('vidal://ucd/12662', 'MAGNESIUM C.10% LAV AB10ML'), new Drug('vidal://ucd/12784', 'MAGNESIUM CHL 10% REN A.B'), new Drug('vidal://ucd/39058', 'MAGNESIUM C.10% LAV AP10ML'), ]; expectedPrescribables.refUnit = new Unit('vidal://unit/5', 'µg'); assert.lengthOf(prescribables, 1); assert.equal(prescribables[0].id, expectedPrescribables.id); assert.deepEqual(prescribables[0].refUnit, expectedPrescribables.refUnit); assert.sameDeepMembers(prescribables[0].ucds, expectedPrescribables.ucds); }); function sharedMockDataSupplier(url) { if (url === '/rest/api/ucd/10205/prescribables') { return fetch('../../components/vidal-substitution/test-resources/ucdPrescribablesResult.xml'); } if (url === '/rest/api/prescribable/10251/ucds') { return fetch('../../components/vidal-substitution/test-resources/ucdsFromPrescribablesResult.xml'); } if (url === '/rest/api/prescribable/10251/units') { return fetch('../../components/vidal-substitution/test-resources/prescribableUnitsResult.xml'); } return Promise.reject(new Response()); } }); //# sourceMappingURL=prescribables-service_test.js.map