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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | rdk.zip\rdk\product\production\rdk\src\utils | pjds-utility-spec.js | Mon Aug 28 19:41:48 2017 UTC |
| 2 | rdk.zip\rdk\product\production\rdk\src\utils | pjds-utility-spec.js | Tue Oct 3 18:46:14 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 31 | 1686 |
| Changed | 30 | 68 |
| 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 nock = require(' nock'); | |
| 5 | var httpMo cks = requ ire('node- mocks-http '); | |
| 6 | var pjdsUt il = requi re('./pjds -utility') ; | |
| 7 | var RdkErr or = requi re('./erro rs/rdk-err or'); | |
| 8 | var logger = sinon.s tub(requir e('bunyan' ).createLo gger({ | |
| 9 | name: 'pjds-util ity-spec' | |
| 10 | })); | |
| 11 | ||
| 12 | var trustU ser = { | |
| 13 | uid: ' CDS', | |
| 14 | name: 'CDS', | |
| 15 | permis sionSet: { | |
| 16 | ad ditionalPe rmissions: ['add-fri dge-sticke r'], | |
| 17 | va l: ['read- access'] | |
| 18 | }, | |
| 19 | status : 'active' , | |
| 20 | system Designator : 'externa l' | |
| 21 | }; | |
| 22 | var subjec tUser = { | |
| 23 | uid: 'urn: va:user: REDACTED :0007', | |
| 24 | permis sionSet: { | |
| 25 | ad ditionalPe rmissions: [ | |
| 26 | 'judo-ch op', | |
| 27 | 'can-yod el' | |
| 28 | ], | |
| 29 | modifiedBy : 'urn:va: user: REDACTED :0001', | |
| 30 | mo difiedOn: '2017-03-1 4T13:59:26 Z', | |
| 31 | va l: [ | |
| 32 | 'read-ac cess', | |
| 33 | 'sumo-wr estler', | |
| 34 | 'potty-t rained' | |
| 35 | ] | |
| 36 | }, | |
| 37 | status : 'active' | |
| 38 | }; | |
| 39 | var acting User = { | |
| 40 | uid: 'urn: va:user: REDACTED :0002', | |
| 41 | permis sionSet: { | |
| 42 | ad ditionalPe rmissions: [ | |
| 43 | 'judo-ch op', | |
| 44 | 'can-yod el' | |
| 45 | ], | |
| 46 | modifiedBy : 'urn:va: user: REDACTED :0001', | |
| 47 | mo difiedOn: '2017-03-1 4T13:59:26 Z', | |
| 48 | va l: [ | |
| 49 | 'read-ac cess', | |
| 50 | 'sumo-wr estler', | |
| 51 | 'yodel-d reams' | |
| 52 | ] | |
| 53 | }, | |
| 54 | status : 'active' | |
| 55 | }; | |
| 56 | var permis sionSets = { | |
| 57 | items: [{ | |
| 58 | 'u id': 'sumo -wrestler' , | |
| 59 | 'l abel': 'Su mo Wrestle r', | |
| 60 | 'p ermissions ': ['not-t o-be-trifl ed-with'], | |
| 61 | 's tatus': 'a ctive' | |
| 62 | }, { | |
| 63 | 'u id': 'read -access', | |
| 64 | 'l abel': 'Re ad Access' , | |
| 65 | 'p ermissions ': ['i-can -has-read' ], | |
| 66 | 's tatus': 'a ctive' | |
| 67 | }] | |
| 68 | }; | |
| 69 | var permis sions = { | |
| 70 | items: [{ | |
| 71 | 'u id': 'not- to-be-trif led-with', | |
| 72 | 'l abel': 'Se riously, d on\'t trif le', | |
| 73 | 's tatus': 'a ctive' | |
| 74 | }, { | |
| 75 | 'u id': 'i-ca n-has-read ', | |
| 76 | 'l abel': 'Pa ssed 1st g rade after 3rd try', | |
| 77 | 's tatus': 'a ctive' | |
| 78 | }, { | |
| 79 | 'u id': 'add- fridge-sti cker', | |
| 80 | 'l abel': 'Ce lebrate Po tty Time w ith Sticke rs!', | |
| 81 | 's tatus': 'a ctive' | |
| 82 | }, { | |
| 83 | 'u id': 'judo -chop', | |
| 84 | 'l abel': 'Ju do CHOP', | |
| 85 | 'd escription ': 'Downwa rd chop to the upwar d facing a ir', | |
| 86 | 's tatus': 'a ctive' | |
| 87 | }] | |
| 88 | }; | |
| 89 | var appCon fig = { | |
| 90 | 'gener alPurposeJ dsServer': { | |
| 91 | 'baseUrl': 'http:// IP ', | |
| 92 | 'u rlLengthLi mit': 120 | |
| 93 | } | |
| 94 | }; | |
| 95 | describe(' pjds-utili ty', funct ion () { | |
| 96 | var re q; | |
| 97 | var re s; | |
| 98 | before Each(funct ion () { | |
| 99 | re q = {}; | |
| 100 | re q.logger = logger; | |
| 101 | re s = httpMo cks.create Response({ req: req}) ; | |
| 102 | re s.status = function( statusCode ) { | |
| 103 | this.sta tusCode = statusCode ; | |
| 104 | return t his; | |
| 105 | }; | |
| 106 | re s.rdkSend = function (){}; | |
| 107 | }); | |
| 108 | afterE ach(functi on () { | |
| 109 | no ck.cleanAl l(); | |
| 110 | }); | |
| 111 | descri be('.getRe questParam eter', fun ction () { | |
| 112 | de scribe('ca n access b y string p ath', func tion () { | |
| 113 | var obj; | |
| 114 | beforeEa ch(functio n(){ | |
| 115 | obj = { | |
| 116 | filter: 'e q(status,a ctive)', | |
| 117 | user: subj ectUser | |
| 118 | }; | |
| 119 | }); | |
| 120 | ||
| 121 | describe ('query pa rameters', function () { | |
| 122 | it(' returns a default if no proper ty is foun d', functi on(){ | |
| 123 | _.set(req, 'query.fi lter', obj .filter); | |
| 124 | //look in the wrong path | |
| 125 | var param = pjdsUtil .getReques tParameter (req, 'wro ng.path', 'not true' ); | |
| 126 | expect(par am).to.be. equal('not true'); | |
| 127 | expect(par am).to.not .be.equal( obj.filter ); | |
| 128 | }); | |
| 129 | it(' returns pr operly if property f ound by pa th', funct ion(){ | |
| 130 | _.set(req, 'query.fi lter', obj .filter); | |
| 131 | var param = pjdsUtil .getReques tParameter (req, 'fil ter', 'not true'); | |
| 132 | expect(par am).to.not .be.equal( 'not true' ); | |
| 133 | expect(par am).to.be. equal(obj. filter); | |
| 134 | }); | |
| 135 | }); | |
| 136 | ||
| 137 | describe ('body par ameters', function ( ) { | |
| 138 | it(' returns a default if no proper ty is foun d', functi on(){ | |
| 139 | _.set(req, 'body', o bj); | |
| 140 | //look in the wrong path | |
| 141 | var param = pjdsUtil .getReques tParameter (req, 'wro ng.path', 'not true' ); | |
| 142 | expect(par am).to.be. equal('not true'); | |
| 143 | expect(obj ).to.not.c ontain(par am); | |
| 144 | }); | |
| 145 | ||
| 146 | it(' returns pr operly if property f ound by pa th', funct ion(){ | |
| 147 | _.set(req, 'body', o bj); | |
| 148 | var param = pjdsUtil .getReques tParameter (req, 'fil ter', null ); | |
| 149 | expect(par am, 'The f ilter shou ld be equa l').to.be. equal(obj. filter); | |
| 150 | ||
| 151 | param = pj dsUtil.get RequestPar ameter(req , 'user.ui d', null); | |
| 152 | expect(par am, 'The o bject item s should b e equal'). to.be.equa l(obj.user .uid); | |
| 153 | ||
| 154 | param = pj dsUtil.get RequestPar ameter(req , 'user.pe rmissionSe t.val', nu ll); | |
| 155 | expect(par am, 'The o bject item s should b e equal'). to.be.a.pe rmutationO f(obj.user .permissio nSet.val); | |
| 156 | }); | |
| 157 | }); | |
| 158 | ||
| 159 | describe ('request parameters ', functio n () { | |
| 160 | it(' returns a default if no proper ty is foun d', functi on(){ | |
| 161 | _.set(req, 'params', obj); | |
| 162 | //look in the wrong path | |
| 163 | var param = pjdsUtil .getReques tParameter (req, 'wro ng.path', 'not true' ); | |
| 164 | expect(par am).to.be. equal('not true'); | |
| 165 | expect(par am).to.not .be.equal( obj); | |
| 166 | }); | |
| 167 | it(' returns pr operly if property f ound by pa th', funct ion(){ | |
| 168 | _.set(req, 'params.f ilter', ob j.filter); | |
| 169 | var param = pjdsUtil .getReques tParameter (req, 'fil ter', 'not true'); | |
| 170 | expect(par am).to.not .be.equal( 'not true' ); | |
| 171 | expect(par am).to.be. equal(obj. filter); | |
| 172 | }); | |
| 173 | }); | |
| 174 | }) ; | |
| 175 | de scribe('ca n access b y array pa th', funct ion () { | |
| 176 | var obj; | |
| 177 | beforeEa ch(functio n () { | |
| 178 | obj = { | |
| 179 | filter: 'e q(status,a ctive)', | |
| 180 | user: subj ectUser | |
| 181 | }; | |
| 182 | }); | |
| 183 | ||
| 184 | describe ('query pa rameters', function () { | |
| 185 | it(' returns a default if no proper ty is foun d', functi on(){ | |
| 186 | _.set(req, 'query.fi lter', obj .filter); | |
| 187 | //look in the wrong path | |
| 188 | var param = pjdsUtil .getReques tParameter (req, ['wr ong', 'pat h'], 'not true'); | |
| 189 | expect(par am).to.be. equal('not true'); | |
| 190 | expect(par am).to.not .be.equal( obj.filter ); | |
| 191 | }); | |
| 192 | it(' returns pr operly if property f ound by pa th', funct ion(){ | |
| 193 | _.set(req, 'query.fi lter', obj .filter); | |
| 194 | var param = pjdsUtil .getReques tParameter (req, ['fi lter'], 'n ot true'); | |
| 195 | expect(par am).to.not .be.equal( 'not true' ); | |
| 196 | expect(par am).to.be. equal(obj. filter); | |
| 197 | }); | |
| 198 | }); | |
| 199 | ||
| 200 | describe ('body par ameters', function ( ) { | |
| 201 | it(' returns a default if no proper ty is foun d', functi on(){ | |
| 202 | _.set(req, 'body', o bj); | |
| 203 | //look in the wrong path | |
| 204 | var param = pjdsUtil .getReques tParameter (req, ['wr ong', 'pat h'], 'not true'); | |
| 205 | expect(par am).to.be. equal('not true'); | |
| 206 | expect(obj ).to.not.c ontain(par am); | |
| 207 | }); | |
| 208 | ||
| 209 | it(' returns pr operly if property f ound by pa th', funct ion(){ | |
| 210 | _.set(req, 'body', o bj); | |
| 211 | var param = pjdsUtil .getReques tParameter (req, ['fi lter'], nu ll); | |
| 212 | expect(par am, 'The f ilter shou ld be equa l').to.be. equal(obj. filter); | |
| 213 | ||
| 214 | param = pj dsUtil.get RequestPar ameter(req , ['user', 'uid'], n ull); | |
| 215 | expect(par am, 'The o bject item s should b e equal'). to.be.equa l(obj.user .uid); | |
| 216 | ||
| 217 | param = pj dsUtil.get RequestPar ameter(req , ['user', 'permissi onSet', 'v al'], null ); | |
| 218 | expect(par am, 'The o bject item s should b e equal'). to.be.a.pe rmutationO f(obj.user .permissio nSet.val); | |
| 219 | }); | |
| 220 | }); | |
| 221 | ||
| 222 | describe ('request parameters ', functio n () { | |
| 223 | it(' returns a default if no proper ty is foun d', functi on(){ | |
| 224 | _.set(req, 'params', obj); | |
| 225 | //look in the wrong path | |
| 226 | var param = pjdsUtil .getReques tParameter (req, 'wro ng.path', 'not true' ); | |
| 227 | expect(par am).to.be. equal('not true'); | |
| 228 | expect(par am).to.not .be.equal( obj); | |
| 229 | }); | |
| 230 | it(' returns pr operly if property f ound by pa th', funct ion(){ | |
| 231 | _.set(req, 'params.f ilter', ob j.filter); | |
| 232 | var param = pjdsUtil .getReques tParameter (req, ['fi lter'], 'n ot true'); | |
| 233 | expect(par am).to.not .be.equal( 'not true' ); | |
| 234 | expect(par am).to.be. equal(obj. filter); | |
| 235 | }); | |
| 236 | }); | |
| 237 | }) ; | |
| 238 | }); | |
| 239 | descri be('.filte rArrayByUi d', functi on () { | |
| 240 | de scribe('se nds back t he source' , function () { | |
| 241 | var sour ceArray = []; | |
| 242 | var filt erArray = []; | |
| 243 | var resu ltArray = []; | |
| 244 | beforeEa ch(functio n(){ | |
| 245 | sour ceArray = subjectUse r.permissi onSet.val; | |
| 246 | filt erArray = permission Sets.items ; | |
| 247 | }); | |
| 248 | afterEac h(function (){ | |
| 249 | resu ltArray = []; | |
| 250 | }); | |
| 251 | it('with out error if there i s no sourc e', functi on() { | |
| 252 | var finalArray = pjdsUti l.filterAr rayByUid(u ndefined, filterArra y); | |
| 253 | //re sult shoul d be no ch ange | |
| 254 | resu ltArray = undefined; | |
| 255 | expe ct(finalAr ray).to.be .equal(res ultArray); | |
| 256 | }); | |
| 257 | it('with out modifi cation whe n there is no filter ', functio n() { | |
| 258 | var finalArray = pjdsUti l.filterAr rayByUid(s ourceArray , []); | |
| 259 | //re sult shoul d be no ch ange | |
| 260 | resu ltArray = subjectUse r.permissi onSet.val; | |
| 261 | expe ct(finalAr ray).to.be .a.permuta tionOf(res ultArray); | |
| 262 | }); | |
| 263 | it('modi fied by th e filtered array', f unction(){ | |
| 264 | var finalArray = pjdsUti l.filterAr rayByUid(s ourceArray , filterAr ray); | |
| 265 | resu ltArray = ['read-acc ess', 'sum o-wrestler ']; | |
| 266 | expe ct(finalAr ray).to.be .a.permuta tionOf(res ultArray); | |
| 267 | }); | |
| 268 | }) ; | |
| 269 | }); | |
| 270 | descri be('.actin gUserFromR equest', f unction () { | |
| 271 | de scribe('re turns the session us er object' , function () { | |
| 272 | it('as a n empty ob ject when no session is found on the req uest', fun ction(){ | |
| 273 | var user = pjd sUtil.acti ngUserFrom Request(re q); | |
| 274 | expe ct(user).t o.be.an.ob ject(); | |
| 275 | expe ct(user).t o.be.empty (); | |
| 276 | }); | |
| 277 | it('as a user ojec t when a s ession is found on t he request ', functio n(){ | |
| 278 | _.se t(req, 'se ssion.user ', subject User); | |
| 279 | var user = pjd sUtil.acti ngUserFrom Request(re q); | |
| 280 | expe ct(user).t o.be.an.ob ject(); | |
| 281 | expe ct(user).t o.be(subje ctUser); | |
| 282 | }); | |
| 283 | }) ; | |
| 284 | }); | |
| 285 | descri be('.isUse rModifying Self', fun ction () { | |
| 286 | be foreEach(f unction(){ | |
| 287 | _.set(re q, 'sessio n.user', a ctingUser) ; | |
| 288 | }) ; | |
| 289 | de scribe('re turns true if the ac ting user does not h ave "edit- own-permis sions" and ', functio n () { | |
| 290 | it('the method det ermines th e acting a nd subject user uids match', f unction(){ | |
| 291 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, actingUse r); | |
| 292 | expe ct(isModif ingSelf).t o.be.true( ); | |
| 293 | }); | |
| 294 | it('the method was not passe d a subjec t user uid , but one exists on the reques t and it i s the acti ngUser', f unction () { | |
| 295 | _.se t(req, 'bo dy.user', actingUser ); | |
| 296 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, undefined ); | |
| 297 | expe ct(isModif ingSelf).t o.be.true( ); | |
| 298 | }); | |
| 299 | }) ; | |
| 300 | ||
| 301 | de scribe('re turns fals e if', fun ction () { | |
| 302 | it('the method det ermines th e acting a nd subject user uids match AND the actin g user doe s have "ed it-own-per missions"' , function (){ | |
| 303 | _.se t(req, 'se ssion.user .permissio ns', []); //permissi ons are al ways set d uring logi n or retri eving the user info | |
| 304 | req. session.us er.permiss ions.push( 'edit-own- permission s'); | |
| 305 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, actingUse r); | |
| 306 | expe ct(isModif ingSelf).t o.be.false (); | |
| 307 | }); | |
| 308 | it('the method was not passe d a subjec t user, bu t a non-ma tching use r exists o n the requ est', func tion (){ | |
| 309 | _.se t(req, 'bo dy.user', subjectUse r); | |
| 310 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, undefined ); | |
| 311 | expe ct(isModif ingSelf).t o.be.false (); | |
| 312 | }); | |
| 313 | it('the method can not deter mine an ac ting user uid', func tion (){ | |
| 314 | _.se t(req, 'se ssion.user .uid', '') ; | |
| 315 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, subjectUs er); | |
| 316 | expe ct(isModif ingSelf).t o.be.false (); | |
| 317 | }); | |
| 318 | it('the method can not deter mine a sub ject user uid', func tion (){ | |
| 319 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, {'uid': u ndefined}) ; | |
| 320 | expe ct(isModif ingSelf).t o.be.false (); | |
| 321 | }); | |
| 322 | }) ; | |
| 323 | ||
| 324 | de scribe('re turns erro r if', fun ction () { | |
| 325 | it('the method can not find a subject user being passed in nor on th e request' , function () { | |
| 326 | _.se t(req, 'bo dy.user', undefined) ; | |
| 327 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, undefined ); | |
| 328 | expe ct(isModif ingSelf, ' The return ed item sh ould be an RdkError with a cod e').to.hav e.property ('code'); | |
| 329 | expe ct(_.get(i sModifingS elf, 'code ')).to.mat ch(/200.40 0.1026/); | |
| 330 | }); | |
| 331 | it('the method can not find a subject user\'s ui d being pa ssed in no r on the t he request ', functio n() { | |
| 332 | _.se t(req, 'bo dy.user', _.omit(sub jectUser, 'uid')); | |
| 333 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, undefined ); | |
| 334 | expe ct(isModif ingSelf, ' The return ed item sh ould be an RdkError with a cod e').to.hav e.property ('code'); | |
| 335 | expe ct(_.get(i sModifingS elf, 'code ')).to.mat ch(/200.40 0.1025/); | |
| 336 | }); | |
| 337 | it('the method can not parse the subje ct user it found', f unction() { | |
| 338 | _.set(req, 'body.use r', '{uid: "urn:va:u ser: REDACTED :0007"'); | |
| 339 | var isModifing Self = pjd sUtil.isUs erModifyin gSelf(req, undefined ); | |
| 340 | expe ct(isModif ingSelf, ' The return ed item sh ould be an RdkError with a cod e').to.hav e.property ('code'); | |
| 341 | expe ct(_.get(i sModifingS elf, 'code ')).to.mat ch(/200.40 0.1021/); | |
| 342 | }); | |
| 343 | }) ; | |
| 344 | }); | |
| 345 | descri be('.permi ssionSetFr omRequest' , function () { | |
| 346 | de scribe('me thod attem pts to get `permissi onSets` fr om the req uest and', function () { | |
| 347 | it('retu rns the pe rmission s ets from t he request object', function ( ) { | |
| 348 | _.se t(req, 'pe rmissionSe ts', permi ssionSets. items); | |
| 349 | var requestPer mSet = pjd sUtil.perm issionSetF romRequest (req); | |
| 350 | expe ct(request PermSet).t o.be.an.ob ject(); | |
| 351 | }); | |
| 352 | describe ('returns an error i f', functi on () { | |
| 353 | it(' the permis sionSet st ring canno t be parse d', functi on(){ | |
| 354 | _.set(req, 'body.per missionSet s', '[{uid : "sudo-wr estler", l abel:"Sumo Wrestler" }'); | |
| 355 | var reques tPermSet = pjdsUtil. permission SetFromReq uest(req); | |
| 356 | expect(req uestPermSe t, 'The re turned ite m should b e an RdkEr ror with a code').to .have.prop erty('code '); | |
| 357 | expect(_.g et(request PermSet, ' code')).to .match(/20 0.400.1021 /); | |
| 358 | }); | |
| 359 | it(' the permis sionSet ar ray is und efined', f unction(){ | |
| 360 | var reques tPermSet = pjdsUtil. permission SetFromReq uest(req); | |
| 361 | expect(req uestPermSe t, 'The re turned ite m should b e an RdkEr ror with a code').to .have.prop erty('code '); | |
| 362 | expect(_.g et(request PermSet, ' code')).to .match(/20 0.400.1020 /); | |
| 363 | }); | |
| 364 | }); | |
| 365 | }) ; | |
| 366 | }); | |
| 367 | descri be('.addit ionalPermi ssionsFrom Request', function() { | |
| 368 | de scribe('me thod attem pts to get `addition alPermissi ons` from the reques t and', fu nction () { | |
| 369 | it('retu rns the pe rmission s ets from t he request object', function ( ) { | |
| 370 | _.se t(req, 'bo dy.additio nalPermiss ions', per missions.i tems); | |
| 371 | var requestPer missions = pjdsUtil. additional Permission sFromReque st(req); | |
| 372 | expe ct(request Permission s).to.be.a n.object() ; | |
| 373 | }); | |
| 374 | describe ('returns an error i f', functi on () { | |
| 375 | it(' the permis sions stri ng cannot be parsed' , function (){ | |
| 376 | _.set(req, 'body.add itionalPer missions', '{uid:not -to-be-tri fled-with" ,label: "S eriously, don\'t tri fle",statu s: "active "}, {ui'); | |
| 377 | var reques tPermissio ns = pjdsU til.additi onalPermis sionsFromR equest(req ); | |
| 378 | expect(req uestPermis sions, 'Th e returned item shou ld be an R dkError wi th a code' ).to.have. property(' code'); | |
| 379 | expect(_.g et(request Permission s, 'code') ).to.match (/200.400. 1021/); | |
| 380 | }); | |
| 381 | }); | |
| 382 | }) ; | |
| 383 | ||
| 384 | }); | |
| 385 | descri be('.subje ctuserFrom Request', function ( ) { | |
| 386 | de scribe('re turns user if', func tion(){ | |
| 387 | it('the method fin ds a "user " on the r equest obj ect', func tion(){ | |
| 388 | _.se t(req, 'bo dy.user', subjectUse r); | |
| 389 | var isModifing Self = pjd sUtil.subj ectUserFro mRequest(r eq); | |
| 390 | expe ct(isModif ingSelf, ' An object representi ng the sub ject user should be returned') .to.be.an. object(); | |
| 391 | }); | |
| 392 | }) ; | |
| 393 | de scribe('re turns erro r if', fun ction () { | |
| 394 | it('the method can not find a subject user on th e request' , function () { | |
| 395 | var isModifing Self = pjd sUtil.subj ectUserFro mRequest(r eq); | |
| 396 | expe ct(isModif ingSelf, ' The return ed item sh ould be an RdkError with a cod e').to.hav e.property ('code'); | |
| 397 | expe ct(_.get(i sModifingS elf, 'code ')).to.mat ch(/200.40 0.1026/); | |
| 398 | }); | |
| 399 | it('the method can not find a subject user\'s ui d on the r equest', f unction() { | |
| 400 | _.se t(req, 'bo dy.user', _.omit(sub jectUser, 'uid')); | |
| 401 | var isModifing Self = pjd sUtil.subj ectUserFro mRequest(r eq); | |
| 402 | expe ct(isModif ingSelf, ' The return ed item sh ould be an RdkError with a cod e').to.hav e.property ('code'); | |
| 403 | expe ct(_.get(i sModifingS elf, 'code ')).to.mat ch(/200.40 0.1025/); | |
| 404 | }); | |
| 405 | it('the method can not parse the subje ct user', function() { | |
| 406 | _.set(req, 'body.use r', '{uid: "urn:va:u ser: REDACTED :0007"'); | |
| 407 | var isModifing Self = pjd sUtil.subj ectUserFro mRequest(r eq); | |
| 408 | expe ct(isModif ingSelf, ' The return ed item sh ould be an RdkError with a cod e').to.hav e.property ('code'); | |
| 409 | expe ct(_.get(i sModifingS elf, 'code ')).to.mat ch(/200.40 0.1021/); | |
| 410 | }); | |
| 411 | }) ; | |
| 412 | }); | |
| 413 | descri be('.gathe rUniquePer missions', function () { | |
| 414 | de scribe('re turns a li st of perm issions if ', functio n () { | |
| 415 | it('a us er, permis sionSet an d permissi on is sent properly' , function () { | |
| 416 | var permission sToReturn = pjdsUtil .gatherUni quePermiss ions(actin gUser, per missionSet s.items, p ermissions .items); | |
| 417 | //no tice can-y odel was r emoved fro m the list as it is not in the permissio ns list | |
| 418 | expe ct(permiss ionsToRetu rn).to.be. permutatio nOf(['judo -chop','no t-to-be-tr ifled-with ','i-can-h as-read']) ; | |
| 419 | }); | |
| 420 | }) ; | |
| 421 | de scribe('re turns noth ing if', f unction () { | |
| 422 | it('a us er isn\'t set or has no permis sion sets and permis sions', fu nction () { | |
| 423 | var permission sToReturn = pjdsUtil .gatherUni quePermiss ions(undef ined, perm issionSets .items, pe rmissions. items); | |
| 424 | expe ct(permiss ionsToRetu rn).to.be. empty(); | |
| 425 | }); | |
| 426 | it('the permission s filter a rray is em pty', func tion () { | |
| 427 | var permission sToReturn = pjdsUtil .gatherUni quePermiss ions(actin gUser, per missionSet s.items, u ndefined); | |
| 428 | expe ct(permiss ionsToRetu rn).to.be. empty(); | |
| 429 | }); | |
| 430 | }) ; | |
| 431 | }); | |
| 432 | descri be('.getPe rmissionSe t', functi on () { | |
| 433 | be foreEach(f unction () { | |
| 434 | req.logg er = logge r; | |
| 435 | _.set(re q, 'app.co nfig', app Config); | |
| 436 | }) ; | |
| 437 | de scribe('re turns perm ission set s if', fun ction () { | |
| 438 | it('the requested sets are a vailable f rom pjds', function (done) { | |
| 439 | var cb = funct ion(err, r esponse, r eq, pjdsOp tions) { | |
| 440 | expect(err , 'There s hould not be an erro r').to.be. null(); | |
| 441 | expect(_.s ize(_.get( response, 'data.item s')), 'Thi s test has two permi ssion sets and expec ts to see them both' ).to.be(2) ; | |
| 442 | expect(pjd sOptions, 'DE6491 re quires tha t users ha ve only ac tive permi ssion sets applied t o them').t o.have.own Property(' filterList '); | |
| 443 | expect(pjd sOptions.f ilterList, 'DE6491 r equired th at an acti ve filter be made on permissio n sets wit h the opti on to chan ge the fil ter sent t o pjds').t o.match(/( eq)(.*?)(s tatus)(.*? )(active)/ ); | |
| 444 | done(); | |
| 445 | }; | |
| 446 | ||
| 447 | nock('http :// IP ') | |
| 448 | .get('/per mset/?filt er=eq(%22s tatus%22%2 C%22active %22)') | |
| 449 | .reply(200 , permissi onSets); | |
| 450 | ||
| 451 | pjds Util.getPe rmissionSe t(req, {}, cb); | |
| 452 | }); | |
| 453 | it('the requested sets are a vailable f rom pjds w hen a filt er is sent to overri de the act ive status default f ilter', fu nction (do ne) { | |
| 454 | var pjdsOption s = { | |
| 455 | filterList : 'or(eq(s tatus,acti ve),eq(sta tus,deprec ated))' | |
| 456 | }; | |
| 457 | var cb = funct ion(err, r esponse, r eq, pjdsOp tions) { | |
| 458 | expect(err , 'There s hould not be an erro r').to.be. null(); | |
| 459 | expect(_.s ize(_.get( response, 'data.item s')), 'Thi s test has two permi ssion sets and expec ts to see them both' ).to.be(2) ; | |
| 460 | expect(pjd sOptions, 'DE6491 re quires tha t users ha ve only ac tive permi ssion sets applied t o them').t o.have.own Property(' filterList '); | |
| 461 | expect(pjd sOptions.f ilterList, 'DE6491 r equired th at an acti ve filter be made on permissio n sets wit h the opti on to chan ge the fil ter sent t o pjds').t o.match(/( eq)(.*?)(s tatus)(.*? )(active)( .*?)(eq)(. *?)(status )(.*?)(dep recated)/) ; | |
| 462 | done(); | |
| 463 | }; | |
| 464 | ||
| 465 | nock('http :// IP ') | |
| 466 | .get('/per mset/?filt er=or(eq(% 22status%2 2%2C%22act ive%22)%2C eq(%22stat us%22%2C%2 2deprecate d%22))') | |
| 467 | .reply(200 , permissi onSets); | |
| 468 | ||
| 469 | pjds Util.getPe rmissionSe t(req, pjd sOptions, cb); | |
| 470 | }); | |
| 471 | }) ; | |
| 472 | de scribe('re turns an e rror if', function ( ) { | |
| 473 | it('the request to pjds retu rns an err or', funct ion (done) { | |
| 474 | var errorToRet urn = 'Nop e not this time'; | |
| 475 | var cb = funct ion(err, r esponse, r eq, pjdsOp tions) { | |
| 476 | expect(err ).to.have. ownPropert y('code'); | |
| 477 | expect(err ).to.have. ownPropert y('status' ); | |
| 478 | expect(res ponse, 'Th ere will a lways be s ome sorta object sen t back in the respon se from pj ds-store.g et').to.ex ist(); | |
| 479 | expect(pjd sOptions, 'DE6491 re quires tha t users ha ve only ac tive permi ssion sets applied t o them').t o.have.own Property(' filterList '); | |
| 480 | expect(pjd sOptions.f ilterList, 'DE6491 r equired th at an acti ve filter be made on permissio n sets wit h the opti on to chan ge the fil ter sent t o pjds').t o.match(/( eq)(.*?)(s tatus)(.*? )(active)/ ); | |
| 481 | done(); | |
| 482 | }; | |
| 483 | ||
| 484 | nock('http :// IP ') | |
| 485 | .get('/per mset/?filt er=eq(%22s tatus%22%2 C%22active %22)') | |
| 486 | .reply(404 , errorToR eturn); | |
| 487 | ||
| 488 | pjds Util.getPe rmissionSe t(req, {}, cb); | |
| 489 | }); | |
| 490 | }) ; | |
| 491 | }); | |
| 492 | descri be('.getPe rmissions' , function () { | |
| 493 | be foreEach(f unction () { | |
| 494 | req.logg er = logge r; | |
| 495 | _.set(re q, 'app.co nfig', app Config); | |
| 496 | }) ; | |
| 497 | de scribe('re turns perm issions if ', functio n () { | |
| 498 | it('the requested permission s are avai lable from pjds', fu nction (do ne) { | |
| 499 | var cb = funct ion(err, r esponse, r eq, pjdsOp tions) { | |
| 500 | expect(err , 'There s hould not be an erro r').to.be. null(); | |
| 501 | expect(_.s ize(_.get( response, 'data.item s')), 'Thi s test has four perm issions an d expects to see the m all').to .be(4); | |
| 502 | expect(pjd sOptions, 'DE6491 re quires tha t users ha ve only ac tive permi ssions app lied to th em').to.ha ve.ownProp erty('filt erList'); | |
| 503 | expect(pjd sOptions.f ilterList, 'DE6491 r equired th at an acti ve filter be made on permissio ns with th e option t o change t he filter sent to pj ds').to.ma tch(/(eq)( .*?)(statu s)(.*?)(ac tive)/); | |
| 504 | done(); | |
| 505 | }; | |
| 506 | ||
| 507 | nock('http :// IP ') | |
| 508 | .get('/per mission/?f ilter=eq(% 22status%2 2%2C%22act ive%22)') | |
| 509 | .reply(200 , permissi ons); | |
| 510 | ||
| 511 | pjds Util.getPe rmissions( req, {}, c b); | |
| 512 | }); | |
| 513 | it('the requested permission s are avai lable from pjds when a filter is sent to override the active status de fault filt er', funct ion (done) { | |
| 514 | var pjdsOption s = { | |
| 515 | filterList : 'or(eq(s tatus,acti ve),eq(sta tus,deprec ated))' | |
| 516 | }; | |
| 517 | var cb = funct ion(err, r esponse, r eq, pjdsOp tions) { | |
| 518 | expect(err , 'There s hould not be an erro r').to.be. null(); | |
| 519 | expect(_.s ize(_.get( response, 'data.item s')), 'Thi s test has four perm issions an d expects to see the m all').to .be(4); | |
| 520 | expect(pjd sOptions, 'DE6491 re quires tha t users ha ve only ac tive permi ssions app lied to th em').to.ha ve.ownProp erty('filt erList'); | |
| 521 | expect(pjd sOptions.f ilterList, 'DE6491 r equired th at an acti ve filter be made on permissio ns with th e option t o change t he filter sent to pj ds').to.ma tch(/(eq)( .*?)(statu s)(.*?)(ac tive)(.*?) (eq)(.*?)( status)(.* ?)(depreca ted)/); | |
| 522 | done(); | |
| 523 | }; | |
| 524 | ||
| 525 | nock('http :// IP ') | |
| 526 | .get('/per mission/?f ilter=or(e q(%22statu s%22%2C%22 active%22) %2Ceq(%22s tatus%22%2 C%22deprec ated%22))' ) | |
| 527 | .reply(200 , permissi ons); | |
| 528 | ||
| 529 | pjds Util.getPe rmissions( req, pjdsO ptions, cb ); | |
| 530 | }); | |
| 531 | }) ; | |
| 532 | de scribe('re turns an e rror if', function ( ) { | |
| 533 | it('the request to pjds retu rns an err or', funct ion (done) { | |
| 534 | var errorToRet urn = 'Nop e not this time'; | |
| 535 | var cb = funct ion (err, response, req, pjdsO ptions) { | |
| 536 | expect(err ).to.have. ownPropert y('code'); | |
| 537 | expect(err ).to.have. ownPropert y('status' ); | |
| 538 | expect(res ponse, 'Th ere will a lways be s ome sorta object sen t back in the respon se from pj ds-store.g et').to.ex ist(); | |
| 539 | expect(pjd sOptions, 'DE6491 re quires tha t users ha ve only ac tive permi ssions app lied to th em').to.ha ve.ownProp erty('filt erList'); | |
| 540 | expect(pjd sOptions.f ilterList, 'DE6491 r equired th at an acti ve filter be made on permissio ns with th e option t o change t he filter sent to pj ds').to.ma tch(/(eq)( .*?)(statu s)(.*?)(ac tive)/); | |
| 541 | done(); | |
| 542 | }; | |
| 543 | ||
| 544 | nock('http :// IP ') | |
| 545 | .get('/per mission/?f ilter=eq(% 22status%2 2%2C%22act ive%22)') | |
| 546 | .reply(404 , errorToR eturn); | |
| 547 | ||
| 548 | pjds Util.getPe rmissions( req, {}, c b); | |
| 549 | }); | |
| 550 | }) ; | |
| 551 | }); | |
| 552 | descri be('.getUs er', funct ion () { | |
| 553 | be foreEach(f unction () { | |
| 554 | _.set(re q, 'app.co nfig', app Config); | |
| 555 | }) ; | |
| 556 | de scribe('re turns an o bject from pjds if', function () { | |
| 557 | it('a ke y is provi ded', func tion (done ) { | |
| 558 | var pjdsOption s = { | |
| 559 | key: subje ctUser.uid | |
| 560 | }; | |
| 561 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 562 | expect(err or, 'The e rror shoul d be null' ).to.be.nu ll(); | |
| 563 | expect(_.g et(respons e, 'data') , 'The tes t response data shou ld have so me keys'). to.have.ke ys(['uid', 'permissi onSet', 's tatus']); | |
| 564 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 565 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have de faulted to ehmpusers ').to.matc h(/ehmpuse rs/); | |
| 566 | done(); | |
| 567 | }; | |
| 568 | ||
| 569 | nock('http :// IP ') | |
| 570 | .get('/ehm pusers/urn :va:user: REDACTED :0007') | |
| 571 | .reply(200 , subjectU ser); | |
| 572 | ||
| 573 | pjds Util.getUs er(req, re s, pjdsOpt ions, cb); | |
| 574 | }); | |
| 575 | it('a ke y and the trustsys s tore is pr ovided', f unction (d one) { | |
| 576 | var pjdsOption s = { | |
| 577 | key: trust User.uid, | |
| 578 | store: 'tr ustsys' // overriding the defau lt store | |
| 579 | }; | |
| 580 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 581 | expect(err or).to.be. null(); | |
| 582 | expect(_.g et(respons e, 'data') , 'The tes t response data shou ld have so me keys'). to.have.ke ys(['uid', 'name', ' permission Set', 'sta tus', 'sys temDesigna tor']); | |
| 583 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 584 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have pr operly cha nged to tr ustsys').t o.match(/t rustsys/); | |
| 585 | done(); | |
| 586 | }; | |
| 587 | ||
| 588 | nock('http :// IP ') | |
| 589 | .get('/tru stsys/CDS' ) | |
| 590 | .reply(200 , trustUse r); | |
| 591 | ||
| 592 | pjds Util.getUs er(req, re s, pjdsOpt ions, cb); | |
| 593 | }); | |
| 594 | }) ; | |
| 595 | de scribe('re turns an e rror if', function ( ) { | |
| 596 | it('no k ey is prov ided in th e pJDSOpti ons', func tion (done ) { | |
| 597 | var pjdsOption s = {}; | |
| 598 | var cb = funct ion() {}; | |
| 599 | res. rdkSend = function ( data) { | |
| 600 | expect(dat a).to.have .ownProper ty('code') ; | |
| 601 | expect(dat a.code).to .match(/20 0.400.1024 /); | |
| 602 | done(); | |
| 603 | }; | |
| 604 | ||
| 605 | pjds Util.getUs er(req, re s, pjdsOpt ions, cb); | |
| 606 | }); | |
| 607 | it('pjds sends bac k an error ', functio n (done) { | |
| 608 | var pjdsOption s = { | |
| 609 | key: subje ctUser.uid | |
| 610 | }; | |
| 611 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 612 | expect(res ponse.stat usCode).to .be(404); | |
| 613 | expect(err or).to.be. instanceOf (RdkError) ; | |
| 614 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 615 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have pr operly cha nged to eh mpusers'). to.match(/ ehmpusers/ ); | |
| 616 | done(); | |
| 617 | }; | |
| 618 | ||
| 619 | nock('http :// IP ') | |
| 620 | .get('/ehm pusers/urn :va:user: REDACTED :0007') | |
| 621 | .reply(404 , new Erro r('Pft, yo u thought wrong')); | |
| 622 | ||
| 623 | pjds Util.getUs er(req, re s, pjdsOpt ions, cb); | |
| 624 | }); | |
| 625 | }) ; | |
| 626 | }); | |
| 627 | descri be('.getUs erWithFilt eredPermis sions', fu nction () { | |
| 628 | be foreEach(f unction () { | |
| 629 | _.set(re q, 'app.co nfig', app Config); | |
| 630 | ||
| 631 | nock('http :// IP ') | |
| 632 | .get ('/permset /?filter=e q(%22statu s%22%2C%22 active%22) ') | |
| 633 | .rep ly(200, pe rmissionSe ts); | |
| 634 | nock('http :// IP ') | |
| 635 | .get ('/permiss ion/?filte r=eq(%22st atus%22%2C %22active% 22)') | |
| 636 | .rep ly(200, pe rmissions) ; | |
| 637 | }) ; | |
| 638 | de scribe('re turns an o bject from pjds if', function () { | |
| 639 | it('a ke y is provi ded', func tion (done ) { | |
| 640 | var pjdsOption s = { | |
| 641 | user: { | |
| 642 | uid: s ubjectUser .uid, | |
| 643 | store: 'ehmpuser s' | |
| 644 | } | |
| 645 | }; | |
| 646 | var cb = funct ion(error, response) { | |
| 647 | expect(err or, 'The e rror shoul d be null' ).to.be.nu ll(); | |
| 648 | expect(res ponse, 'Th e test res ponse data should ha ve some ke ys').to.ha ve.keys([' uid', 'per missionSet ', 'permis sionSets', 'permissi ons', 'sta tus', 'cre atedBy', ' createdTim e', 'lastS uccessfulL ogin','las tUnsuccess fulLogin', 'unsuccess fulLoginAt temptCount ']); | |
| 649 | done(); | |
| 650 | }; | |
| 651 | ||
| 652 | nock('http :// IP ') | |
| 653 | .get('/ehm pusers/urn :va:user: REDACTED :0007') | |
| 654 | .reply(200 , subjectU ser); | |
| 655 | ||
| 656 | pjds Util.getUs erWithFilt eredPermis sions(req, res, pjds Options, c b); | |
| 657 | }); | |
| 658 | it('a ke y and the trustsys s tore is pr ovided', f unction (d one) { | |
| 659 | var pjdsOption s = { | |
| 660 | user: { | |
| 661 | uid: t rustUser.u id, | |
| 662 | store: 'trustsys ' //overri ding the d efault sto re | |
| 663 | } | |
| 664 | }; | |
| 665 | var cb = funct ion(error, response) { | |
| 666 | expect(err or).to.be. null(); | |
| 667 | expect(res ponse, 'Th e test res ponse data should ha ve some ke ys').to.ha ve.keys([' uid', 'nam e', 'permi ssionSet', 'permissi onSets', ' permission s', 'statu s', 'creat edBy', 'cr eatedTime' , 'lastSuc cessfulLog in','lastU nsuccessfu lLogin','u nsuccessfu lLoginAtte mptCount', 'systemDe signator'] ); | |
| 668 | done(); | |
| 669 | }; | |
| 670 | ||
| 671 | nock('http :// IP ') | |
| 672 | .get('/tru stsys/CDS' ) | |
| 673 | .reply(200 , trustUse r); | |
| 674 | ||
| 675 | pjds Util.getUs erWithFilt eredPermis sions(req, res, pjds Options, c b); | |
| 676 | }); | |
| 677 | }) ; | |
| 678 | de scribe('re turns an e rror if', function ( ) { | |
| 679 | it('no k ey is prov ided in th e pJDSOpti ons', func tion (done ) { | |
| 680 | dele te req.uid ; //make s ure the re q has no u id | |
| 681 | var pjdsOption s = {}; | |
| 682 | var cb = funct ion(err, d ata) {}; | |
| 683 | res. rdkSend = function ( data) { | |
| 684 | expect(dat a, 'The Rd kError sho uld have a code').to .have.ownP roperty('c ode'); | |
| 685 | expect(dat a.code, 'T he RdkErro r Code sho uld match. ').to.matc h(/200.400 .1025/); | |
| 686 | done(); | |
| 687 | }; | |
| 688 | ||
| 689 | pjds Util.getUs erWithFilt eredPermis sions(req, res, pjds Options, c b); | |
| 690 | }); | |
| 691 | it('pjds sends bac k an error ', functio n (done) { | |
| 692 | var pjdsOption s = { | |
| 693 | key: subje ctUser.uid , | |
| 694 | user: subj ectUser | |
| 695 | }; | |
| 696 | var cb = funct ion(error, response) { | |
| 697 | expect(res ponse).to. be.null(); | |
| 698 | expect(err or, 'RdkEr rors shoul d have a c ode').to.h ave.ownPro perty('cod e'); | |
| 699 | expect(err or.code, ' The error code shoul d match'). to.match(/ 200.500.10 20/); | |
| 700 | done(); | |
| 701 | }; | |
| 702 | ||
| 703 | nock('http :// IP ') | |
| 704 | .get('/ehm pusers/urn :va:user: REDACTED :0007') | |
| 705 | .reply(404 , new Erro r('Pft, yo u thought wrong')); | |
| 706 | ||
| 707 | pjds Util.getUs erWithFilt eredPermis sions(req, res, pjds Options, c b); | |
| 708 | }); | |
| 709 | }) ; | |
| 710 | }); | |
| 711 | descri be('.editU ser', func tion () { | |
| 712 | be foreEach(f unction () { | |
| 713 | _.set(re q, 'app.co nfig', app Config); | |
| 714 | }) ; | |
| 715 | de scribe('re turns an o bject from pjds if', function () { | |
| 716 | it('a ke y is provi ded', func tion (done ) { | |
| 717 | var pjdsOption s = { | |
| 718 | key: subje ctUser.uid , | |
| 719 | data: subj ectUser | |
| 720 | }; | |
| 721 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 722 | expect(err or, 'The e rror shoul d be null' ).to.be.nu ll(); | |
| 723 | expect(res ponse, 'Th e test res ponse shou ld not be empty').to .not.be.em pty(); | |
| 724 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 725 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have de faulted to ehmpusers ').to.matc h(/ehmpuse rs/); | |
| 726 | done(); | |
| 727 | }; | |
| 728 | ||
| 729 | nock('http :// IP ') | |
| 730 | .filtering RequestBod y(/.*/, '* ') | |
| 731 | .put('/ehm pusers/urn :va:user: REDACTED :0007', '* ') | |
| 732 | .reply(200 , {statusC ode: 200}) ; | |
| 733 | ||
| 734 | pjds Util.editU ser(req, r es, pjdsOp tions, cb) ; | |
| 735 | }); | |
| 736 | it('a ke y and the trustsys s tore is pr ovided', f unction (d one) { | |
| 737 | var pjdsOption s = { | |
| 738 | key: trust User.uid, | |
| 739 | data: trus tUser, | |
| 740 | store: 'tr ustsys' // overriding the defau lt store | |
| 741 | }; | |
| 742 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 743 | expect(err or).to.be. null(); | |
| 744 | expect(res ponse, 'Th e test res ponse shou ld not be empty').to .not.be.em pty(); | |
| 745 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 746 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have pr operly cha nged to tr ustsys').t o.match(/t rustsys/); | |
| 747 | done(); | |
| 748 | }; | |
| 749 | ||
| 750 | nock('http :// IP ') | |
| 751 | .filtering RequestBod y(/.*/, '* ') | |
| 752 | .put('/tru stsys/CDS' , '*') | |
| 753 | .reply(200 , {statusC ode: 200}) ; | |
| 754 | ||
| 755 | pjds Util.editU ser(req, r es, pjdsOp tions, cb) ; | |
| 756 | }); | |
| 757 | }) ; | |
| 758 | de scribe('re turns an e rror if', function ( ) { | |
| 759 | it('no k ey is prov ided in th e pJDSOpti ons', func tion (done ) { | |
| 760 | var pjdsOption s = { | |
| 761 | data: subj ectUser | |
| 762 | }; | |
| 763 | var cb = funct ion() {}; | |
| 764 | res. rdkSend = function ( data) { | |
| 765 | expect(dat a).to.have .ownProper ty('code') ; | |
| 766 | expect(dat a.code).to .match(/20 0.400.1024 /); | |
| 767 | done(); | |
| 768 | }; | |
| 769 | ||
| 770 | pjds Util.editU ser(req, r es, pjdsOp tions, cb) ; | |
| 771 | }); | |
| 772 | it('pjds sends bac k an error ', functio n (done) { | |
| 773 | var pjdsOption s = { | |
| 774 | key: subje ctUser.uid , | |
| 775 | data: subj ectUser | |
| 776 | }; | |
| 777 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 778 | expect(res ponse.stat usCode).to .be(404); | |
| 779 | expect(err or).to.be. instanceOf (RdkError) ; | |
| 780 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 781 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have pr operly cha nged to eh mpusers'). to.match(/ ehmpusers/ ); | |
| 782 | done(); | |
| 783 | }; | |
| 784 | ||
| 785 | nock('http :// IP ') | |
| 786 | .filtering RequestBod y(/.*/, '* ') | |
| 787 | .put('/ehm pusers/urn :va:user: REDACTED :0007', '* ') | |
| 788 | .reply(404 , new Erro r('Pft, yo u thought wrong')); | |
| 789 | ||
| 790 | pjds Util.editU ser(req, r es, pjdsOp tions, cb) ; | |
| 791 | }); | |
| 792 | }) ; | |
| 793 | }); | |
| 794 | descri be('.patch User', fun ction () { | |
| 795 | be foreEach(f unction () { | |
| 796 | _.set(re q, 'app.co nfig', app Config); | |
| 797 | }) ; | |
| 798 | de scribe('re turns an o bject from pjds if', function () { | |
| 799 | it('a ke y is provi ded', func tion (done ) { | |
| 800 | var pjdsOption s = { | |
| 801 | key: subje ctUser.uid , | |
| 802 | data: subj ectUser | |
| 803 | }; | |
| 804 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 805 | expect(err or, 'The e rror shoul d be null' ).to.be.nu ll(); | |
| 806 | expect(res ponse, 'Th e test res ponse shou ld not be empty').to .not.be.em pty(); | |
| 807 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 808 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have de faulted to ehmpusers ').to.matc h(/ehmpuse rs/); | |
| 809 | done(); | |
| 810 | }; | |
| 811 | ||
| 812 | nock('http :// IP ') | |
| 813 | .filtering RequestBod y(/.*/, '* ') | |
| 814 | .patch('/e hmpusers/u rn:va:user : REDACTED :0007', '* ') | |
| 815 | .reply(200 , {statusC ode: 200}) ; | |
| 816 | ||
| 817 | pjds Util.patch User(req, res, pjdsO ptions, cb ); | |
| 818 | }); | |
| 819 | it('a ke y and the trustsys s tore is pr ovided', f unction (d one) { | |
| 820 | var pjdsOption s = { | |
| 821 | key: trust User.uid, | |
| 822 | data: trus tUser, | |
| 823 | store: 'tr ustsys' // overriding the defau lt store | |
| 824 | }; | |
| 825 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 826 | expect(err or).to.be. null(); | |
| 827 | expect(res ponse, 'Th e test res ponse shou ld not be empty').to .not.be.em pty(); | |
| 828 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 829 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have pr operly cha nged to tr ustsys').t o.match(/t rustsys/); | |
| 830 | done(); | |
| 831 | }; | |
| 832 | ||
| 833 | nock('http :// IP ') | |
| 834 | .filtering RequestBod y(/.*/, '* ') | |
| 835 | .patch('/t rustsys/CD S', '*') | |
| 836 | .reply(200 , {statusC ode: 200}) ; | |
| 837 | ||
| 838 | pjds Util.patch User(req, res, pjdsO ptions, cb ); | |
| 839 | }); | |
| 840 | }) ; | |
| 841 | de scribe('re turns an e rror if', function ( ) { | |
| 842 | it('no k ey is prov ided in th e pJDSOpti ons', func tion (done ) { | |
| 843 | var pjdsOption s = { | |
| 844 | data: subj ectUser | |
| 845 | }; | |
| 846 | var cb = funct ion() {}; | |
| 847 | res. rdkSend = function ( data) { | |
| 848 | expect(dat a).to.have .ownProper ty('code') ; | |
| 849 | expect(dat a.code).to .match(/20 0.400.1024 /); | |
| 850 | done(); | |
| 851 | }; | |
| 852 | ||
| 853 | pjds Util.patch User(req, res, pjdsO ptions, cb ); | |
| 854 | }); | |
| 855 | it('pjds sends bac k an error ', functio n (done) { | |
| 856 | var pjdsOption s = { | |
| 857 | key: trust User.uid, | |
| 858 | data: trus tUser, | |
| 859 | store: 'tr ustsys' | |
| 860 | }; | |
| 861 | var cb = funct ion(error, response, req, res, pjdsOptio ns) { | |
| 862 | expect(err or).to.be. instanceOf (RdkError) ; | |
| 863 | expect(pjd sOptions, 'The store property should hav e been set ').to.have .ownProper ty('store' ); | |
| 864 | expect(pjd sOptions.s tore, 'The store pro perty shou ld have pr operly cha nged to tr ustsys').t o.match(/t rustsys/); | |
| 865 | done(); | |
| 866 | }; | |
| 867 | ||
| 868 | nock('http :// IP ') | |
| 869 | .filtering RequestBod y(/.*/, '* ') | |
| 870 | .patch('/t rustsys/CD S', '*') | |
| 871 | .reply(404 , new Erro r('Pft, no t on your life')); | |
| 872 | ||
| 873 | pjds Util.patch User(req, res, pjdsO ptions, cb ); | |
| 874 | }); | |
| 875 | }) ; | |
| 876 | }); | |
| 877 | }); |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.