1
1
import assert from 'assert' ;
2
- import internalSchemaToStandard from './internalToMongoDB' ;
2
+ import internalSchemaToMongoDB from './internalToMongoDB' ;
3
3
4
- describe ( 'internalSchemaToStandard' , function ( ) {
5
- describe ( 'Converts: ' , function ( ) {
6
- it ( 'get me analyzed thing ' , async function ( ) {
4
+ describe ( 'internalSchemaToMongoDB' , async function ( ) {
5
+ describe ( 'Converts: ' , async function ( ) {
6
+ it ( 'all the types ' , async function ( ) {
7
7
const internal = {
8
8
count : 1 ,
9
9
fields : [
@@ -892,7 +892,7 @@ describe('internalSchemaToStandard', function() {
892
892
}
893
893
]
894
894
} ;
895
- const standard = internalSchemaToStandard ( internal ) ;
895
+ const standard = await internalSchemaToMongoDB ( internal ) ;
896
896
assert . deepStrictEqual ( standard , {
897
897
bsonType : 'object' ,
898
898
required : [ ] ,
@@ -1006,7 +1006,7 @@ describe('internalSchemaToStandard', function() {
1006
1006
} ) ;
1007
1007
} ) ;
1008
1008
1009
- it ( 'nested document/object' , function ( ) {
1009
+ it ( 'nested document/object' , async function ( ) {
1010
1010
const internal = {
1011
1011
count : 2 ,
1012
1012
fields : [
@@ -1105,7 +1105,7 @@ describe('internalSchemaToStandard', function() {
1105
1105
}
1106
1106
]
1107
1107
} ;
1108
- const standard = internalSchemaToStandard ( internal ) ;
1108
+ const standard = await internalSchemaToMongoDB ( internal ) ;
1109
1109
assert . deepStrictEqual ( standard , {
1110
1110
bsonType : 'object' ,
1111
1111
required : [ 'author' ] ,
@@ -1126,8 +1126,8 @@ describe('internalSchemaToStandard', function() {
1126
1126
} ) ;
1127
1127
} ) ;
1128
1128
1129
- describe ( 'arrays' , function ( ) {
1130
- it ( 'array - single type' , function ( ) {
1129
+ describe ( 'arrays' , async function ( ) {
1130
+ it ( 'array - single type' , async function ( ) {
1131
1131
const internal = {
1132
1132
count : 2 ,
1133
1133
fields : [
@@ -1190,7 +1190,7 @@ describe('internalSchemaToStandard', function() {
1190
1190
}
1191
1191
]
1192
1192
} ;
1193
- const standard = internalSchemaToStandard ( internal ) ;
1193
+ const standard = await internalSchemaToMongoDB ( internal ) ;
1194
1194
assert . deepStrictEqual ( standard , {
1195
1195
bsonType : 'object' ,
1196
1196
required : [ ] ,
@@ -1205,7 +1205,7 @@ describe('internalSchemaToStandard', function() {
1205
1205
} ) ;
1206
1206
} ) ;
1207
1207
1208
- it ( 'array - complex mixed type' , function ( ) {
1208
+ it ( 'array - complex mixed type' , async function ( ) {
1209
1209
const internal = {
1210
1210
count : 2 ,
1211
1211
fields : [
@@ -1335,7 +1335,7 @@ describe('internalSchemaToStandard', function() {
1335
1335
}
1336
1336
]
1337
1337
} ;
1338
- const standard = internalSchemaToStandard ( internal ) ;
1338
+ const standard = await internalSchemaToMongoDB ( internal ) ;
1339
1339
assert . deepStrictEqual ( standard , {
1340
1340
bsonType : 'object' ,
1341
1341
required : [ ] ,
@@ -1366,7 +1366,7 @@ describe('internalSchemaToStandard', function() {
1366
1366
} ) ;
1367
1367
} ) ;
1368
1368
1369
- it ( 'array - simple mixed type' , function ( ) {
1369
+ it ( 'array - simple mixed type' , async function ( ) {
1370
1370
const internal = {
1371
1371
count : 2 ,
1372
1372
fields : [
@@ -1429,7 +1429,7 @@ describe('internalSchemaToStandard', function() {
1429
1429
}
1430
1430
]
1431
1431
} ;
1432
- const standard = internalSchemaToStandard ( internal ) ;
1432
+ const standard = await internalSchemaToMongoDB ( internal ) ;
1433
1433
assert . deepStrictEqual ( standard , {
1434
1434
bsonType : 'object' ,
1435
1435
required : [ 'arrayMixedType' ] ,
@@ -1445,8 +1445,8 @@ describe('internalSchemaToStandard', function() {
1445
1445
} ) ;
1446
1446
} ) ;
1447
1447
1448
- describe ( 'mixed types' , function ( ) {
1449
- it ( 'simple mixed type' , function ( ) {
1448
+ describe ( 'mixed types' , async function ( ) {
1449
+ it ( 'simple mixed type' , async function ( ) {
1450
1450
const internal = {
1451
1451
count : 2 ,
1452
1452
fields : [
@@ -1507,7 +1507,7 @@ describe('internalSchemaToStandard', function() {
1507
1507
}
1508
1508
]
1509
1509
} ;
1510
- const standard = internalSchemaToStandard ( internal ) ;
1510
+ const standard = await internalSchemaToMongoDB ( internal ) ;
1511
1511
assert . deepStrictEqual ( standard , {
1512
1512
bsonType : 'object' ,
1513
1513
required : [ ] ,
@@ -1519,7 +1519,7 @@ describe('internalSchemaToStandard', function() {
1519
1519
} ) ;
1520
1520
} ) ;
1521
1521
1522
- it ( 'complex mixed type' , function ( ) {
1522
+ it ( 'complex mixed type' , async function ( ) {
1523
1523
const internal = {
1524
1524
count : 2 ,
1525
1525
fields : [
@@ -1623,7 +1623,7 @@ describe('internalSchemaToStandard', function() {
1623
1623
}
1624
1624
]
1625
1625
} ;
1626
- const standard = internalSchemaToStandard ( internal ) ;
1626
+ const standard = await internalSchemaToMongoDB ( internal ) ;
1627
1627
assert . deepStrictEqual ( standard , {
1628
1628
bsonType : 'object' ,
1629
1629
required : [ ] ,
@@ -1651,5 +1651,118 @@ describe('internalSchemaToStandard', function() {
1651
1651
} ) ;
1652
1652
} ) ;
1653
1653
} ) ;
1654
+
1655
+ it ( 'can be aborted' , async function ( ) {
1656
+ const internal = {
1657
+ count : 2 ,
1658
+ fields : [
1659
+ {
1660
+ name : 'mixedComplexType' ,
1661
+ path : [
1662
+ 'mixedComplexType'
1663
+ ] ,
1664
+ count : 2 ,
1665
+ type : [
1666
+ 'Array' ,
1667
+ 'Document' ,
1668
+ 'Undefined'
1669
+ ] ,
1670
+ probability : 0.6666666666666666 ,
1671
+ hasDuplicates : false ,
1672
+ types : [
1673
+ {
1674
+ name : 'Array' ,
1675
+ path : [
1676
+ 'mixedComplexType'
1677
+ ] ,
1678
+ count : 1 ,
1679
+ probability : 0.3333333333333333 ,
1680
+ bsonType : 'Array' ,
1681
+ types : [
1682
+ {
1683
+ name : 'Int32' ,
1684
+ path : [
1685
+ 'mixedComplexType'
1686
+ ] ,
1687
+ count : 3 ,
1688
+ probability : 1 ,
1689
+ unique : 3 ,
1690
+ hasDuplicates : false ,
1691
+ values : [
1692
+ 1 ,
1693
+ 2 ,
1694
+ 3
1695
+ ] ,
1696
+ bsonType : 'Int32'
1697
+ }
1698
+ ] ,
1699
+ totalCount : 3 ,
1700
+ lengths : [
1701
+ 3
1702
+ ] ,
1703
+ averageLength : 3
1704
+ } ,
1705
+ {
1706
+ name : 'Document' ,
1707
+ path : [
1708
+ 'mixedComplexType'
1709
+ ] ,
1710
+ count : 1 ,
1711
+ probability : 0.3333333333333333 ,
1712
+ bsonType : 'Document' ,
1713
+ fields : [
1714
+ {
1715
+ name : 'a' ,
1716
+ path : [
1717
+ 'mixedComplexType' ,
1718
+ 'a'
1719
+ ] ,
1720
+ count : 1 ,
1721
+ type : 'String' ,
1722
+ probability : 1 ,
1723
+ hasDuplicates : false ,
1724
+ types : [
1725
+ {
1726
+ name : 'String' ,
1727
+ path : [
1728
+ 'mixedComplexType' ,
1729
+ 'a'
1730
+ ] ,
1731
+ count : 1 ,
1732
+ probability : 1 ,
1733
+ unique : 1 ,
1734
+ hasDuplicates : false ,
1735
+ values : [
1736
+ 'bc'
1737
+ ] ,
1738
+ bsonType : 'String'
1739
+ }
1740
+ ]
1741
+ }
1742
+ ]
1743
+ } ,
1744
+ {
1745
+ name : 'Undefined' ,
1746
+ bsonType : 'Undefined' ,
1747
+ unique : 1 ,
1748
+ hasDuplicates : false ,
1749
+ path : [
1750
+ 'mixedComplexType'
1751
+ ] ,
1752
+ count : 1 ,
1753
+ probability : 0.3333333333333333
1754
+ }
1755
+ ]
1756
+ }
1757
+ ]
1758
+ } ;
1759
+ const abortController = new AbortController ( ) ;
1760
+ const promise = internalSchemaToMongoDB ( internal , { signal : abortController . signal } ) ;
1761
+ abortController . abort ( new Error ( 'Too long, didn\'t wait.' ) ) ;
1762
+ await assert . rejects ( promise , {
1763
+ name : 'Error' ,
1764
+ message : 'Too long, didn\'t wait.'
1765
+ } ) ;
1766
+ } ) ;
1654
1767
} ) ;
1655
1768
} ) ;
0 commit comments