11import assert from 'assert' ;
2- import internalSchemaToStandard from './internalToMongoDB' ;
2+ import internalSchemaToMongoDB from './internalToMongoDB' ;
33
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 ( ) {
77 const internal = {
88 count : 1 ,
99 fields : [
@@ -892,7 +892,7 @@ describe('internalSchemaToStandard', function() {
892892 }
893893 ]
894894 } ;
895- const standard = internalSchemaToStandard ( internal ) ;
895+ const standard = await internalSchemaToMongoDB ( internal ) ;
896896 assert . deepStrictEqual ( standard , {
897897 bsonType : 'object' ,
898898 required : [ ] ,
@@ -1006,7 +1006,7 @@ describe('internalSchemaToStandard', function() {
10061006 } ) ;
10071007 } ) ;
10081008
1009- it ( 'nested document/object' , function ( ) {
1009+ it ( 'nested document/object' , async function ( ) {
10101010 const internal = {
10111011 count : 2 ,
10121012 fields : [
@@ -1105,7 +1105,7 @@ describe('internalSchemaToStandard', function() {
11051105 }
11061106 ]
11071107 } ;
1108- const standard = internalSchemaToStandard ( internal ) ;
1108+ const standard = await internalSchemaToMongoDB ( internal ) ;
11091109 assert . deepStrictEqual ( standard , {
11101110 bsonType : 'object' ,
11111111 required : [ 'author' ] ,
@@ -1126,8 +1126,8 @@ describe('internalSchemaToStandard', function() {
11261126 } ) ;
11271127 } ) ;
11281128
1129- describe ( 'arrays' , function ( ) {
1130- it ( 'array - single type' , function ( ) {
1129+ describe ( 'arrays' , async function ( ) {
1130+ it ( 'array - single type' , async function ( ) {
11311131 const internal = {
11321132 count : 2 ,
11331133 fields : [
@@ -1190,7 +1190,7 @@ describe('internalSchemaToStandard', function() {
11901190 }
11911191 ]
11921192 } ;
1193- const standard = internalSchemaToStandard ( internal ) ;
1193+ const standard = await internalSchemaToMongoDB ( internal ) ;
11941194 assert . deepStrictEqual ( standard , {
11951195 bsonType : 'object' ,
11961196 required : [ ] ,
@@ -1205,7 +1205,7 @@ describe('internalSchemaToStandard', function() {
12051205 } ) ;
12061206 } ) ;
12071207
1208- it ( 'array - complex mixed type' , function ( ) {
1208+ it ( 'array - complex mixed type' , async function ( ) {
12091209 const internal = {
12101210 count : 2 ,
12111211 fields : [
@@ -1335,7 +1335,7 @@ describe('internalSchemaToStandard', function() {
13351335 }
13361336 ]
13371337 } ;
1338- const standard = internalSchemaToStandard ( internal ) ;
1338+ const standard = await internalSchemaToMongoDB ( internal ) ;
13391339 assert . deepStrictEqual ( standard , {
13401340 bsonType : 'object' ,
13411341 required : [ ] ,
@@ -1366,7 +1366,7 @@ describe('internalSchemaToStandard', function() {
13661366 } ) ;
13671367 } ) ;
13681368
1369- it ( 'array - simple mixed type' , function ( ) {
1369+ it ( 'array - simple mixed type' , async function ( ) {
13701370 const internal = {
13711371 count : 2 ,
13721372 fields : [
@@ -1429,7 +1429,7 @@ describe('internalSchemaToStandard', function() {
14291429 }
14301430 ]
14311431 } ;
1432- const standard = internalSchemaToStandard ( internal ) ;
1432+ const standard = await internalSchemaToMongoDB ( internal ) ;
14331433 assert . deepStrictEqual ( standard , {
14341434 bsonType : 'object' ,
14351435 required : [ 'arrayMixedType' ] ,
@@ -1445,8 +1445,8 @@ describe('internalSchemaToStandard', function() {
14451445 } ) ;
14461446 } ) ;
14471447
1448- describe ( 'mixed types' , function ( ) {
1449- it ( 'simple mixed type' , function ( ) {
1448+ describe ( 'mixed types' , async function ( ) {
1449+ it ( 'simple mixed type' , async function ( ) {
14501450 const internal = {
14511451 count : 2 ,
14521452 fields : [
@@ -1507,7 +1507,7 @@ describe('internalSchemaToStandard', function() {
15071507 }
15081508 ]
15091509 } ;
1510- const standard = internalSchemaToStandard ( internal ) ;
1510+ const standard = await internalSchemaToMongoDB ( internal ) ;
15111511 assert . deepStrictEqual ( standard , {
15121512 bsonType : 'object' ,
15131513 required : [ ] ,
@@ -1519,7 +1519,7 @@ describe('internalSchemaToStandard', function() {
15191519 } ) ;
15201520 } ) ;
15211521
1522- it ( 'complex mixed type' , function ( ) {
1522+ it ( 'complex mixed type' , async function ( ) {
15231523 const internal = {
15241524 count : 2 ,
15251525 fields : [
@@ -1623,7 +1623,7 @@ describe('internalSchemaToStandard', function() {
16231623 }
16241624 ]
16251625 } ;
1626- const standard = internalSchemaToStandard ( internal ) ;
1626+ const standard = await internalSchemaToMongoDB ( internal ) ;
16271627 assert . deepStrictEqual ( standard , {
16281628 bsonType : 'object' ,
16291629 required : [ ] ,
@@ -1651,5 +1651,118 @@ describe('internalSchemaToStandard', function() {
16511651 } ) ;
16521652 } ) ;
16531653 } ) ;
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+ } ) ;
16541767 } ) ;
16551768} ) ;
0 commit comments