Skip to content

Commit fc58269

Browse files
Anemylerouxb
andauthored
chore(playgrounds): add all types playground for type testing (#462)
* add all types playground for type testing * better field names for types * DBRef is not the same as DBPointer Co-authored-by: Le Roux Bodenstein <[email protected]>
1 parent b997af6 commit fc58269

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { Buffer } = require('node:buffer');
2+
3+
use('test');
4+
5+
// Create a document with all the BSON types.
6+
const doc = {
7+
double: new Double(1.2), // Double, 1, double
8+
string: 'Hello, world!', // String, 2, string
9+
object: { key: 'value' }, // Object, 3, object
10+
array: [1, 2, 3], // Array, 4, array
11+
binData: new Binary(Buffer.from([1, 2, 3])), // Binary data, 5, binData
12+
// Undefined, 6, undefined (deprecated)
13+
objectId: new ObjectId(), // ObjectId, 7, objectId
14+
boolean: true, // Boolean, 8, boolean
15+
date: new Date(), // Date, 9, date
16+
null: null, // Null, 10, null
17+
regex: new BSONRegExp('pattern', 'i'), // Regular Expression, 11, regex
18+
// DBPointer, 12, dbPointer (deprecated)
19+
javascript: new Code('function() {}'), // JavaScript, 13, javascript
20+
symbol: new BSONSymbol('symbol'), // Symbol, 14, symbol (deprecated)
21+
javascriptWithScope: new Code('function() {}', { foo: 1, bar: 'a' }), // JavaScript code with scope 15 "javascriptWithScope" Deprecated in MongoDB 4.4.
22+
int: new Int32(12345), // 32-bit integer, 16, "int"
23+
timestamp: new Timestamp(), // Timestamp, 17, timestamp
24+
long: new Long('123456789123456789'), // 64-bit integer, 18, long
25+
decimal: new Decimal128(Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])), // Decimal128, 19, decimal
26+
minKey: new MinKey(), // Min key, -1, minKey
27+
maxKey: new MaxKey(), // Max key, 127, maxKey
28+
29+
binDataSubtypes: {
30+
generic: new Binary(Buffer.from([1, 2, 3]), 0), // 0
31+
functionData: new Binary('//8=', 1), // 1
32+
binaryOld: new Binary('//8=', 2), // 2
33+
uuidOld: new Binary('c//SZESzTGmQ6OfR38A11A==', 3), // 3
34+
uuid: new UUID('AAAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA'), // 4
35+
md5: new Binary('c//SZESzTGmQ6OfR38A11A==', 5), // 5
36+
encrypted: new Binary('c//SZESzTGmQ6OfR38A11A==', 6), // 6
37+
compressedTimeSeries: new Binary('c//SZESzTGmQ6OfR38A11A==', 0), // 7
38+
custom: new Binary('//8=', 128), // 128
39+
},
40+
41+
dbRef: new DBRef('namespace', new ObjectId()), // not actually a separate type, just a convention
42+
};
43+
44+
// Insert the document into the `all_types` collection.
45+
db.all_types.insertOne(doc);

src/test/suite/explorer/playgroundsExplorer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ suite('Playgrounds Controller Test Suite', function () {
5454
try {
5555
const children = await treeController.getPlaygrounds(rootUri);
5656

57-
assert.strictEqual(Object.keys(children).length, 6);
57+
assert.strictEqual(Object.keys(children).length, 7);
5858

5959
const playgrounds = Object.values(children).filter(
6060
(item: any) => item.label && item.label.split('.').pop() === 'mongodb'
6161
);
6262

63-
assert.strictEqual(Object.keys(playgrounds).length, 6);
63+
assert.strictEqual(Object.keys(playgrounds).length, 7);
6464
} catch (error) {
6565
assert(false, error as Error);
6666
}

0 commit comments

Comments
 (0)