89. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/4/2017 8:04:36 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.

89.1 Files compared

# Location File Last Modified
1 rdk.zip\rdk\product\production\rdk\src\subsystems\jds jds-sync-subsystem-spec.js Mon Aug 21 12:51:00 2017 UTC
2 rdk.zip\rdk\product\production\rdk\src\subsystems\jds jds-sync-subsystem-spec.js Tue Oct 3 18:32:54 2017 UTC

89.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 46 1246
Changed 45 118
Inserted 0 0
Removed 0 0

89.3 Comparison options

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

89.4 Active regular expressions

No regular expressions were active.

89.5 Comparison detail

  1   'use stric t';
  2  
  3   var rdk =  require('. ./../core/ rdk');
  4   var jdsSyn c = requir e('./jds-s ync-subsys tem');
  5   var httpMo cks = requ ire('node- mocks-http ');
  6   var _ = re quire('lod ash');
  7   var pidVal idator = r dk.utils.p idValidato r;
  8   var nullch ecker = re quire('../ ../utils/n ullchecker ');
  9   var S = re quire('str ing');
  10  
  11   var full_i ncomplete  = {
  12       icn: ' 10108V4208 71',
  13       latest Enterprise SyncReques tTimestamp : 14678193 60679,
  14       latest JobTimesta mp: 146781 9371546,
  15       latest SourceStam pTime: 201 6070611360 0,
  16       sites:  {
  17             ' R E D A CTED ': {
  18                latestJo bTimestamp : 14678193 60679,
  19                  pid: ' R E D A CTED ;3',
  20                sourceSt ampTime: 2 0160706094 004,
  21                syncComp leted: fal se,
  22                solrSync Completed:  false
  23           },
  24             REDA C TED : {
  25                latestJo bTimestamp : 14678193 60679,
  26                  pid: ' REDA C TED ;3',
  27                sourceSt ampTime: 2 0160706093 941,
  28                syncComp leted: fal se,
  29                solrSync Completed:  false
  30           }
  31       },
  32       syncCo mpleted: f alse,
  33       solrSy ncComplete d: false
  34   };
  35  
  36   var full_c omplete =  {
  37       icn: ' 10108V4208 71',
  38       latest Enterprise SyncReques tTimestamp : 14678193 60679,
  39       latest JobTimesta mp: 146781 9371546,
  40       latest SourceStam pTime: 201 6070611360 0,
  41       sites:  {
  42             ' R E D A CTED ': {
  43                latestJo bTimestamp : 14678193 60679,
  44                  pid: ' R E D A CTED ;3',
  45                sourceSt ampTime: 2 0160706094 004,
  46                syncComp leted: tru e,
  47                solrSync Completed:  true
  48           },
  49             REDA C TED : {
  50                latestJo bTimestamp : 14678193 60679,
  51                  pid: ' REDA C TED ;3',
  52                sourceSt ampTime: 2 0160706093 941,
  53                syncComp leted: tru e,
  54                solrSync Completed:  true
  55           }
  56       },
  57       syncCo mpleted: t rue,
  58       solrSy ncComplete d: true
  59   };
  60  
  61   var site_i ncomplete  = {
  62       icn: ' 10108V4208 71',
  63       latest Enterprise SyncReques tTimestamp : 14678193 60679,
  64       sites:  {
  65             ' R E D A CTED ': {
  66                latestJo bTimestamp : 14678193 60679,
  67                  pid: ' R E D A CTED ;3',
  68                sourceSt ampTime: 2 0160706094 004,
  69                syncComp leted: tru e,
  70                solrSync Completed:  true
  71           },
  72             REDA C TED : {
  73                latestJo bTimestamp : 14678193 60679,
  74                  pid: ' REDA C TED ;3',
  75                sourceSt ampTime: 2 0160706093 941,
  76                syncComp leted: fal se,
  77                solrSync Completed:  false
  78           }
  79       }
  80   };
  81  
  82   var site_c omplete =  {
  83       icn: ' 10108V4208 71',
  84       latest Enterprise SyncReques tTimestamp : 14678193 60679,
  85       sites:  {
  86             ' R E D A CTED ': {
  87                latestJo bTimestamp : 14678193 60679,
  88                  pid: ' R E D A CTED ;3',
  89                sourceSt ampTime: 2 0160706094 004,
  90                syncComp leted: tru e,
  91                solrSync Completed:  true
  92           },
  93             REDA C TED : {
  94                latestJo bTimestamp : 14678193 60679,
  95                  pid: ' REDA C TED ;3',
  96                sourceSt ampTime: 2 0160706093 941,
  97                syncComp leted: tru e,
  98                solrSync Completed:  true
  99           }
  100       }
  101   };
  102  
  103   var site_e rror = {
  104       icn: ' 10108V4208 71',
  105       latest Enterprise SyncReques tTimestamp : 14678193 60679,
  106       sites:  {
  107             ' R E D A CTED ': {
  108                latestJo bTimestamp : 14678193 60679,
  109                  pid: ' R E D A CTED ;3',
  110                sourceSt ampTime: 2 0160706094 004,
  111                hasError : true,
  112                syncComp leted: fal se,
  113                solrSync Completed:  false
  114           },
  115             REDA C TED : {
  116                latestJo bTimestamp : 14678193 60679,
  117                  pid: ' REDA C TED ;3',
  118                sourceSt ampTime: 2 0160706093 941,
  119                syncComp leted: tru e,
  120                solrSync Completed:  true
  121           }
  122       }
  123   };
  124  
  125   var full_e rror = {
  126       icn: ' 10108V4208 71',
  127       latest Enterprise SyncReques tTimestamp : 14678193 60679,
  128       latest JobTimesta mp: 146781 9371546,
  129       latest SourceStam pTime: 201 6070611360 0,
  130       hasErr or: true,
  131       sites:  {
  132             ' R E D A CTED ': {
  133                latestJo bTimestamp : 14678193 60679,
  134                  pid: ' R E D A CTED ;3',
  135                sourceSt ampTime: 2 0160706094 004,
  136                syncComp leted: tru e,
  137                solrSync Completed:  true
  138           },
  139             REDA C TED : {
  140                latestJo bTimestamp : 14678193 60679,
  141                  pid: ' REDA C TED ;3',
  142                sourceSt ampTime: 2 0160706093 941,
  143                hasError : true,
  144                syncComp leted: fal se,
  145                solrSync Completed:  false
  146           }
  147       },
  148       syncCo mpleted: f alse,
  149       solrSy ncComplete d: false
  150   };
  151  
  152   var full_s olr_error  = {
  153       icn: ' 10108V4208 71',
  154       latest Enterprise SyncReques tTimestamp : 14812935 55965,
  155       latest JobTimesta mp: 148129 3555965,
  156       latest SourceStam pTime: 201 6120816230 0,
  157       sites:  {
  158             ' R E D A CTED ': {
  159                latestJo bTimestamp : 14812935 55965,
  160                  pid: ' R E D A CTED ;3',
  161                solrSync Completed:  false,
  162                hasSolrE rror: true ,
  163                sourceSt ampTime: 2 0161208162 300,
  164                syncComp leted: fal se
  165           },
  166             REDA C TED : {
  167                latestJo bTimestamp : 14812935 55965,
  168                  pid: ' REDA C TED ;3',
  169                solrSync Completed:  true,
  170                sourceSt ampTime: 2 0161208162 254,
  171                syncComp leted: tru e
  172           }
  173       },
  174       solrSy ncComplete d: false,
  175       hasSol rError: tr ue,
  176       syncCo mpleted: f alse
  177   };
  178  
  179   describe(' jdsSync\'s ', functio n() {
  180       var pi d;
  181       var re q;
  182       var lo g;
  183       var ht tpExpected ;
  184       before Each(funct ion() {
  185           pi d = 'test; patientId' ;
  186  
  187           re q = buildR equest();
  188           lo g = '';
  189  
  190           ht tpExpected  = [];
  191           si non.stub(p idValidato r, 'isIcn' ).callsFak e(function (icn) {
  192                return n ullchecker .isNotNull ish(icn) & & !S(icn). contains(' ;');
  193           }) ;
  194           si non.stub(p idValidato r, 'isSite Dfn').call sFake(func tion(icn)  {
  195                return n ullchecker .isNotNull ish(icn) & & S(icn).c ontains('; ');
  196           }) ;
  197           si non.stub(r dk.utils.h ttp, 'get' ).callsFak e(stubHttp .bind(null , 'GET'));
  198           si non.stub(r dk.utils.h ttp, 'post ').callsFa ke(stubHtt p.bind(nul l, 'POST') );
  199       });
  200  
  201       afterE ach(functi on() {
  202           pi dValidator .isIcn.res tore(); //  Unwraps t he spy
  203           pi dValidator .isSiteDfn .restore() ; // Unwra ps the spy
  204           rd k.utils.ht tp.get.res tore(); //  Unwraps t he spy
  205           rd k.utils.ht tp.post.re store(); / / Unwraps  the spy
  206       });
  207  
  208       descri be('getPat ientStatus ', functio n() {
  209           it ('should a dd the pid  to the pa th', funct ion(done)  {
  210                expectHt tpFetch('v xSyncServe r', '/sync /status?pi d=test;pat ientId');
  211  
  212  
  213                req.app. subsystems .jdsSync.g etPatientS tatus(pid,  req, expe ctSuccess( done));
  214           }) ;
  215  
  216           it ('should a dd the icn  to the pa th', funct ion(done)  {
  217                pid = 't esticn';
  218                expectHt tpFetch('v xSyncServe r', '/sync /status?ic n=testicn' );
  219                req.app. subsystems .jdsSync.g etPatientS tatus(pid,  req, expe ctSuccess( done));
  220           }) ;
  221  
  222           it ('should g et the pid  from the  request wh en not pro vided', fu nction(don e) {
  223                req = bu ildRequest ({
  224                    para ms: {
  225                         pid: 'req; pid'
  226                    }
  227                });
  228                expectHt tpFetch('v xSyncServe r', '/sync /status?pi d=req;pid' );
  229                req.app. subsystems .jdsSync.g etPatientS tatus(null , req, exp ectSuccess (done));
  230           }) ;
  231  
  232           it ('should r eturn 404  when a pat ient isn\' t found',  function(d one) {
  233                expectHt tpFetch('v xSyncServe r', '/sync /status?pi d=test;pat ientId', 4 04);
  234                req.app. subsystems .jdsSync.g etPatientS tatus(pid,  req, expe ctError(do ne, 404, ' pid test;p atientId i s unsynced '));
  235           }) ;
  236  
  237           it ('should r eturn a st andard err or result  for other  errors', f unction(do ne) {
  238                expectHt tpFetch('v xSyncServe r', '/sync /status?pi d=test;pat ientId', 4 07);
  239                req.app. subsystems .jdsSync.g etPatientS tatus(pid,  req, expe ctError(do ne, 407));
  240           }) ;
  241       });
  242  
  243       descri be('isSimp leSyncStat usWithErro r()', func tion() {
  244           it ('should b e false fo r empty st atus', fun ction() {
  245                expect(j dsSync.isS impleSyncS tatusWithE rror()).to .equal(fal se);
  246           }) ;
  247  
  248           it ('should b e false wh en priorit ySite is p assed and  no hasErro r attribut e exists',  function( ) {
  249                  expect(jds Sync.isSim pleSyncSta tusWithErr or(full_co mplete, ' REDA C TED ')).to.equ al(false);
  250                  expect(jds Sync.isSim pleSyncSta tusWithErr or(site_in complete,  ' REDA C TED ')).to.equ al(false);
  251                  expect(jds Sync.isSim pleSyncSta tusWithErr or(site_er ror, ' REDA C TED ')).to.equ al(false);
  252           }) ;
  253  
  254           it ('should b e false wh en no hasE rror attri bute exist s', functi on() {
  255                expect(j dsSync.isS impleSyncS tatusWithE rror(full_ incomplete )).to.equa l(false);
  256                expect(j dsSync.isS impleSyncS tatusWithE rror(full_ complete)) .to.equal( false);
  257           }) ;
  258  
  259           it ('should b e true whe n priority Site is pa ssed and n o hasError  attribute  exists fo r that sit e', functi on() {
  260                  expect(jds Sync.isSim pleSyncSta tusWithErr or(site_er ror, ' R E D A CTED ')).to.equ al(true);
  261           }) ;
  262  
  263           it ('should b e true whe n no prior itySite is  passed an d every si te has a h asError at tribute',  function()  {
  264                expect(j dsSync.isS impleSyncS tatusWithE rror(full_ error)).to .equal(tru e);
  265                expect(j dsSync.isS impleSyncS tatusWithE rror(site_ error)).to .equal(fal se);
  266           }) ;
  267  
  268           it ('should b e true whe n priority Site passe d does not  exist and  every sit e has a ha sError att ribute', f unction()  {
  269                expect(j dsSync.isS impleSyncS tatusWithE rror(full_ error, 'XX XX')).to.e qual(true) ;
  270                expect(j dsSync.isS impleSyncS tatusWithE rror(site_ error, 'XX XX')).to.e qual(false );
  271           }) ;
  272       });
  273  
  274       descri be('isSimp leSyncStat usComplete ()', funct ion() {
  275           it ('should b e false fo r empty st atus', fun ction() {
  276                expect(j dsSync.isS impleSyncS tatusCompl ete()).to. equal(fals e);
  277           }) ;
  278  
  279           it ('should b e true if  the top-le vel syncCo mpleted at tribute is  true', fu nction() {
  280                expect(j dsSync.isS impleSyncS tatusCompl ete(full_c omplete)). to.equal(t rue);
  281           }) ;
  282  
  283           it ('should b e false wh en no prio ritySite i s passed a nd every s ite-level  syncComple ted attrib ute is fal se', funct ion() {
  284                expect(j dsSync.isS impleSyncS tatusCompl ete(full_i ncomplete) ).to.equal (false);
  285           }) ;
  286  
  287           it ('should b e true whe n no prior itySite is  passed an d any sync Completed  attributes  are true' , function () {
  288                expect(j dsSync.isS impleSyncS tatusCompl ete(full_c omplete)). to.equal(t rue);
  289                expect(j dsSync.isS impleSyncS tatusCompl ete(site_c omplete)). to.equal(t rue);
  290           }) ;
  291  
  292           it ('should b e false wh en priorit ySite sync Completed  attribute  is false',  function( ) {
  293                  expect(jds Sync.isSim pleSyncSta tusComplet e(site_inc omplete, ' REDA C TED ')).to.equ al(false);
  294           }) ;
  295  
  296           it ('should b e true whe n priority Site syncC ompleted a ttribute i s true', f unction()  {
  297                  expect(jds Sync.isSim pleSyncSta tusComplet e(site_inc omplete, ' R E D A CTED ')).to.equ al(true);
  298           }) ;
  299  
  300           it ('should b e true whe n priority Site is tr ue with er ror in oth er site',  function()  {
  301                  expect(jds Sync.isSim pleSyncSta tusComplet e(site_err or, ' REDA C TED ')).to.equ al(true);
  302           }) ;
  303  
  304           it ('should b e false wh en priorit ySite does  not exist  and every  site-leve l syncComp leted attr ibute is f alse', fun ction() {
  305                expect(j dsSync.isS impleSyncS tatusCompl ete(full_i ncomplete,  'XXXX')). to.equal(f alse);
  306           }) ;
  307  
  308           it ('should b e true whe n priority Site does  not exist  and any sy ncComplete d attribut es are tru e', functi on() {
  309                expect(j dsSync.isS impleSyncS tatusCompl ete(full_c omplete, ' XXXX')).to .equal(tru e);
  310                expect(j dsSync.isS impleSyncS tatusCompl ete(site_c omplete, ' XXXX')).to .equal(tru e);
  311           }) ;
  312       });
  313  
  314       descri be('getPat ientStatus Detail', f unction()  {
  315           it ('should a dd the pid  and detai led params  to the pa th', funct ion(done)  {
  316                expectHt tpFetch('j dsServer',  '/status/ test;patie ntId?detai led=true') ;
  317                req.app. subsystems .jdsSync.g etPatientS tatusDetai l(pid, req , expectSu ccess(done ));
  318           }) ;
  319  
  320           it ('should r eturn 404  when a pat ient isn\' t found',  function(d one) {
  321                expectHt tpFetch('j dsServer',  '/status/ test;patie ntId?detai led=true',  404);
  322                req.app. subsystems .jdsSync.g etPatientS tatusDetai l(pid, req , expectEr ror(done,  404, 'pid  test;patie ntId is un synced'));
  323           }) ;
  324  
  325           it ('should r eturn a st andard err or result  for other  errors', f unction(do ne) {
  326                expectHt tpFetch('j dsServer',  '/status/ test;patie ntId?detai led=true',  407);
  327                req.app. subsystems .jdsSync.g etPatientS tatusDetai l(pid, req , expectEr ror(done,  407));
  328           }) ;
  329       });
  330  
  331       descri be('getPat ientDataSt atusSimple ', functio n() {
  332           it ('should a dd the pid  and detai led params  to the pa th', funct ion(done)  {
  333                expectHt tpFetch('j dsServer',  '/status/ test;patie ntId?detai led=true') ;
  334                req.app. subsystems .jdsSync.g etPatientS tatusDetai l(pid, req , expectSu ccess(done ));
  335           }) ;
  336  
  337           it ('should r eturn 404  when a pat ient isn\' t found',  function(d one) {
  338                expectHt tpFetch('j dsServer',  '/status/ test;patie ntId?detai led=true',  404);
  339                req.app. subsystems .jdsSync.g etPatientS tatusDetai l(pid, req , expectEr ror(done,  404, 'pid  test;patie ntId is un synced'));
  340           }) ;
  341  
  342           it ('should r eturn a st andard err or result  for other  errors', f unction(do ne) {
  343                expectHt tpFetch('j dsServer',  '/status/ test;patie ntId?detai led=true',  407);
  344                req.app. subsystems .jdsSync.g etPatientS tatusDetai l(pid, req , expectEr ror(done,  407));
  345           }) ;
  346       });
  347  
  348       descri be('getOpe rationalSt atus', fun ction() {
  349           va r site = ' testsite';
  350  
  351           it ('should g et the sit e from the  request s ite proper ty', funct ion(done)  {
  352                req.site  = 'sessio nSite';
  353                expectHt tpFetch('j dsServer',  '/statuso d/sessionS ite');
  354                req.app. subsystems .jdsSync.g etOperatio nalStatus( null, req,  expectSuc cess(done) );
  355           }) ;
  356  
  357           it ('should u se the pas sed-in sit e', functi on(done) {
  358                expectHt tpFetch('j dsServer',  '/statuso d/testsite ');
  359                req.app. subsystems .jdsSync.g etOperatio nalStatus( site, req,  expectSuc cess(done) );
  360           }) ;
  361  
  362           it ('should r eturn a st andard err or result  for errors ', functio n(done) {
  363                expectHt tpFetch('j dsServer',  '/statuso d/testsite ', 407);
  364                req.app. subsystems .jdsSync.g etOperatio nalStatus( site, req,  expectErr or(done, 4 07));
  365           }) ;
  366       });
  367  
  368       descri be('getPat ientAllSit es', funct ion() {
  369           it ('should a dd the pid  to the pa th', funct ion(done)  {
  370                expectHt tpFetch('j dsServer',  '/vpr/mpi d/test;pat ientId');
  371                req.app. subsystems .jdsSync.g etPatientA llSites(pi d, req, ex pectSucces s(done));
  372           }) ;
  373  
  374           it ('should r eturn succ ess when t he status  is 202', f unction(do ne) {
  375                expectHt tpFetch('j dsServer',  '/vpr/mpi d/test;pat ientId', 2 02);
  376                req.app. subsystems .jdsSync.g etPatientA llSites(pi d, req, ex pectSucces s(done));
  377           }) ;
  378  
  379           it ('should r eturn a st andard err or result  for errors ', functio n(done) {
  380                expectHt tpFetch('j dsServer',  '/vpr/mpi d/test;pat ientId', 4 07);
  381                req.app. subsystems .jdsSync.g etPatientA llSites(pi d, req, ex pectError( done, 407) );
  382           }) ;
  383       });
  384       //jshi nt -W069
  385       descri be('create SimpleStat usResult',  function( ) {
  386           it ('should r eturn a sy nc complet e response ', functio n() {
  387                var stat us = jdsSy nc.createS impleStatu sResult(re q.logger,  _.keys(req .app.confi g.vistaSit es), {
  388                    data : full_com plete
  389                });
  390  
  391                expect(s tatus.allS ites).to.b e.true();
  392                expect(s tatus.isSo lrSyncComp leted).to. be.true();
  393                  expect(sta tus.VISTA[ ' R E D A CTED '].isSyncC ompleted). to.be.true ();
  394                  expect(sta tus.VISTA[ ' R E D A CTED '].isSolrS yncComplet ed).to.be. true();
  395                  expect(sta tus.VISTA[ ' REDA C TED '].isSyncC ompleted). to.be.true ();
  396                  expect(sta tus.VISTA[ ' REDA C TED '].isSolrS yncComplet ed).to.be. true();
  397                expect(s tatus.hasS olrError). to.be.unde fined();
  398           }) ;
  399  
  400           it ('should r eturn a sy nc incompl ete respon se', funct ion() {
  401                var stat us = jdsSy nc.createS impleStatu sResult(re q.logger,  _.keys(req .app.confi g.vistaSit es), {
  402                    data : full_inc omplete
  403                });
  404  
  405                expect(s tatus.allS ites).to.b e.false();
  406                expect(s tatus.isSo lrSyncComp leted).to. be.false() ;
  407                  expect(sta tus.VISTA[ ' R E D A CTED '].isSyncC ompleted). to.be.fals e();
  408                  expect(sta tus.VISTA[ ' R E D A CTED '].isSolrS yncComplet ed).to.be. false();
  409                  expect(sta tus.VISTA[ ' REDA C TED '].isSyncC ompleted). to.be.fals e();
  410                  expect(sta tus.VISTA[ ' REDA C TED '].isSolrS yncComplet ed).to.be. false();
  411                expect(s tatus.hasS olrError). to.be.unde fined();
  412           }) ;
  413  
  414           it ('should r eturn hasS olrError w hen it is  present',  function()  {
  415                var stat us = jdsSy nc.createS impleStatu sResult(re q.logger,  _.keys(req .app.confi g.vistaSit es), {
  416                    data : full_sol r_error
  417                });
  418  
  419                expect(s tatus.allS ites).to.b e.false();
  420                expect(s tatus.isSo lrSyncComp leted).to. be.false() ;
  421                  expect(sta tus.VISTA[ ' R E D A CTED '].isSyncC ompleted). to.be.fals e();
  422                  expect(sta tus.VISTA[ ' R E D A CTED '].isSolrS yncComplet ed).to.be. false();
  423                  expect(sta tus.VISTA[ ' R E D A CTED '].hasSolr Error).to. be.true();
  424                  expect(sta tus.VISTA[ ' REDA C TED '].isSyncC ompleted). to.be.true ();
  425                  expect(sta tus.VISTA[ ' REDA C TED '].isSolrS yncComplet ed).to.be. true();
  426                expect(s tatus.hasS olrError). to.be.true ();
  427           }) ;
  428       });
  429       //jshi nt +W069
  430       descri be('syncSt atusResult Processor' , function () {
  431           it ('should r espond wit h a 500 if  the respo nse is fal sey', func tion() {
  432                var erro r = 599;
  433                  var pid =  ' R E D A CTED ;3';
  434                var resp onse = 're sponse';
  435                var data  = 'data';
  436                var expe ctedRespon se = {
  437                    stat us: 500,
  438                    data : {
  439                         error: {
  440                             code:  500,
  441                             messag e: 'data'
  442                         }
  443                    }
  444                };
  445                jdsSync. _syncStatu sResultPro cessor(pid , function (err, resp onse) {
  446                    expe ct(err).to .equal(err or);
  447                    expe ct(respons e).to.eql( expectedRe sponse);
  448                }, req,  error, res ponse, dat a);
  449           }) ;
  450           it ('should c reate an u nsynced me ssage if t he respons e is 404',  function( ) {
  451                var erro r = null;
  452                  var pid =  ' R E D A CTED ;3';
  453                var resp onse = {
  454                    stat usCode: 40 4
  455                };
  456                var data  = 'data';
  457                var expe ctedRespon se = {
  458                    stat us: 404,
  459                    data : {
  460                         error: {
  461                             code:  404,
  462                               message: ' pid  R E D A CTED ;3 is unsy nced'
  463                         }
  464                    }
  465                };
  466                jdsSync. _syncStatu sResultPro cessor(pid , function (err, resp onse) {
  467                    expe ct(err).to .equal(err or);
  468                    expe ct(respons e).to.eql( expectedRe sponse);
  469                }, req,  error, res ponse, dat a);
  470           }) ;
  471           it ('should c reate an s uccessful  message if  the respo nse is 200 ', functio n() {
  472                var erro r = null;
  473                  var pid =  ' R E D A CTED ;3';
  474                var resp onse = {
  475                    stat usCode: 20 0
  476                };
  477                var data  = 'data';
  478                var expe ctedRespon se = {
  479                    stat us: 200,
  480                    data : data
  481                };
  482                jdsSync. _syncStatu sResultPro cessor(pid , function (err, resp onse) {
  483                    expe ct(err).to .equal(err or);
  484                    expe ct(respons e).to.eql( expectedRe sponse);
  485                }, req,  error, res ponse, dat a);
  486           }) ;
  487           it ('should c reate an s uccessful  message if  the respo nse is 202 ', functio n() {
  488                var erro r = null;
  489                  var pid =  ' R E D A CTED ;3';
  490                var resp onse = {
  491                    stat usCode: 20 2
  492                };
  493                var data  = 'data';
  494                var expe ctedRespon se = {
  495                    stat us: 202,
  496                    data : data
  497                };
  498                jdsSync. _syncStatu sResultPro cessor(pid , function (err, resp onse) {
  499                    expe ct(err).to .equal(err or);
  500                    expe ct(respons e).to.eql( expectedRe sponse);
  501                }, req,  error, res ponse, dat a);
  502           }) ;
  503           it ('should c reate a ge neric erro r message  if the res ponse is n ot handled ', functio n() {
  504                var erro r = new Er ror('could  not get U RL');
  505                  var pid =  ' R E D A CTED ;3';
  506                var resp onse = {
  507                    stat usCode: 50 9
  508                };
  509                var data  = 'data';
  510                var expe ctedRespon se = {
  511                    stat us: 500,
  512                    data : {
  513                         error: {
  514                             code:  500,
  515                             messag e: data
  516                         }
  517                    }
  518                };
  519                jdsSync. _syncStatu sResultPro cessor(pid , function (err, resp onse) {
  520                    expe ct(err).to .equal(err or);
  521                    expe ct(respons e).to.eql( expectedRe sponse);
  522                }, req,  error, res ponse, dat a);
  523           }) ;
  524       });
  525  
  526       functi on buildRe quest(defa ults) {
  527           va r request  = _.merge( httpMocks. createRequ est({
  528                method:  'GET',
  529                url: '/s ync'
  530           }) , defaults );
  531  
  532           re quest.logg er = {
  533                trace: d oLog.bind( null, 'tra ce'),
  534                debug: d oLog.bind( null, 'deb ug'),
  535                info: do Log.bind(n ull, 'info '),
  536                warn: do Log.bind(n ull, 'warn '),
  537                error: d oLog.bind( null, 'err or')
  538           };
  539  
  540           re quest.audi t = {};
  541  
  542           re quest.sess ion = {
  543                user: {
  544                      site: ' R E D A CTED '
  545                }
  546           };
  547  
  548           re quest.app  = {
  549                config:  {
  550                    jdsS erver: {
  551                         host: 'jds host',
  552                         port: 1
  553                    },
  554                    vxSy ncServer:  {
  555                         host: 'vxs ynchost',
  556                         port: 2
  557                    },
  558                    hmpS erver: {
  559                         host: 'hmp host',
  560                         port: 3,
  561                          accessCode : ' R E D A CTED ;500',
  562                          verifyCode : ' REDACTED ; REDACTED '
  563                    },
  564                    jdsS ync: {
  565                         settings:  {
  566                             timeou tMillis: 2 00,
  567                             waitMi llis: 80
  568                         }
  569                    },
  570                    vist aSites: {
  571                          ' R E D A CTED ': {},
  572                          ' REDA C TED ': {}
  573                    }
  574                },
  575                subsyste ms: {}
  576           };
  577  
  578           re quest.app. subsystems .jdsSync =  jdsSync;
  579  
  580           re turn reque st;
  581       }
  582  
  583       functi on doLog(l evel, stuf f) {
  584           lo g += level  + ': ' +  JSON.strin gify(stuff ) + '\n';
  585       }
  586  
  587       functi on stubHtt p(method,  httpConfig , callback ) {
  588           ht tpExpected .must.not. be.empty() ;
  589           va r expected  = httpExp ected.shif t();
  590  
  591           if  (expected .log) {
  592                expect(l og).to.eql (expected. log);
  593           }
  594           if  (expected .auditPati entId) {
  595                expect(r eq.audit.p atientId). to.equal(e xpected.au ditPatient Id);
  596           }
  597           if  (expected .content)  {
  598                expect(h ttpConfig. body).to.e ql(expecte d.content) ;
  599           }
  600  
  601           ex pect(metho d).to.equa l(expected .method);
  602           ex pect(httpC onfig.base Url).to.eq ual(req.ap p.config[e xpected.se rverName]. baseUrl);
  603           ex pect(httpC onfig.url) .to.equal( expected.u rl);
  604  
  605           if  (expected .response  && httpCon fig.json | | typeof(h ttpConfig. body) ===  'object')  {
  606                expected .response  = JSON.par se(expecte d.response );
  607           }
  608           ca llback(exp ected.erro r, {
  609                statusCo de: expect ed.status
  610           },  expected. response);
  611       }
  612  
  613       functi on expectH ttpFetch(s erverName,  path, sta tus, respo nse, error ) {
  614           va r expected  = {
  615                serverNa me: server Name,
  616                url: pat h,
  617                method:  'GET',
  618                status:  status ||  200,
  619                response : JSON.str ingify(res ponse || { }),
  620                error: e rror
  621           };
  622           ht tpExpected .push(expe cted);
  623           va r fluent =  {
  624                toAudit:  function( patientId)  {
  625                    expe cted.audit PatientId  = patientI d;
  626                    retu rn this;
  627                },
  628                toLog: f unction(me ssages) {
  629                    expe cted.log =  messages  || 'log';
  630                    retu rn this;
  631                }
  632           };
  633           fl uent.andAu dit = flue nt.toAudit ;
  634           fl uent.andLo g = fluent .toLog;
  635           re turn fluen t;
  636       }
  637  
  638       functi on expectS uccess(don e, status)  {
  639           va r callsbac k = 0;
  640           re turn funct ion(error,  result) {
  641                expect(e rror).to.b e.falsy();
  642                if (stat us) {
  643                    expe ct(result. status).to .equal(sta tus);
  644                } else i f (result  && result. status) {
  645                    expe ct(result. status).to .be.betwee n(200, 202 );
  646                }
  647                httpExpe cted.must. be.empty() ;
  648  
  649                callsbac k++;
  650                expect(c allsback). to.equal(1 );
  651                // allow  the check  for only  one invoca tion of ca llback:
  652                setImmed iate(done) ;
  653           };
  654       }
  655  
  656       functi on expectE rror(done,  status, m essage, er ror) {
  657           st atus = sta tus || 500 ;
  658           me ssage = me ssage || ' There was  an error p rocessing  your reque st. The er ror has be en logged. ';
  659           va r callsbac k = 0;
  660           re turn funct ion(err, r esult) {
  661                if (erro r) {
  662                    expe ct(err).to .eql(error );
  663                }
  664                if (resu lt.status)  {
  665                    expe ct(result. status).to .equal(sta tus);
  666                }
  667                var erro rObject =  result.err or || (res ult.data | | {}).erro r;
  668                if (erro rObject) {
  669                    expe ct(errorOb ject.code) .to.equal( status);
  670                    if ( message) {
  671                         expect(err orObject.m essage).to .equal(mes sage);
  672                    }
  673                }
  674                httpExpe cted.must. be.empty() ;
  675  
  676                callsbac k++;
  677                expect(c allsback). to.equal(1 );
  678                // allow  the check  for only  one invoca tion of ca llback:
  679                setImmed iate(done) ;
  680           };
  681       }
  682   });