Produced by Araxis Merge on 10/4/2017 8:04:35 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | rdk.zip\rdk\product\production\rdk\src\resources\incident-report | incident-report-resource-spec.js | Fri Aug 25 15:36:55 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\resources\incident-report | incident-report-resource-spec.js | Tue Oct 3 18:15:21 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 19 | 1650 |
| Changed | 18 | 40 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | 'use stric t'; | |
| 2 | ||
| 3 | var _ = re quire('lod ash'); | |
| 4 | var async = require( 'async'); | |
| 5 | var bunyan = require ('bunyan') ; | |
| 6 | var fs = r equire('fs '); | |
| 7 | var uuid = require(' node-uuid' ); | |
| 8 | var incide ntReportRe source = r equire('./ incident-r eport-reso urce'); | |
| 9 | var rdk = require('. ./../core/ rdk'); | |
| 10 | var os = r equire('os '); | |
| 11 | var RdkErr or = rdk.u tils.RdkEr ror; | |
| 12 | ||
| 13 | describe(' incident-r eport-reso urce', fun ction() { | |
| 14 | before Each(funct ion() { | |
| 15 | si non.stub(o s, 'platfo rm').calls Fake(funct ion() { | |
| 16 | return ' linux'; | |
| 17 | }) ; | |
| 18 | }); | |
| 19 | ||
| 20 | descri be('getRes ourceConfi g', functi on() { | |
| 21 | it ('returns one object ', functio n() { | |
| 22 | var reso urceConfig = inciden tReportRes ource.getR esourceCon fig(); | |
| 23 | expect(r esourceCon fig).to.ha ve.length( 1); | |
| 24 | expect(r esourceCon fig[0].nam e).to.equa l('inciden t-report') ; | |
| 25 | }) ; | |
| 26 | it ('has the expected p ermissions ', functio n() { | |
| 27 | var reso urceConfig = inciden tReportRes ource.getR esourceCon fig(); | |
| 28 | expect(r esourceCon fig).to.ha ve.length( 1); | |
| 29 | expect(r esourceCon fig[0].req uiredPermi ssions).to .eql(['acc ess-genera l-ehmp']); | |
| 30 | }) ; | |
| 31 | ||
| 32 | }); | |
| 33 | ||
| 34 | descri be('writeI ncidentFil e', functi on() { | |
| 35 | it ('returns an error w hen the in cident dir ectory is not config ured', fun ction(done ) { | |
| 36 | var req = {}; | |
| 37 | _.set(re q, 'app.co nfig', {}) ; | |
| 38 | _.set(re q, 'logger ', sinon.s tub(bunyan .createLog ger({name: 'incident -report-re source'})) ); | |
| 39 | incident ReportReso urce._writ eIncidentF ile(req, n ull, null, function( err) { | |
| 40 | expe ct(err).to .be.an.err or(RdkErro r); | |
| 41 | expe ct(err.err or).to.mat ch(/incide nts.rootDi rectory mu st be conf igured/); | |
| 42 | expe ct(err.mes sage).to.m atch(/Serv er misconf iguration/ ); | |
| 43 | done (); | |
| 44 | }); | |
| 45 | }) ; | |
| 46 | it ('returns an error i f the dire ctory for the incide nt can not be create d', functi on(done) { | |
| 47 | var req = {}; | |
| 48 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/inc idents'); | |
| 49 | _.set(re q, 'logger ', sinon.s tub(bunyan .createLog ger({name: 'incident -report-re source'})) ); | |
| 50 | var inci dentReport Id = 'eHMP -IR-9c2784 b0-e33b-11 e6-9326-43 7f339a0e84 '; // new Date(14853 75584379); // 2017-0 1-25T20:19 :44.379Z | |
| 51 | function myMkdirp( path, call back) { | |
| 52 | expe ct(path).t o.equal('/ tmp/incide nts/2017-0 1-25'); | |
| 53 | retu rn callbac k(new Erro r('error m aking dire ctory')); | |
| 54 | } | |
| 55 | ||
| 56 | sinon.st ub(fs, 're adFile').c allsFake(f unction(fi le, option s, callbac k) { | |
| 57 | retu rn callbac k(null, [ | |
| 58 | 'proc /pro c proc rw, relatime 0 0', | |
| 59 | '/dev/mapp er/VolGrou p-lv_root / ext4 rw, seclabel,r elatime,ba rrier=1,da ta=ordered 0 0', | |
| 60 | '127.0.0.1 :/var/log/ rdk /tmp/i ncidents n fs4 rw,rel atime,vers =4,rsize=6 5536,wsize =65536,nam len=255,ha rd,proto=t cp, PORT ,timeo=600 ,retrans=2 ,sec=sys,c lientaddr= 127.0.0.1, minorversi on=0,local _lock=none ,addr=127. 0.0.1 0 0' | |
| 61 | ].jo in('\n')); | |
| 62 | }); | |
| 63 | ||
| 64 | incident ReportReso urce._writ eIncidentF ile(req, i ncidentRep ortId, 'in cident tex t', functi on(err) { | |
| 65 | expe ct(req.log ger.error. calledWith (sinon.mat ch.object, 'Could no t create i ncident di rectory')) .to.be.tru e(); | |
| 66 | expe ct(err).to .be.an.err or(RdkErro r); | |
| 67 | expe ct(err.mes sage).to.m atch(/dire ctory perm ission err or/); | |
| 68 | done (); | |
| 69 | }, myMkd irp); | |
| 70 | }) ; | |
| 71 | it ('returns an error i f the inci dent repor t file cou ld not be written', function(d one) { | |
| 72 | var req = {}; | |
| 73 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/inc idents'); | |
| 74 | _.set(re q, 'logger ', sinon.s tub(bunyan .createLog ger({name: 'incident -report-re source'})) ); | |
| 75 | var inci dentReport Id = 'eHMP -IR-9c2784 b0-e33b-11 e6-9326-43 7f339a0e84 '; // new Date(14853 75584379); // 2017-0 1-25T20:19 :44.379Z | |
| 76 | function myMkdirp( path, call back) { | |
| 77 | expe ct(path).t o.equal('/ tmp/incide nts/2017-0 1-25'); | |
| 78 | retu rn callbac k(); | |
| 79 | } | |
| 80 | ||
| 81 | sinon.st ub(fs, 're adFile').c allsFake(f unction(fi le, option s, callbac k) { | |
| 82 | retu rn callbac k(null, [ | |
| 83 | 'proc /pro c proc rw, relatime 0 0', | |
| 84 | '/dev/mapp er/VolGrou p-lv_root / ext4 rw, seclabel,r elatime,ba rrier=1,da ta=ordered 0 0', | |
| 85 | '127.0.0.1 :/var/log/ rdk /tmp/i ncidents n fs4 rw,rel atime,vers =4,rsize=6 5536,wsize =65536,nam len=255,ha rd,proto=t cp, PORT ,timeo=600 ,retrans=2 ,sec=sys,c lientaddr= 127.0.0.1, minorversi on=0,local _lock=none ,addr=127. 0.0.1 0 0' | |
| 86 | ].jo in('\n')); | |
| 87 | }); | |
| 88 | ||
| 89 | sinon.st ub(fs, 'wr iteFile'). callsFake( function(p ath, conte nts, callb ack) { | |
| 90 | retu rn callbac k(new Erro r('error w riting fil e')); | |
| 91 | }); | |
| 92 | ||
| 93 | incident ReportReso urce._writ eIncidentF ile(req, i ncidentRep ortId, 'in cident tex t', functi on(err) { | |
| 94 | expe ct(req.log ger.error. calledWith (sinon.mat ch.object, 'Could no t save inc ident file ')).to.be. true(); | |
| 95 | expe ct(err).to .be.an.err or(RdkErro r); | |
| 96 | expe ct(err.mes sage).to.m atch(/file permissio n error/); | |
| 97 | done (); | |
| 98 | }, myMkd irp); | |
| 99 | }) ; | |
| 100 | it ('returns no error i f the repo rt was suc cessfully written', function(d one) { | |
| 101 | var req = {}; | |
| 102 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/inc idents'); | |
| 103 | _.set(re q, 'logger ', sinon.s tub(bunyan .createLog ger({name: 'incident -report-re source'})) ); | |
| 104 | var inci dentReport Id = 'eHMP -IR-9c2784 b0-e33b-11 e6-9326-43 7f339a0e84 '; // new Date(14853 75584379); // 2017-0 1-25T20:19 :44.379Z | |
| 105 | function myMkdirp( path, call back) { | |
| 106 | expe ct(path).t o.equal('/ tmp/incide nts/2017-0 1-25'); | |
| 107 | retu rn callbac k(); | |
| 108 | } | |
| 109 | ||
| 110 | sinon.st ub(fs, 're adFile').c allsFake(f unction(fi le, option s, callbac k) { | |
| 111 | retu rn callbac k(null, [ | |
| 112 | 'proc /pro c proc rw, relatime 0 0', | |
| 113 | '/dev/mapp er/VolGrou p-lv_root / ext4 rw, seclabel,r elatime,ba rrier=1,da ta=ordered 0 0', | |
| 114 | '127.0.0.1 :/var/log/ rdk /tmp/i ncidents n fs4 rw,rel atime,vers =4,rsize=6 5536,wsize =65536,nam len=255,ha rd,proto=t cp, PORT ,timeo=600 ,retrans=2 ,sec=sys,c lientaddr= 127.0.0.1, minorversi on=0,local _lock=none ,addr=127. 0.0.1 0 0' | |
| 115 | ].jo in('\n')); | |
| 116 | }); | |
| 117 | ||
| 118 | sinon.st ub(fs, 'wr iteFile'). callsFake( function(p ath, conte nts, callb ack) { | |
| 119 | expe ct(path).t o.equal('/ tmp/incide nts/2017-0 1-25/' + i ncidentRep ortId + '. txt'); | |
| 120 | expe ct(content s).to.equa l('inciden t text'); | |
| 121 | retu rn callbac k(); | |
| 122 | }); | |
| 123 | incident ReportReso urce._writ eIncidentF ile(req, i ncidentRep ortId, 'in cident tex t', functi on(err) { | |
| 124 | expe ct(req.log ger.error. called).to .be.false( ); | |
| 125 | expe ct(err).to .be.falsy( ); | |
| 126 | done (); | |
| 127 | }, myMkd irp); | |
| 128 | }) ; | |
| 129 | }); | |
| 130 | ||
| 131 | descri be('create IncidentRe port', fun ction() { | |
| 132 | va r requestB ody; | |
| 133 | be foreEach(f unction() { | |
| 134 | requestB ody = { | |
| 135 | pid: ' R E D A CTED ;3', | |
| 136 | inci dents: [{ | |
| 137 | simpleSync Status: {} , | |
| 138 | errorTimes tamp: '201 7-01-18T18 :04:40.229 Z', | |
| 139 | message: ' Example Lo g Line', | |
| 140 | errorLogId : '', | |
| 141 | requestId: 'cd229052 -a3ea-49c4 -b0e2-4de0 e2863734' | |
| 142 | }], | |
| 143 | trac ker: { | |
| 144 | screenName : 'summary ', | |
| 145 | hash: '#/p atient/sum mary', | |
| 146 | hostname: ' IP ', | |
| 147 | url: 'http s:// IP /#/patient /summary', | |
| 148 | appCodeNam e: 'Mozill a', | |
| 149 | appName: ' Netscape', | |
| 150 | appVersion : '5.0 (Wi ndows NT 6 .1; WOW64; Trident/7 .0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; rv:11.0) like Gecko ', | |
| 151 | platform: 'Win32', | |
| 152 | facility: 'PANORAMA' , | |
| 153 | duz: {' R E D A CTED ': '3'}, | |
| 154 | site: ' R E D A CTED ', | |
| 155 | title: 'Cl inician', | |
| 156 | pid: '', | |
| 157 | icn: '', | |
| 158 | history: [ '/staff/pr ovider-cen tric-view' , '/patien t/summary' ], | |
| 159 | historyTim es: [14847 62636811, 1484762677 444] | |
| 160 | } | |
| 161 | }; | |
| 162 | }) ; | |
| 163 | ||
| 164 | it ('creates a child lo gger with the incide nt id', fu nction(don e) { | |
| 165 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 166 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 167 | retu rn myUuid; | |
| 168 | }); | |
| 169 | var req = {}; | |
| 170 | _.set(re q, 'body.i ncidents', []); | |
| 171 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 172 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 173 | retu rn sinon.s tub(bunyan .createLog ger({name: 'incident -report-re source-spe c'})); | |
| 174 | }); | |
| 175 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function () { | |
| 176 | done (); | |
| 177 | }); | |
| 178 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion() { | |
| 179 | }); | |
| 180 | var res = {}; | |
| 181 | res.set = function () { | |
| 182 | }; | |
| 183 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 184 | }) ; | |
| 185 | it ('logs inf o when the patient s tatus deta il could n ot be fetc hed', func tion(done) { | |
| 186 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 187 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 188 | retu rn myUuid; | |
| 189 | }); | |
| 190 | var req = {}; | |
| 191 | req.id = '543'; | |
| 192 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 193 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 194 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 195 | retu rn logger; | |
| 196 | }); | |
| 197 | _.set(req, 'body.pid ', ' R E D A CTED ;1234'); | |
| 198 | _.set(re q, 'sessio n.user', { | |
| 199 | uid: 'urn: va:user: R E D A CTED :1', | |
| 200 | firs tname: 'JO HN', | |
| 201 | last name: 'DOE ' | |
| 202 | }); | |
| 203 | _.set(re q, 'sessio n.id', '12 34'); | |
| 204 | _.set(re q, 'body', requestBo dy); | |
| 205 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 206 | var fetc hError = n ew Error(' could not be fetched '); | |
| 207 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 208 | expe ct(pid).to .eql(req.b ody.pid); | |
| 209 | call back(fetch Error); | |
| 210 | }); | |
| 211 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 212 | retu rn callbac k(); | |
| 213 | }); | |
| 214 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.to', 'r oot@localh ost'); | |
| 215 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.from', 'nobody@lo calhost'); | |
| 216 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 217 | retu rn callbac k(); | |
| 218 | }); | |
| 219 | sinon.st ub(fs, 'wr iteFile'). callsFake( function(p ath, conte nts, callb ack) { | |
| 220 | expe ct(content s).to.cont ain('"mess age": "cou ld not be fetched"') ; | |
| 221 | retu rn callbac k(); | |
| 222 | }); | |
| 223 | var res = {}; | |
| 224 | res.stat us = funct ion(code) { | |
| 225 | expe ct(code).t o.eql(200) ; | |
| 226 | retu rn this; | |
| 227 | }; | |
| 228 | res.rdkS end = func tion(body) { | |
| 229 | done (); | |
| 230 | }; | |
| 231 | res.set = function () { | |
| 232 | }; | |
| 233 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 234 | }) ; | |
| 235 | it ('logs inf o when the patient s tatus coul d not be f etched', f unction(do ne) { | |
| 236 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 237 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 238 | retu rn myUuid; | |
| 239 | }); | |
| 240 | var req = {}; | |
| 241 | req.id = '543'; | |
| 242 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 243 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 244 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 245 | retu rn logger; | |
| 246 | }); | |
| 247 | _.set(req, 'body.pid ', ' R E D A CTED ;1234'); | |
| 248 | _.set(re q, 'sessio n.user', { | |
| 249 | uid: 'urn: va:user: R E D A CTED :1', | |
| 250 | firs tname: 'JO HN', | |
| 251 | last name: 'DOE ' | |
| 252 | }); | |
| 253 | _.set(re q, 'sessio n.id', '12 34'); | |
| 254 | _.set(re q, 'body', requestBo dy); | |
| 255 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 256 | var fetc hError = n ew Error(' could not be fetched '); | |
| 257 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 258 | expe ct(pid).to .eql(req.b ody.pid); | |
| 259 | call back(fetch Error); | |
| 260 | }); | |
| 261 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 262 | retu rn callbac k(); | |
| 263 | }); | |
| 264 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.to', 'r oot@localh ost'); | |
| 265 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.from', 'nobody@lo calhost'); | |
| 266 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 267 | retu rn callbac k(); | |
| 268 | }); | |
| 269 | sinon.st ub(fs, 'wr iteFile'). callsFake( function(p ath, conte nts, callb ack) { | |
| 270 | expe ct(content s).to.cont ain('"mess age": "cou ld not be fetched"') ; | |
| 271 | retu rn callbac k(); | |
| 272 | }); | |
| 273 | var res = {}; | |
| 274 | res.stat us = funct ion(code) { | |
| 275 | expe ct(code).t o.eql(200) ; | |
| 276 | retu rn this; | |
| 277 | }; | |
| 278 | res.rdkS end = func tion(body) { | |
| 279 | expe ct(body).t o.eql({ | |
| 280 | incidentRe portId: 'e HMP-IR-' + myUuid | |
| 281 | }); | |
| 282 | done (); | |
| 283 | }; | |
| 284 | res.set = function () { | |
| 285 | }; | |
| 286 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 287 | }) ; | |
| 288 | it ('logs an error when unable to write the incident file', fun ction(done ) { | |
| 289 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 290 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 291 | retu rn myUuid; | |
| 292 | }); | |
| 293 | var req = {}; | |
| 294 | req.id = '543'; | |
| 295 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 296 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 297 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 298 | retu rn logger; | |
| 299 | }); | |
| 300 | _.set(re q, 'sessio n.user', { | |
| 301 | uid: 'urn: va:user: R E D A CTED :1', | |
| 302 | firs tname: 'JO HN', | |
| 303 | last name: 'DOE ' | |
| 304 | }); | |
| 305 | _.set(re q, 'sessio n.id', '12 34'); | |
| 306 | _.set(re q, 'body', requestBo dy); | |
| 307 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 308 | expe ct(pid).to .eql(req.b ody.pid); | |
| 309 | retu rn callbac k(); | |
| 310 | }); | |
| 311 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 312 | retu rn callbac k(); | |
| 313 | }); | |
| 314 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/inc idents'); | |
| 315 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 316 | retu rn callbac k(); | |
| 317 | }); | |
| 318 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 319 | expe ct(tasks). to.have.le ngth(2); | |
| 320 | retu rn tasks[1 ](function (err) { | |
| 321 | expect(err ).to.be.an .error(Rdk Error); | |
| 322 | expect(err .logged).t o.be.true( ); | |
| 323 | return han dler(err); | |
| 324 | }); | |
| 325 | }); | |
| 326 | sinon.st ub(fs, 'wr iteFile'). callsFake( function(p ath, conte nts, callb ack) { | |
| 327 | retu rn callbac k('could n ot write') ; | |
| 328 | }); | |
| 329 | var res = {}; | |
| 330 | res.stat us = funct ion(code) { | |
| 331 | expe ct(code).t o.eql(500) ; | |
| 332 | retu rn this; | |
| 333 | }; | |
| 334 | res.rdkS end = func tion(body) { | |
| 335 | expe ct(req.log ger.error. calledWith Match({inc identText: true}, si non.match. string)).t o.be.true( ); | |
| 336 | expe ct(body).t o.be.an.er ror(); | |
| 337 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 338 | expe ct(body.co de).to.eql ('200.500. 1010'); | |
| 339 | done (); | |
| 340 | }; | |
| 341 | res.set = function () { | |
| 342 | }; | |
| 343 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 344 | }) ; | |
| 345 | it ('logs a r edacted ve rsion to t he rdk log file when unable to write the incident file', fun ction(done ) { | |
| 346 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 347 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 348 | retu rn myUuid; | |
| 349 | }); | |
| 350 | var req = {}; | |
| 351 | req.id = '543'; | |
| 352 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 353 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 354 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 355 | retu rn logger; | |
| 356 | }); | |
| 357 | _.set(re q, 'sessio n.user', { | |
| 358 | uid: 'urn: va:user: R E D A CTED :1', | |
| 359 | firs tname: 'JO HN', | |
| 360 | last name: 'DOE ' | |
| 361 | }); | |
| 362 | _.set(re q, 'sessio n.id', '12 34'); | |
| 363 | requestB ody.incide nts[0].det ail = {sen sitiveA: t rue}; | |
| 364 | requestB ody.incide nts[0].det ails = {se nsitiveB: true}; | |
| 365 | _.set(re q, 'body', requestBo dy); | |
| 366 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 367 | expe ct(pid).to .eql(req.b ody.pid); | |
| 368 | retu rn callbac k(); | |
| 369 | }); | |
| 370 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 371 | retu rn callbac k(); | |
| 372 | }); | |
| 373 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/inc idents'); | |
| 374 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 375 | retu rn callbac k(); | |
| 376 | }); | |
| 377 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 378 | expe ct(tasks). to.have.le ngth(2); | |
| 379 | retu rn tasks[1 ](function (err) { | |
| 380 | expect(err ).to.be.an .error(Rdk Error); | |
| 381 | expect(err .logged).t o.be.true( ); | |
| 382 | return han dler(err); | |
| 383 | }); | |
| 384 | }); | |
| 385 | sinon.st ub(fs, 'wr iteFile'). callsFake( function(p ath, conte nts, callb ack) { | |
| 386 | expe ct(content s).to.matc h(/sensiti veA/); | |
| 387 | expe ct(content s).to.matc h(/sensiti veB/); | |
| 388 | retu rn callbac k('could n ot write') ; | |
| 389 | }); | |
| 390 | var res = {}; | |
| 391 | res.stat us = funct ion(code) { | |
| 392 | expe ct(code).t o.eql(500) ; | |
| 393 | retu rn this; | |
| 394 | }; | |
| 395 | res.rdkS end = func tion(body) { | |
| 396 | expe ct(req.log ger.error. calledWith Match({inc identText: true}, si non.match. string)).t o.be.true( ); | |
| 397 | expe ct(req.log ger.error. getCall(2) .args[1]). to.match(/ --- # eHMP Incident Report/); | |
| 398 | expe ct(req.log ger.error. getCall(2) .args[1]). not.to.mat ch(/sensit iveA/); | |
| 399 | expe ct(req.log ger.error. getCall(2) .args[1]). not.to.mat ch(/sensit iveB/); | |
| 400 | expe ct(body).t o.be.an.er ror(); | |
| 401 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 402 | expe ct(body.co de).to.eql ('200.500. 1010'); | |
| 403 | done (); | |
| 404 | }; | |
| 405 | res.set = function () { | |
| 406 | }; | |
| 407 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 408 | }) ; | |
| 409 | it ('logs an error when email con figuration is missin g "to"', f unction(do ne) { | |
| 410 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 411 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 412 | retu rn myUuid; | |
| 413 | }); | |
| 414 | var req = {}; | |
| 415 | req.id = '543'; | |
| 416 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 417 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 418 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 419 | retu rn logger; | |
| 420 | }); | |
| 421 | _.set(re q, 'sessio n.user', { | |
| 422 | uid: 'urn: va:user: R E D A CTED :1', | |
| 423 | firs tname: 'JO HN', | |
| 424 | last name: 'DOE ' | |
| 425 | }); | |
| 426 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 427 | _.set(re q, 'sessio n.id', '12 34'); | |
| 428 | _.set(re q, 'body', requestBo dy); | |
| 429 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 430 | expe ct(pid).to .eql(req.b ody.pid); | |
| 431 | retu rn callbac k(); | |
| 432 | }); | |
| 433 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 434 | expe ct(pid).to .eql(req.b ody.pid); | |
| 435 | retu rn callbac k(); | |
| 436 | }); | |
| 437 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.from', 'nobody@lo calhost'); | |
| 438 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 439 | retu rn callbac k(); | |
| 440 | }); | |
| 441 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 442 | retu rn handler (); | |
| 443 | }); | |
| 444 | var res = {}; | |
| 445 | res.stat us = funct ion(code) { | |
| 446 | expe ct(code).t o.eql(500) ; | |
| 447 | retu rn this; | |
| 448 | }; | |
| 449 | res.rdkS end = func tion(body) { | |
| 450 | expe ct(body).t o.be.an.er ror(); | |
| 451 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 452 | expe ct(body.co de).to.eql ('200.500. 1018'); | |
| 453 | done (); | |
| 454 | }; | |
| 455 | res.set = function () { | |
| 456 | }; | |
| 457 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 458 | }) ; | |
| 459 | it ('logs an error when email con figuration is missin g "from"', function( done) { | |
| 460 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 461 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 462 | retu rn myUuid; | |
| 463 | }); | |
| 464 | var req = {}; | |
| 465 | req.id = '543'; | |
| 466 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 467 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 468 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 469 | retu rn logger; | |
| 470 | }); | |
| 471 | _.set(re q, 'sessio n.user', { | |
| 472 | uid: 'urn: va:user: R E D A CTED :1', | |
| 473 | firs tname: 'JO HN', | |
| 474 | last name: 'DOE ' | |
| 475 | }); | |
| 476 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 477 | _.set(re q, 'sessio n.id', '12 34'); | |
| 478 | _.set(re q, 'body', requestBo dy); | |
| 479 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 480 | expe ct(pid).to .eql(req.b ody.pid); | |
| 481 | retu rn callbac k(); | |
| 482 | }); | |
| 483 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 484 | expe ct(pid).to .eql(req.b ody.pid); | |
| 485 | retu rn callbac k(); | |
| 486 | }); | |
| 487 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.to', 'n obody@loca lhost'); | |
| 488 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 489 | retu rn callbac k(); | |
| 490 | }); | |
| 491 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 492 | retu rn handler (); | |
| 493 | }); | |
| 494 | var res = {}; | |
| 495 | res.stat us = funct ion(code) { | |
| 496 | expe ct(code).t o.eql(500) ; | |
| 497 | retu rn this; | |
| 498 | }; | |
| 499 | res.rdkS end = func tion(body) { | |
| 500 | expe ct(body).t o.be.an.er ror(); | |
| 501 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 502 | expe ct(body.co de).to.eql ('200.500. 1019'); | |
| 503 | done (); | |
| 504 | }; | |
| 505 | res.set = function () { | |
| 506 | }; | |
| 507 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 508 | }) ; | |
| 509 | it ('logs an error when email con figuration is missin g "to" and "from"', function(d one) { | |
| 510 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 511 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 512 | retu rn myUuid; | |
| 513 | }); | |
| 514 | var req = {}; | |
| 515 | req.id = '543'; | |
| 516 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 517 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 518 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 519 | retu rn logger; | |
| 520 | }); | |
| 521 | _.set(re q, 'sessio n.user', { | |
| 522 | uid: 'urn: va:user: R E D A CTED :1', | |
| 523 | firs tname: 'JO HN', | |
| 524 | last name: 'DOE ' | |
| 525 | }); | |
| 526 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 527 | _.set(re q, 'sessio n.id', '12 34'); | |
| 528 | _.set(re q, 'body', requestBo dy); | |
| 529 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 530 | expe ct(pid).to .eql(req.b ody.pid); | |
| 531 | retu rn callbac k(); | |
| 532 | }); | |
| 533 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 534 | expe ct(pid).to .eql(req.b ody.pid); | |
| 535 | retu rn callbac k(); | |
| 536 | }); | |
| 537 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il', {}); | |
| 538 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 539 | retu rn callbac k(); | |
| 540 | }); | |
| 541 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 542 | retu rn handler (); | |
| 543 | }); | |
| 544 | var res = {}; | |
| 545 | res.stat us = funct ion(code) { | |
| 546 | expe ct(code).t o.eql(500) ; | |
| 547 | retu rn this; | |
| 548 | }; | |
| 549 | res.rdkS end = func tion(body) { | |
| 550 | expe ct(body).t o.be.an.er ror(); | |
| 551 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 552 | expe ct(body.co de).to.eql ('200.500. 1015'); | |
| 553 | done (); | |
| 554 | }; | |
| 555 | res.set = function () { | |
| 556 | }; | |
| 557 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 558 | }) ; | |
| 559 | it ('logs an error when notificat ion recipi ent reject ed the ema il', funct ion(done) { | |
| 560 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 561 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 562 | retu rn myUuid; | |
| 563 | }); | |
| 564 | var req = {}; | |
| 565 | req.id = '543'; | |
| 566 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 567 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 568 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 569 | retu rn logger; | |
| 570 | }); | |
| 571 | _.set(re q, 'sessio n.user', { | |
| 572 | uid: 'urn: va:user: R E D A CTED :1', | |
| 573 | firs tname: 'JO HN', | |
| 574 | last name: 'DOE ' | |
| 575 | }); | |
| 576 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 577 | _.set(re q, 'sessio n.id', '12 34'); | |
| 578 | _.set(re q, 'body', requestBo dy); | |
| 579 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 580 | expe ct(pid).to .eql(req.b ody.pid); | |
| 581 | retu rn callbac k(); | |
| 582 | }); | |
| 583 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 584 | expe ct(pid).to .eql(req.b ody.pid); | |
| 585 | retu rn callbac k(); | |
| 586 | }); | |
| 587 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.to', 'r oot@localh ost'); | |
| 588 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.from', 'nobody@lo calhost'); | |
| 589 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 590 | retu rn callbac k(null, { | |
| 591 | rejectedEr rors: [ | |
| 592 | 'foo' | |
| 593 | ] | |
| 594 | }); | |
| 595 | }); | |
| 596 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 597 | retu rn handler (); | |
| 598 | }); | |
| 599 | var res = {}; | |
| 600 | res.stat us = funct ion(code) { | |
| 601 | expe ct(code).t o.eql(500) ; | |
| 602 | retu rn this; | |
| 603 | }; | |
| 604 | res.rdkS end = func tion(body) { | |
| 605 | expe ct(body).t o.be.an.er ror(); | |
| 606 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 607 | expe ct(body.co de).to.eql ('200.500. 1016'); | |
| 608 | done (); | |
| 609 | }; | |
| 610 | res.set = function () { | |
| 611 | }; | |
| 612 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 613 | }) ; | |
| 614 | it ('logs an error when notificat ion email send attem pt failed' , function (done) { | |
| 615 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 616 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 617 | retu rn myUuid; | |
| 618 | }); | |
| 619 | var req = {}; | |
| 620 | req.id = '543'; | |
| 621 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 622 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 623 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 624 | retu rn logger; | |
| 625 | }); | |
| 626 | _.set(re q, 'sessio n.user', { | |
| 627 | uid: 'urn: va:user: R E D A CTED :1', | |
| 628 | firs tname: 'JO HN', | |
| 629 | last name: 'DOE ' | |
| 630 | }); | |
| 631 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 632 | _.set(re q, 'sessio n.id', '12 34'); | |
| 633 | _.set(re q, 'body', requestBo dy); | |
| 634 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 635 | expe ct(pid).to .eql(req.b ody.pid); | |
| 636 | retu rn callbac k(); | |
| 637 | }); | |
| 638 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 639 | expe ct(pid).to .eql(req.b ody.pid); | |
| 640 | retu rn callbac k(); | |
| 641 | }); | |
| 642 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.to', 'r oot@localh ost'); | |
| 643 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.from', 'nobody@lo calhost'); | |
| 644 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 645 | retu rn callbac k(new Erro r('nodemai ler error' )); | |
| 646 | }); | |
| 647 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 648 | retu rn handler (); | |
| 649 | }); | |
| 650 | var res = {}; | |
| 651 | res.stat us = funct ion(code) { | |
| 652 | expe ct(code).t o.eql(500) ; | |
| 653 | retu rn this; | |
| 654 | }; | |
| 655 | res.rdkS end = func tion(body) { | |
| 656 | expe ct(body).t o.be.an.er ror(); | |
| 657 | expe ct(req.log ger.error. calledWith (body)).to .be.true() ; | |
| 658 | expe ct(body.co de).to.eql ('200.500. 1017'); | |
| 659 | done (); | |
| 660 | }; | |
| 661 | res.set = function () { | |
| 662 | }; | |
| 663 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 664 | }) ; | |
| 665 | it ('responds with the incident i d on succe ss', funct ion(done) { | |
| 666 | var myUu id = 'eefc f960-e3de- 11e6-82bd- bfc89d917f bf'; | |
| 667 | sinon.st ub(uuid, ' v1').calls Fake(funct ion() { | |
| 668 | retu rn myUuid; | |
| 669 | }); | |
| 670 | var req = {}; | |
| 671 | req.id = '543'; | |
| 672 | _.set(re q, 'logger .child', f unction(ob ject) { | |
| 673 | expe ct(object) .to.eql({i ncidentRep ortId: 'eH MP-IR-' + myUuid}); | |
| 674 | var logger = s inon.stub( bunyan.cre ateLogger( {name: 'in cident-rep ort-resour ce-spec'}) ); | |
| 675 | retu rn logger; | |
| 676 | }); | |
| 677 | _.set(re q, 'sessio n.user', { | |
| 678 | uid: 'urn: va:user: R E D A CTED :1', | |
| 679 | firs tname: 'JO HN', | |
| 680 | last name: 'DOE ' | |
| 681 | }); | |
| 682 | _.set(re q, 'app.co nfig.incid ents.rootD irectory', '/tmp/foo '); | |
| 683 | _.set(re q, 'sessio n.id', '12 34'); | |
| 684 | _.set(re q, 'body', requestBo dy); | |
| 685 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tusDetail' , function (pid, req, callback) { | |
| 686 | expe ct(pid).to .eql(req.b ody.pid); | |
| 687 | retu rn callbac k(); | |
| 688 | }); | |
| 689 | _.set(re q, 'app.su bsystems.j dsSync.get PatientSta tus', func tion(pid, req, callb ack) { | |
| 690 | expe ct(pid).to .eql(req.b ody.pid); | |
| 691 | retu rn callbac k(); | |
| 692 | }); | |
| 693 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.to', 'r oot@localh ost'); | |
| 694 | _.set(re q, 'app.co nfig.incid ents.notif icationEma il.from', 'nobody@lo calhost'); | |
| 695 | _.set(re q, 'app.su bsystems.e mail.sendM ail', func tion(confi g, callbac k) { | |
| 696 | retu rn callbac k(); | |
| 697 | }); | |
| 698 | sinon.st ub(async, 'series'). callsFake( function(t asks, hand ler) { | |
| 699 | retu rn handler (); | |
| 700 | }); | |
| 701 | var res = {}; | |
| 702 | res.stat us = funct ion(code) { | |
| 703 | expe ct(code).t o.eql(200) ; | |
| 704 | retu rn this; | |
| 705 | }; | |
| 706 | res.rdkS end = func tion(body) { | |
| 707 | expe ct(body).t o.eql({ | |
| 708 | incidentRe portId: 'e HMP-IR-' + myUuid | |
| 709 | }); | |
| 710 | done (); | |
| 711 | }; | |
| 712 | res.set = function () { | |
| 713 | }; | |
| 714 | incident ReportReso urce._crea teIncident Report(req , res); | |
| 715 | }) ; | |
| 716 | }); | |
| 717 | ||
| 718 | descri be('parseD ateFromUui dV1', func tion() { | |
| 719 | it ('parses a date from a valid u uid v1', f unction() { | |
| 720 | var uuid v1A = 'eef cf960-e3de -11e6-82bd -bfc89d917 fbf'; | |
| 721 | var uuid v1B = '3d1 9b980-e3e9 -11e6-82bd -bfc89d917 fbf'; | |
| 722 | var date A = incide ntReportRe source._pa rseDateFro mUuidV1(uu idv1A); | |
| 723 | var date B = incide ntReportRe source._pa rseDateFro mUuidV1(uu idv1B); | |
| 724 | expect(d ateA.getTi me()).to.e ql(1485445 731318); | |
| 725 | expect(d ateB.getTi me()).to.e ql(1485450 157336); | |
| 726 | }) ; | |
| 727 | }); | |
| 728 | ||
| 729 | descri be('normal izeUnixTim estampToMi lliseconds ', functio n() { | |
| 730 | it ('converts a second- based unix timestamp to a mill isecond-ba sed unix t imestamp', function( ) { | |
| 731 | var inpu t = 148545 0339; | |
| 732 | var expe cted = 148 5450339000 ; | |
| 733 | var actu al = incid entReportR esource._n ormalizeUn ixTimestam pToMillise conds(inpu t); | |
| 734 | expect(a ctual).to. equal(expe cted); | |
| 735 | }) ; | |
| 736 | it ('leaves a milliseco nd-based u nix timest amp alone' , function () { | |
| 737 | var inpu t = 148545 0505000; | |
| 738 | var actu al = incid entReportR esource._n ormalizeUn ixTimestam pToMillise conds(inpu t); | |
| 739 | expect(a ctual).to. equal(inpu t); | |
| 740 | }) ; | |
| 741 | }); | |
| 742 | ||
| 743 | descri be('replac eErrors', function() { | |
| 744 | it ('ignores things tha t aren\'t Errors', f unction() { | |
| 745 | var notA nError = { }; | |
| 746 | var hand led = inci dentReport Resource._ replaceErr ors('key', notAnErro r); | |
| 747 | expect(h andled).to .be(notAnE rror); | |
| 748 | }) ; | |
| 749 | it ('ignores RdkErrors' , function () { | |
| 750 | var rdkE rror = new RdkError( new Error( 'test erro r')); | |
| 751 | var hand led = inci dentReport Resource._ replaceErr ors('key', rdkError) ; | |
| 752 | expect(h andled).to .be(rdkErr or); | |
| 753 | }) ; | |
| 754 | it ('converts Errors', function() { | |
| 755 | var erro r = new Er ror('test error'); | |
| 756 | var hand led = inci dentReport Resource._ replaceErr ors('key', error); | |
| 757 | expect(_ .isObject( handled)). to.be(true ); | |
| 758 | expect(_ .keys(hand led)).to.e ql(['stack ', 'messag e']); | |
| 759 | expect(h andled.mes sage).to.b e('test er ror'); | |
| 760 | }) ; | |
| 761 | }); | |
| 762 | ||
| 763 | descri be('format JsonValueA tIndentati onLevel', function() { | |
| 764 | it ('adds ind entation t o lines af ter the fi rst line', function( ) { | |
| 765 | var json = {a: 'a' , b: 'b'}; | |
| 766 | var form attedJson = incident ReportReso urce._form atJsonValu eAtIndenta tionLevel( json, 2); | |
| 767 | var line s = format tedJson.sp lit('\n'); | |
| 768 | var firs tLine = li nes.shift( ); | |
| 769 | expect(f irstLine). to.equal(' {'); // no indentati on to firs t line | |
| 770 | var last Line = lin es.pop(); | |
| 771 | expect(l astLine).t o.equal('' ); // fina l newline | |
| 772 | _.each(l ines, func tion(line) { | |
| 773 | expe ct(line).t o.match(/ .*/); / / 2 spaces = 1 level of indent ation | |
| 774 | }); | |
| 775 | }) ; | |
| 776 | it ('does not indent on e-line res ults', fun ction() { | |
| 777 | var json = {}; | |
| 778 | var form attedJson = incident ReportReso urce._form atJsonValu eAtIndenta tionLevel( json, 2); | |
| 779 | var line s = format tedJson.sp lit('\n'); | |
| 780 | var firs tLine = li nes.shift( ); | |
| 781 | expect(f irstLine). to.equal(' {}'); // n o indentat ion to fir st line | |
| 782 | var last Line = lin es.pop(); | |
| 783 | expect(l astLine).t o.equal('' ); // fina l newline | |
| 784 | }) ; | |
| 785 | }); | |
| 786 | ||
| 787 | descri be('format YamlValueA tIndentati onLevel', function() { | |
| 788 | it ('adds ind entation t o lines af ter the fi rst line', function( ) { | |
| 789 | var json = {a: 'a' , b: 'b'}; | |
| 790 | var form attedYaml = incident ReportReso urce._form atYamlValu eAtIndenta tionLevel( json, 2); | |
| 791 | var line s = format tedYaml.sp lit('\n'); | |
| 792 | var firs tLine = li nes.shift( ); | |
| 793 | expect(f irstLine). to.equal(' a: a'); // no indent ation to f irst line | |
| 794 | var last Line = lin es.pop(); | |
| 795 | expect(l astLine).t o.equal('' ); // fina l newline | |
| 796 | _.each(l ines, func tion(line) { | |
| 797 | expe ct(line).t o.match(/ .*/); / / 2 spaces = 1 level of indent ation | |
| 798 | }); | |
| 799 | }) ; | |
| 800 | it ('does not indent on e-line res ults', fun ction() { | |
| 801 | var json = 'my sin gle line'; | |
| 802 | var form attedYaml = incident ReportReso urce._form atYamlValu eAtIndenta tionLevel( json, 2); | |
| 803 | var line s = format tedYaml.sp lit('\n'); | |
| 804 | var firs tLine = li nes.shift( ); | |
| 805 | expect(f irstLine). to.equal(' my single line'); // no indent ation to f irst line | |
| 806 | var last Line = lin es.pop(); | |
| 807 | expect(l astLine).t o.equal('' ); // fina l newline | |
| 808 | }) ; | |
| 809 | it ('wraps lo ng input t o the corr ect indent ation leve l', functi on() { | |
| 810 | var json = 'my sin gle line m y single l ine my sin gle line m y single l ine my sin gle line m y single l ine my sin gle line m y single l ine'; | |
| 811 | var form attedYaml = incident ReportReso urce._form atYamlValu eAtIndenta tionLevel( json, 2); | |
| 812 | var line s = format tedYaml.sp lit('\n'); | |
| 813 | var firs tLine = li nes.shift( ); | |
| 814 | expect(f irstLine). to.equal(' >-'); // n o indentat ion to fir st line | |
| 815 | var last Line = lin es.pop(); | |
| 816 | expect(l astLine).t o.equal('' ); // fina l newline | |
| 817 | expect(l ines).to.h ave.length (2); | |
| 818 | _.each(l ines, func tion(line) { | |
| 819 | expe ct(line).t o.match(/ .*/); / / 2 spaces = 1 level of indent ation | |
| 820 | }); | |
| 821 | ||
| 822 | }) ; | |
| 823 | }); | |
| 824 | ||
| 825 | descri be('getPat ientFromRe port', fun ction() { | |
| 826 | it ('uses bod y.pid if a vailable', function( ) { | |
| 827 | var body = {}; | |
| 828 | body.pid = '123'; | |
| 829 | body.icn = '234'; | |
| 830 | var pati ent = inci dentReport Resource._ getPatient FromReport (body); | |
| 831 | expect(p atient).to .equal(bod y.pid); | |
| 832 | }) ; | |
| 833 | it ('uses bod y.icn if b ody.pid is unavailab le', funct ion() { | |
| 834 | var body = {}; | |
| 835 | body.icn = '234'; | |
| 836 | var pati ent = inci dentReport Resource._ getPatient FromReport (body); | |
| 837 | expect(p atient).to .equal(bod y.icn); | |
| 838 | }) ; | |
| 839 | it ('returns undefined if no pid is availab le', funct ion() { | |
| 840 | var body = {}; | |
| 841 | var pati ent = inci dentReport Resource._ getPatient FromReport (body); | |
| 842 | expect(p atient).to .be.undefi ned(); | |
| 843 | }) ; | |
| 844 | }); | |
| 845 | }); |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.