@@ -499,8 +499,52 @@ describe('parsers/paw/Parser.js', () => {
499
499
} )
500
500
} )
501
501
502
+ describe ( '@convertSingleRequestIntoRequestEntry' , ( ) => {
503
+ it ( 'should work' , ( ) => {
504
+ const inputs = [
505
+ { getUrlBase : ( ) => '' } ,
506
+ { getUrlBase : ( ) => 'http://paw.cloud/base/users' } ,
507
+ { getUrlBase : ( ) => 'file:///base/users' } ,
508
+ { getUrlBase : ( ) => 'urn:paw.cloud/base/users' }
509
+ ]
510
+ const expected = [
511
+ [ { key : '' , value : { getUrlBase : ( ) => null } } ] ,
512
+ [ { key : 'http://paw.cloud' , value : { getUrlBase : ( ) => 'http://paw.cloud/base/users' } } ] ,
513
+ [ { key : 'file://' , value : { getUrlBase : ( ) => 'file:///base/users' } } ] ,
514
+ [ { key : 'urn:paw.cloud' , value : { getUrlBase : ( ) => 'urn:paw.cloud/base/users' } } ]
515
+ ]
516
+ const actual = inputs . map ( input => __internals__ . convertSingleRequestIntoRequestEntry ( input ) )
517
+ expect ( JSON . stringify ( actual , null , 2 ) ) . toEqual ( JSON . stringify ( expected , null , 2 ) )
518
+ } )
519
+ } )
520
+
521
+ describe ( '@convertRequestsIntoRequestEntries' , ( ) => {
522
+ it ( 'should work' , ( ) => {
523
+ spyOn ( __internals__ , 'convertSingleRequestIntoRequestEntry' ) . andCall ( r => {
524
+ return [ { key : r . getUrlBase ( ) * 2 , value : r } ]
525
+ } )
526
+
527
+ const inputs = [
528
+ [ ] ,
529
+ [ { getUrlBase : ( ) => 123 } ] ,
530
+ [ { getUrlBase : ( ) => 123 } , { getUrlBase : ( ) => 234 } ]
531
+ ]
532
+ const expected = [
533
+ [ ] ,
534
+ [ { key : 123 * 2 , value : { getUrlBase : ( ) => 123 } } ] ,
535
+ [
536
+ { key : 123 , value : { getUrlBase : ( ) => 123 } } ,
537
+ { key : 234 , value : { getUrlBase : ( ) => 234 } }
538
+ ]
539
+ ]
540
+ const actual = inputs . map ( input => __internals__ . convertRequestsIntoRequestEntries ( input ) )
541
+ expect ( JSON . stringify ( actual , null , 2 ) ) . toEqual ( JSON . stringify ( expected , null , 2 ) )
542
+ } )
543
+ } )
544
+
502
545
describe ( '@extractCommonHostsFromRequests' , ( ) => {
503
546
it ( 'should work if underlying methods are correct' , ( ) => {
547
+ spyOn ( __internals__ , 'convertRequestsIntoRequestEntries' ) . andCall ( v => v )
504
548
spyOn ( __internals__ , 'addHostEntryToHostMap' ) . andReturn ( { a : 321 , b : 321 , c : 321 } )
505
549
spyOn ( __internals__ , 'updateHostKeyWithLongestCommonPathname' ) . andReturn ( 123 )
506
550
const req1 = { getUrlBase : ( ) => { } }
@@ -1313,6 +1357,74 @@ describe('parsers/paw/Parser.js', () => {
1313
1357
)
1314
1358
expect ( actual ) . toEqual ( expected )
1315
1359
} )
1360
+
1361
+ it ( 'should prefer schema default over value' , ( ) => {
1362
+ const variable = {
1363
+ name : 'userId' ,
1364
+ value : { getEvaluatedString : ( ) => 123 } ,
1365
+ schema : { default : '' } ,
1366
+ type : 345
1367
+ }
1368
+ const request = { getVariableById : ( ) => variable }
1369
+ const location = 'queries'
1370
+ const contexts = List ( [ 567 , 567 ] )
1371
+ const paramName = 'UserId'
1372
+ const input = { variableUUID : 678 }
1373
+ const expected = {
1374
+ key : 'UserId' ,
1375
+ value : new Parameter ( {
1376
+ in : 'queries' ,
1377
+ key : 'userId' ,
1378
+ name : 'userId' ,
1379
+ type : 345 ,
1380
+ description : null ,
1381
+ default : '' ,
1382
+ constraints : List ( [
1383
+ new Constraint . JSONSchema ( { default : '' } )
1384
+ ] ) ,
1385
+ applicableContexts : List ( [ 567 , 567 ] )
1386
+ } )
1387
+ }
1388
+
1389
+ const actual = __internals__ . convertRequestVariableDVIntoParameter (
1390
+ request , location , contexts , input , paramName
1391
+ )
1392
+ expect ( actual ) . toEqual ( expected )
1393
+ } )
1394
+
1395
+ it ( 'should work if no schema' , ( ) => {
1396
+ const variable = {
1397
+ name : 'userId' ,
1398
+ value : { getEvaluatedString : ( ) => 123 } ,
1399
+ schema : null ,
1400
+ type : 345
1401
+ }
1402
+ const request = { getVariableById : ( ) => variable }
1403
+ const location = 'queries'
1404
+ const contexts = List ( [ 567 , 567 ] )
1405
+ const paramName = 'UserId'
1406
+ const input = { variableUUID : 678 }
1407
+ const expected = {
1408
+ key : 'UserId' ,
1409
+ value : new Parameter ( {
1410
+ in : 'queries' ,
1411
+ key : 'userId' ,
1412
+ name : 'userId' ,
1413
+ type : 345 ,
1414
+ description : null ,
1415
+ default : 123 ,
1416
+ constraints : List ( [
1417
+ new Constraint . JSONSchema ( null )
1418
+ ] ) ,
1419
+ applicableContexts : List ( [ 567 , 567 ] )
1420
+ } )
1421
+ }
1422
+
1423
+ const actual = __internals__ . convertRequestVariableDVIntoParameter (
1424
+ request , location , contexts , input , paramName
1425
+ )
1426
+ expect ( actual ) . toEqual ( expected )
1427
+ } )
1316
1428
} )
1317
1429
1318
1430
describe ( '@convertRequestVariableDSIntoParameter' , ( ) => {
0 commit comments