|
1 | 1 | import assert from 'assert';
|
2 |
| -import internalSchemaToExpanded from './internalToExpanded'; |
3 | 2 | import { RELAXED_EJSON_DEFINITIONS } from './internalToStandard';
|
| 3 | +import InternalToExpandedConvertor from './internalToExpanded'; |
| 4 | +import { ObjectId } from 'bson'; |
4 | 5 |
|
5 | 6 | describe('internalSchemaToExpanded', async function() {
|
6 | 7 | describe('Converts: ', async function() {
|
@@ -336,12 +337,21 @@ describe('internalSchemaToExpanded', async function() {
|
336 | 337 | }
|
337 | 338 | ]
|
338 | 339 | };
|
339 |
| - const standard = await internalSchemaToExpanded(internal); |
340 |
| - assert.deepStrictEqual(standard, { |
| 340 | + const convertor = new InternalToExpandedConvertor(); |
| 341 | + const expanded = await convertor.convert(internal); |
| 342 | + const expectedDefinitions: any = RELAXED_EJSON_DEFINITIONS; |
| 343 | + delete expectedDefinitions.BSONSymbol; |
| 344 | + delete expectedDefinitions.CodeWScope; |
| 345 | + delete expectedDefinitions.DBPointer; |
| 346 | + delete expectedDefinitions.DBRef; |
| 347 | + delete expectedDefinitions.Date; |
| 348 | + delete expectedDefinitions.MinKey; |
| 349 | + delete expectedDefinitions.Undefined; |
| 350 | + assert.deepStrictEqual(expanded, { |
341 | 351 | type: 'object',
|
342 | 352 | 'x-bsonType': 'object',
|
343 | 353 | required: [],
|
344 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 354 | + $defs: expectedDefinitions, |
345 | 355 | properties: {
|
346 | 356 | _id: {
|
347 | 357 | $ref: '#/$defs/ObjectId',
|
@@ -593,12 +603,16 @@ describe('internalSchemaToExpanded', async function() {
|
593 | 603 | }
|
594 | 604 | ]
|
595 | 605 | };
|
596 |
| - const standard = await internalSchemaToExpanded(internal); |
597 |
| - assert.deepStrictEqual(standard, { |
| 606 | + const convertor = new InternalToExpandedConvertor(); |
| 607 | + const expanded = await convertor.convert(internal); |
| 608 | + const expectedDefinitions = { |
| 609 | + Double: RELAXED_EJSON_DEFINITIONS.Double |
| 610 | + }; |
| 611 | + assert.deepStrictEqual(expanded, { |
598 | 612 | type: 'object',
|
599 | 613 | 'x-bsonType': 'object',
|
600 | 614 | required: ['author'],
|
601 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 615 | + $defs: expectedDefinitions, |
602 | 616 | properties: {
|
603 | 617 | author: {
|
604 | 618 | type: 'object',
|
@@ -704,12 +718,13 @@ describe('internalSchemaToExpanded', async function() {
|
704 | 718 | }
|
705 | 719 | ]
|
706 | 720 | };
|
707 |
| - const standard = await internalSchemaToExpanded(internal); |
708 |
| - assert.deepStrictEqual(standard, { |
| 721 | + const convertor = new InternalToExpandedConvertor(); |
| 722 | + const expanded = await convertor.convert(internal); |
| 723 | + assert.deepStrictEqual(expanded, { |
709 | 724 | type: 'object',
|
710 | 725 | 'x-bsonType': 'object',
|
711 | 726 | required: [],
|
712 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 727 | + $defs: {}, |
713 | 728 | properties: {
|
714 | 729 | genres: {
|
715 | 730 | type: 'array',
|
@@ -867,12 +882,13 @@ describe('internalSchemaToExpanded', async function() {
|
867 | 882 | }
|
868 | 883 | ]
|
869 | 884 | };
|
870 |
| - const standard = await internalSchemaToExpanded(internal); |
871 |
| - assert.deepStrictEqual(standard, { |
| 885 | + const convertor = new InternalToExpandedConvertor(); |
| 886 | + const expanded = await convertor.convert(internal); |
| 887 | + assert.deepStrictEqual(expanded, { |
872 | 888 | type: 'object',
|
873 | 889 | 'x-bsonType': 'object',
|
874 | 890 | required: [],
|
875 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 891 | + $defs: {}, |
876 | 892 | properties: {
|
877 | 893 | genres: {
|
878 | 894 | type: 'array',
|
@@ -1002,12 +1018,13 @@ describe('internalSchemaToExpanded', async function() {
|
1002 | 1018 | }
|
1003 | 1019 | ]
|
1004 | 1020 | };
|
1005 |
| - const standard = await internalSchemaToExpanded(internal); |
1006 |
| - assert.deepStrictEqual(standard, { |
| 1021 | + const convertor = new InternalToExpandedConvertor(); |
| 1022 | + const expanded = await convertor.convert(internal); |
| 1023 | + assert.deepStrictEqual(expanded, { |
1007 | 1024 | type: 'object',
|
1008 | 1025 | 'x-bsonType': 'object',
|
1009 | 1026 | required: ['arrayMixedType'],
|
1010 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1027 | + $defs: {}, |
1011 | 1028 | properties: {
|
1012 | 1029 | arrayMixedType: {
|
1013 | 1030 | type: 'array',
|
@@ -1111,12 +1128,13 @@ describe('internalSchemaToExpanded', async function() {
|
1111 | 1128 | }
|
1112 | 1129 | ]
|
1113 | 1130 | };
|
1114 |
| - const standard = await internalSchemaToExpanded(internal); |
1115 |
| - assert.deepStrictEqual(standard, { |
| 1131 | + const convertor = new InternalToExpandedConvertor(); |
| 1132 | + const expanded = await convertor.convert(internal); |
| 1133 | + assert.deepStrictEqual(expanded, { |
1116 | 1134 | type: 'object',
|
1117 | 1135 | 'x-bsonType': 'object',
|
1118 | 1136 | required: [],
|
1119 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1137 | + $defs: {}, |
1120 | 1138 | properties: {
|
1121 | 1139 | mixedType: {
|
1122 | 1140 | 'x-metadata': {
|
@@ -1252,12 +1270,13 @@ describe('internalSchemaToExpanded', async function() {
|
1252 | 1270 | }
|
1253 | 1271 | ]
|
1254 | 1272 | };
|
1255 |
| - const standard = await internalSchemaToExpanded(internal); |
1256 |
| - assert.deepStrictEqual(standard, { |
| 1273 | + const convertor = new InternalToExpandedConvertor(); |
| 1274 | + const expanded = await convertor.convert(internal); |
| 1275 | + assert.deepStrictEqual(expanded, { |
1257 | 1276 | type: 'object',
|
1258 | 1277 | 'x-bsonType': 'object',
|
1259 | 1278 | required: [],
|
1260 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1279 | + $defs: {}, |
1261 | 1280 | properties: {
|
1262 | 1281 | mixedComplexType: {
|
1263 | 1282 | 'x-metadata': {
|
@@ -1360,12 +1379,16 @@ describe('internalSchemaToExpanded', async function() {
|
1360 | 1379 | }
|
1361 | 1380 | ]
|
1362 | 1381 | };
|
1363 |
| - const standard = await internalSchemaToExpanded(internal); |
1364 |
| - assert.deepStrictEqual(standard, { |
| 1382 | + const convertor = new InternalToExpandedConvertor(); |
| 1383 | + const expanded = await convertor.convert(internal); |
| 1384 | + const expectedDefinitions = { |
| 1385 | + ObjectId: RELAXED_EJSON_DEFINITIONS.ObjectId |
| 1386 | + }; |
| 1387 | + assert.deepStrictEqual(expanded, { |
1365 | 1388 | type: 'object',
|
1366 | 1389 | 'x-bsonType': 'object',
|
1367 | 1390 | required: ['mixedType'],
|
1368 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1391 | + $defs: expectedDefinitions, |
1369 | 1392 | properties: {
|
1370 | 1393 | mixedType: {
|
1371 | 1394 | 'x-metadata': {
|
@@ -1507,7 +1530,8 @@ describe('internalSchemaToExpanded', async function() {
|
1507 | 1530 | ]
|
1508 | 1531 | };
|
1509 | 1532 | const abortController = new AbortController();
|
1510 |
| - const promise = internalSchemaToExpanded(internal, { signal: abortController.signal }); |
| 1533 | + const convertor = new InternalToExpandedConvertor(); |
| 1534 | + const promise = convertor.convert(internal, { signal: abortController.signal }); |
1511 | 1535 | abortController.abort(new Error('Too long, didn\'t wait.'));
|
1512 | 1536 | await assert.rejects(promise, {
|
1513 | 1537 | name: 'Error',
|
|
0 commit comments