UNPKG

2.86 kBJavaScriptView Raw
1process.env.NODE_ENV = 'test';
2
3const {
4 expect
5} = require('chai');
6const nconf = require('../config');
7const config = nconf.get('config');
8const rmisjs = require('../index')(config);
9const rmis = rmisjs.rmis;
10const rb = require('refbooks')(config);
11const composer = rmisjs.composer;
12const Ajv = require('ajv');
13
14const detailedLocationSchema = require('./detailedLocation');
15
16describe('[RMIS resource > describe]: ', () => {
17 it('describe method', async () => {
18 try {
19 let r = await rmis.resource();
20 return expect(r.describe()).to.have.property('locationService');
21 } catch (e) { }
22 });
23});
24
25describe('[RMIS resource > getLocation]: ', () => {
26 it('getLocation method', async () => {
27 try {
28 let r = await rmis.resource();
29 r = await r.getLocation({
30 location: 1431035
31 });
32 return expect(r).to.have.property('location');
33 } catch (e) { }
34 });
35});
36
37describe('[RMIS resource > getLocations]: ', () => {
38 it('getLocations method', async () => {
39 try {
40 let r = await rmis.resource();
41 r = await r.getLocations({
42 clinic: config.rmis.clinicId
43 });
44 return expect(r).to.have.property('location');
45 } catch (e) { }
46 });
47});
48
49describe('[RMIS composer > getLocationsWithPortal]: ', () => {
50 it('getLocationsWithPortal method', async () => {
51 try {
52 let r = await composer.getLocationsWithPortal();
53 return expect(r).deep.to.have.property('source');
54 } catch (e) { }
55 });
56});
57
58describe('[RMIS composer > getDetailedLocations]: ', () => {
59 it('getDetailedLocations method', async () => {
60 let [mdp365, c33001] = await Promise.all([
61 rb.getRefbook({
62 code: 'MDP365',
63 version: '1.0',
64 part: '1'
65 }).then(r =>
66 r.data.map(i => {
67 return {
68 code: i[1].value,
69 name: i[3].value
70 };
71 })
72 ),
73 rb.getRefbook({
74 code: 'C33001',
75 version: '1.0',
76 part: '1'
77 }).then(r =>
78 r.data.map(i => {
79 return {
80 code: i[2].value,
81 name: i[3].value
82 };
83 })
84 )
85 ]);
86 let data = await composer.getDetailedLocations(mdp365, c33001);
87 let validator = new Ajv();
88 let valid = validator.validate({
89 type: 'array',
90 items: detailedLocationSchema
91 }, data);
92 if (!valid) {
93 console.log(validator.errors);
94 throw new Error('Data is not valid');
95 }
96 });
97});