Skip to content

Commit 0ce95c3

Browse files
committed
more unit tests
1 parent a93b8fd commit 0ce95c3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/shell-api/src/deep-inspect-service-provider-wrapper.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { StubbedInstance } from 'ts-sinon';
88
import { stubInterface } from 'ts-sinon';
99
import { DeepInspectServiceProviderWrapper } from './deep-inspect-service-provider-wrapper';
1010
import * as util from 'util';
11+
import { makePrintableBson } from '@mongosh/shell-bson';
12+
1113
chai.use(sinonChai);
1214

1315
const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom');
@@ -31,6 +33,10 @@ describe('DeepInspectServiceProviderWrapper', function () {
3133
let serviceProvider: StubbedInstance<ServiceProvider>;
3234
let sp: DeepInspectServiceProviderWrapper;
3335

36+
// make the tests behave the same regardless of whether this file was focused
37+
// or not
38+
makePrintableBson(bson);
39+
3440
const doc = {
3541
array: Array.from(Array(1000), (_, i) => i),
3642
string: 'All work and no play makes Jack a dull boy. '.repeat(250),
@@ -107,6 +113,45 @@ describe('DeepInspectServiceProviderWrapper', function () {
107113
),
108114
};
109115

116+
function checkResultEveryType(result: any) {
117+
expect(result).to.deep.equal(everyType);
118+
expect(wasTruncated(util.inspect(result))).to.equal(false);
119+
120+
// this makes sure that we didn't accidentally mess with the custom inspect
121+
// methods of the BSON types, dates, regexes or simple values
122+
expect(util.inspect(result)).to.equal(`{
123+
double: Double(1.2),
124+
doubleThatIsAlsoAnInteger: Double(1),
125+
string: 'Hello, world!',
126+
binData: Binary.createFromBase64('AQID', 0),
127+
boolean: true,
128+
date: 2023-04-05T13:25:08.445Z,
129+
null: null,
130+
regex: BSONRegExp('pattern', 'i'),
131+
javascript: Code('function() {}'),
132+
symbol: BSONSymbol('symbol'),
133+
javascriptWithScope: Code('function() {}', { foo: 1, bar: 'a' }),
134+
int: Int32(12345),
135+
timestamp: Timestamp({ t: 1680701109, i: 1 }),
136+
long: Long('123456789123456789'),
137+
decimal: Decimal128('5.477284286264328586719275128128001E-4088'),
138+
minKey: MinKey(),
139+
maxKey: MaxKey(),
140+
binaries: {
141+
generic: Binary.createFromBase64('AQID', 0),
142+
functionData: Binary.createFromBase64('Ly84PQ==', 1),
143+
binaryOld: Binary.createFromBase64('Ly84PQ==', 2),
144+
uuidOld: Binary.createFromBase64('Yy8vU1pFU3pUR21RNk9mUjM4QTExQT09', 3),
145+
uuid: UUID('aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaaaa'),
146+
md5: MD5('632f2f535a45537a54476d51364f66523338413131413d3d'),
147+
encrypted: Binary.createFromBase64('Yy8vU1pFU3pUR21RNk9mUjM4QTExQT09', 6),
148+
compressedTimeSeries: Binary.createFromBase64('CQCKW/8XjAEAAIfx//////////H/////////AQAAAAAAAABfAAAAAAAAAAEAAAAAAAAAAgAAAAAAAAAHAAAAAAAAAA4AAAAAAAAAAA==', 0),
149+
custom: Binary.createFromBase64('Ly84PQ==', 128)
150+
},
151+
dbRef: DBRef('namespace', ObjectId('642d76b4b7ebfab15d3c4a78'))
152+
}`);
153+
}
154+
110155
beforeEach(function () {
111156
serviceProvider = stubInterface<ServiceProvider>();
112157
serviceProvider.initialDb = 'db1';
@@ -166,10 +211,12 @@ describe('DeepInspectServiceProviderWrapper', function () {
166211
const toArrayResult = await cursor.toArray();
167212
expect(toArrayResult).to.deep.equal([doc, everyType]);
168213
checkResultDoc(toArrayResult[0]);
214+
checkResultEveryType(toArrayResult[1]);
169215

170216
const readBufferedDocumentsResult = cursor.readBufferedDocuments();
171217
expect(readBufferedDocumentsResult).to.deep.equal([doc, everyType]);
172218
checkResultDoc(readBufferedDocumentsResult[0]);
219+
checkResultEveryType(readBufferedDocumentsResult[1]);
173220
});
174221

175222
it('wraps aggregation cursors', async function () {
@@ -202,9 +249,11 @@ describe('DeepInspectServiceProviderWrapper', function () {
202249

203250
const toArrayResult = await cursor.toArray();
204251
checkResultDoc(toArrayResult[0]);
252+
checkResultEveryType(toArrayResult[1]);
205253

206254
const readBufferedDocumentsResult = cursor.readBufferedDocuments();
207255
checkResultDoc(readBufferedDocumentsResult[0]);
256+
checkResultEveryType(readBufferedDocumentsResult[1]);
208257
});
209258

210259
it('wraps run command cursors', async function () {
@@ -234,10 +283,12 @@ describe('DeepInspectServiceProviderWrapper', function () {
234283
const toArrayResult = await cursor.toArray();
235284
expect(toArrayResult).to.deep.equal([doc, everyType]);
236285
checkResultDoc(toArrayResult[0]);
286+
checkResultEveryType(toArrayResult[1]);
237287

238288
const readBufferedDocumentsResult = cursor.readBufferedDocuments();
239289
expect(readBufferedDocumentsResult).to.deep.equal([doc, everyType]);
240290
checkResultDoc(readBufferedDocumentsResult[0]);
291+
checkResultEveryType(readBufferedDocumentsResult[1]);
241292
});
242293

243294
it('wraps change streams', async function () {

0 commit comments

Comments
 (0)