@@ -1444,36 +1444,84 @@ config.parallel('rx-collection.test.js', () => {
1444
1444
} ) ;
1445
1445
} ) ;
1446
1446
describe ( 'issues' , ( ) => {
1447
- describe ( '#528 default value ignored when 0' , ( ) => {
1448
- it ( 'should use value when default=0' , async ( ) => {
1449
- const schema = {
1450
- version : 0 ,
1451
- type : 'object' ,
1452
- properties : {
1453
- passportId : {
1454
- type : 'string' ,
1455
- primary : true
1456
- } ,
1457
- weight : {
1458
- type : 'number' ,
1459
- default : 0
1460
- }
1447
+ it ( '#528 default value ignored when 0' , async ( ) => {
1448
+ const schema = {
1449
+ version : 0 ,
1450
+ type : 'object' ,
1451
+ properties : {
1452
+ passportId : {
1453
+ type : 'string' ,
1454
+ primary : true
1455
+ } ,
1456
+ weight : {
1457
+ type : 'number' ,
1458
+ default : 0
1461
1459
}
1462
- } ;
1463
- const db = await RxDatabase . create ( {
1464
- name : util . randomCouchString ( 10 ) ,
1465
- adapter : 'memory'
1466
- } ) ;
1467
- const collection = await db . collection ( {
1468
- name : 'humanx' ,
1469
- schema
1470
- } ) ;
1471
- const doc = await collection . insert ( {
1472
- passportId : util . randomCouchString ( 10 )
1473
- } ) ;
1474
- assert . equal ( doc . weight , 0 ) ;
1475
- db . destroy ( ) ;
1460
+ }
1461
+ } ;
1462
+ const db = await RxDatabase . create ( {
1463
+ name : util . randomCouchString ( 10 ) ,
1464
+ adapter : 'memory'
1465
+ } ) ;
1466
+ const collection = await db . collection ( {
1467
+ name : 'humanx' ,
1468
+ schema
1469
+ } ) ;
1470
+ const doc = await collection . insert ( {
1471
+ passportId : util . randomCouchString ( 10 )
1472
+ } ) ;
1473
+ assert . equal ( doc . weight , 0 ) ;
1474
+ db . destroy ( ) ;
1475
+ } ) ;
1476
+ it ( '#596 Default value not applied when value is undefined' , async ( ) => {
1477
+ const schema = {
1478
+ version : 0 ,
1479
+ type : 'object' ,
1480
+ properties : {
1481
+ passportId : {
1482
+ type : 'string' ,
1483
+ primary : true
1484
+ } ,
1485
+ firstName : {
1486
+ type : 'string'
1487
+ } ,
1488
+ lastName : {
1489
+ type : 'string'
1490
+ } ,
1491
+ age : {
1492
+ type : 'integer' ,
1493
+ minimum : 0 ,
1494
+ maximum : 150
1495
+ } ,
1496
+ score : {
1497
+ type : 'integer' ,
1498
+ default : 100
1499
+ }
1500
+ }
1501
+ } ;
1502
+ const db = await RxDatabase . create ( {
1503
+ name : util . randomCouchString ( 10 ) ,
1504
+ adapter : 'memory'
1505
+ } ) ;
1506
+ const collection = await db . collection ( {
1507
+ name : 'humanx' ,
1508
+ schema
1509
+ } ) ;
1510
+ // insert a document
1511
+ await collection . insert ( {
1512
+ passportId : 'foobar' ,
1513
+ firstName : 'Bob' ,
1514
+ lastName : 'Kelso' ,
1515
+ age : 56 ,
1516
+ score : undefined
1476
1517
} ) ;
1518
+ const myDocument = await collection
1519
+ . findOne ( )
1520
+ . where ( 'firstName' )
1521
+ . eq ( 'Bob' )
1522
+ . exec ( ) ;
1523
+ assert . equal ( myDocument . score , 100 ) ;
1524
+ db . destroy ( ) ;
1477
1525
} ) ;
1478
1526
} ) ;
1479
1527
describe ( 'wait a bit' , ( ) => {
0 commit comments