|
1 | 1 | import assert from 'assert';
|
2 |
| -import internalSchemaToExpanded from './internalToExpanded'; |
3 | 2 | import { RELAXED_EJSON_DEFINITIONS } from './internalToStandard';
|
| 3 | +import { convertInternalToExpanded } from './internalToExpanded'; |
4 | 4 |
|
5 | 5 | describe('internalSchemaToExpanded', async function() {
|
6 | 6 | describe('Converts: ', async function() {
|
@@ -336,12 +336,20 @@ describe('internalSchemaToExpanded', async function() {
|
336 | 336 | }
|
337 | 337 | ]
|
338 | 338 | };
|
339 |
| - const standard = await internalSchemaToExpanded(internal); |
340 |
| - assert.deepStrictEqual(standard, { |
| 339 | + const expanded = await convertInternalToExpanded(internal); |
| 340 | + const expectedDefinitions: Partial<typeof RELAXED_EJSON_DEFINITIONS> = { ...RELAXED_EJSON_DEFINITIONS }; |
| 341 | + delete expectedDefinitions.BSONSymbol; |
| 342 | + delete expectedDefinitions.CodeWScope; |
| 343 | + delete expectedDefinitions.DBPointer; |
| 344 | + delete expectedDefinitions.DBRef; |
| 345 | + delete expectedDefinitions.Date; |
| 346 | + delete expectedDefinitions.MinKey; |
| 347 | + delete expectedDefinitions.Undefined; |
| 348 | + assert.deepStrictEqual(expanded, { |
341 | 349 | type: 'object',
|
342 | 350 | 'x-bsonType': 'object',
|
343 | 351 | required: [],
|
344 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 352 | + $defs: expectedDefinitions, |
345 | 353 | properties: {
|
346 | 354 | _id: {
|
347 | 355 | $ref: '#/$defs/ObjectId',
|
@@ -593,12 +601,15 @@ describe('internalSchemaToExpanded', async function() {
|
593 | 601 | }
|
594 | 602 | ]
|
595 | 603 | };
|
596 |
| - const standard = await internalSchemaToExpanded(internal); |
597 |
| - assert.deepStrictEqual(standard, { |
| 604 | + const expanded = await convertInternalToExpanded(internal); |
| 605 | + const expectedDefinitions = { |
| 606 | + Double: RELAXED_EJSON_DEFINITIONS.Double |
| 607 | + }; |
| 608 | + assert.deepStrictEqual(expanded, { |
598 | 609 | type: 'object',
|
599 | 610 | 'x-bsonType': 'object',
|
600 | 611 | required: ['author'],
|
601 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 612 | + $defs: expectedDefinitions, |
602 | 613 | properties: {
|
603 | 614 | author: {
|
604 | 615 | type: 'object',
|
@@ -704,12 +715,12 @@ describe('internalSchemaToExpanded', async function() {
|
704 | 715 | }
|
705 | 716 | ]
|
706 | 717 | };
|
707 |
| - const standard = await internalSchemaToExpanded(internal); |
708 |
| - assert.deepStrictEqual(standard, { |
| 718 | + const expanded = await convertInternalToExpanded(internal); |
| 719 | + assert.deepStrictEqual(expanded, { |
709 | 720 | type: 'object',
|
710 | 721 | 'x-bsonType': 'object',
|
711 | 722 | required: [],
|
712 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 723 | + $defs: {}, |
713 | 724 | properties: {
|
714 | 725 | genres: {
|
715 | 726 | type: 'array',
|
@@ -867,12 +878,12 @@ describe('internalSchemaToExpanded', async function() {
|
867 | 878 | }
|
868 | 879 | ]
|
869 | 880 | };
|
870 |
| - const standard = await internalSchemaToExpanded(internal); |
871 |
| - assert.deepStrictEqual(standard, { |
| 881 | + const expanded = await convertInternalToExpanded(internal); |
| 882 | + assert.deepStrictEqual(expanded, { |
872 | 883 | type: 'object',
|
873 | 884 | 'x-bsonType': 'object',
|
874 | 885 | required: [],
|
875 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 886 | + $defs: {}, |
876 | 887 | properties: {
|
877 | 888 | genres: {
|
878 | 889 | type: 'array',
|
@@ -1002,12 +1013,12 @@ describe('internalSchemaToExpanded', async function() {
|
1002 | 1013 | }
|
1003 | 1014 | ]
|
1004 | 1015 | };
|
1005 |
| - const standard = await internalSchemaToExpanded(internal); |
1006 |
| - assert.deepStrictEqual(standard, { |
| 1016 | + const expanded = await convertInternalToExpanded(internal); |
| 1017 | + assert.deepStrictEqual(expanded, { |
1007 | 1018 | type: 'object',
|
1008 | 1019 | 'x-bsonType': 'object',
|
1009 | 1020 | required: ['arrayMixedType'],
|
1010 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1021 | + $defs: {}, |
1011 | 1022 | properties: {
|
1012 | 1023 | arrayMixedType: {
|
1013 | 1024 | type: 'array',
|
@@ -1111,12 +1122,12 @@ describe('internalSchemaToExpanded', async function() {
|
1111 | 1122 | }
|
1112 | 1123 | ]
|
1113 | 1124 | };
|
1114 |
| - const standard = await internalSchemaToExpanded(internal); |
1115 |
| - assert.deepStrictEqual(standard, { |
| 1125 | + const expanded = await convertInternalToExpanded(internal); |
| 1126 | + assert.deepStrictEqual(expanded, { |
1116 | 1127 | type: 'object',
|
1117 | 1128 | 'x-bsonType': 'object',
|
1118 | 1129 | required: [],
|
1119 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1130 | + $defs: {}, |
1120 | 1131 | properties: {
|
1121 | 1132 | mixedType: {
|
1122 | 1133 | 'x-metadata': {
|
@@ -1252,12 +1263,12 @@ describe('internalSchemaToExpanded', async function() {
|
1252 | 1263 | }
|
1253 | 1264 | ]
|
1254 | 1265 | };
|
1255 |
| - const standard = await internalSchemaToExpanded(internal); |
1256 |
| - assert.deepStrictEqual(standard, { |
| 1266 | + const expanded = await convertInternalToExpanded(internal); |
| 1267 | + assert.deepStrictEqual(expanded, { |
1257 | 1268 | type: 'object',
|
1258 | 1269 | 'x-bsonType': 'object',
|
1259 | 1270 | required: [],
|
1260 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1271 | + $defs: {}, |
1261 | 1272 | properties: {
|
1262 | 1273 | mixedComplexType: {
|
1263 | 1274 | 'x-metadata': {
|
@@ -1360,12 +1371,15 @@ describe('internalSchemaToExpanded', async function() {
|
1360 | 1371 | }
|
1361 | 1372 | ]
|
1362 | 1373 | };
|
1363 |
| - const standard = await internalSchemaToExpanded(internal); |
1364 |
| - assert.deepStrictEqual(standard, { |
| 1374 | + const expanded = await convertInternalToExpanded(internal); |
| 1375 | + const expectedDefinitions = { |
| 1376 | + ObjectId: RELAXED_EJSON_DEFINITIONS.ObjectId |
| 1377 | + }; |
| 1378 | + assert.deepStrictEqual(expanded, { |
1365 | 1379 | type: 'object',
|
1366 | 1380 | 'x-bsonType': 'object',
|
1367 | 1381 | required: ['mixedType'],
|
1368 |
| - $defs: RELAXED_EJSON_DEFINITIONS, |
| 1382 | + $defs: expectedDefinitions, |
1369 | 1383 | properties: {
|
1370 | 1384 | mixedType: {
|
1371 | 1385 | 'x-metadata': {
|
@@ -1507,7 +1521,7 @@ describe('internalSchemaToExpanded', async function() {
|
1507 | 1521 | ]
|
1508 | 1522 | };
|
1509 | 1523 | const abortController = new AbortController();
|
1510 |
| - const promise = internalSchemaToExpanded(internal, { signal: abortController.signal }); |
| 1524 | + const promise = convertInternalToExpanded(internal, { signal: abortController.signal }); |
1511 | 1525 | abortController.abort(new Error('Too long, didn\'t wait.'));
|
1512 | 1526 | await assert.rejects(promise, {
|
1513 | 1527 | name: 'Error',
|
|
0 commit comments