Skip to content

Commit ad2c5bb

Browse files
committed
Merge remote-tracking branch 'origin/master' into compass-4513-shell-runtime-worker-thread
2 parents da3b686 + a76f2f9 commit ad2c5bb

29 files changed

+412
-182
lines changed

packages/autocomplete/index.spec.ts

Lines changed: 89 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ import { signatures as shellSignatures, Topologies } from '@mongosh/shell-api';
33

44
import { expect } from 'chai';
55

6+
let collections: string[];
67
const standalone440 = {
78
topology: () => Topologies.Standalone,
89
connectionInfo: () => ({
910
is_atlas: false,
1011
is_data_lake: false,
1112
server_version: '4.4.0'
12-
})
13+
}),
14+
getCollectionCompletionsForCurrentDb: () => collections
1315
};
1416
const sharded440 = {
1517
topology: () => Topologies.Sharded,
1618
connectionInfo: () => ({
1719
is_atlas: false,
1820
is_data_lake: false,
1921
server_version: '4.4.0'
20-
})
22+
}),
23+
getCollectionCompletionsForCurrentDb: () => collections
2124
};
2225

2326
const standalone300 = {
@@ -26,44 +29,51 @@ const standalone300 = {
2629
is_atlas: false,
2730
is_data_lake: false,
2831
server_version: '3.0.0'
29-
})
32+
}),
33+
getCollectionCompletionsForCurrentDb: () => collections
3034
};
3135
const datalake440 = {
3236
topology: () => Topologies.Sharded,
3337
connectionInfo: () => ({
3438
is_atlas: true,
3539
is_data_lake: true,
3640
server_version: '4.4.0'
37-
})
41+
}),
42+
getCollectionCompletionsForCurrentDb: () => collections
3843
};
3944

4045
const noParams = {
4146
topology: () => Topologies.Standalone,
42-
connectionInfo: () => undefined
47+
connectionInfo: () => undefined,
48+
getCollectionCompletionsForCurrentDb: () => collections
4349
};
4450

4551
describe('completer.completer', () => {
52+
beforeEach(() => {
53+
collections = [];
54+
});
55+
4656
context('when context is top level shell api', () => {
47-
it('matches shell completions', () => {
57+
it('matches shell completions', async() => {
4858
const i = 'u';
49-
expect(completer(standalone440, i)).to.deep.equal([['use'], i]);
59+
expect(await completer(standalone440, i)).to.deep.equal([['use'], i]);
5060
});
5161

52-
it('does not have a match', () => {
62+
it('does not have a match', async() => {
5363
const i = 'ad';
54-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
64+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
5565
});
5666

57-
it('is an exact match to one of shell completions', () => {
67+
it('is an exact match to one of shell completions', async() => {
5868
const i = 'use';
59-
expect(completer(standalone440, i)).to.deep.equal([[i], i]);
69+
expect(await completer(standalone440, i)).to.deep.equal([[i], i]);
6070
});
6171
});
6272

6373
context('when no version is passed to completer', () => {
64-
it('matches all db completions', () => {
74+
it('matches all db completions', async() => {
6575
const i = 'db.';
66-
const c = completer(noParams, i);
76+
const c = await completer(noParams, i);
6777
expect(c.length).to.equal(2);
6878
expect(c[1]).to.equal(i);
6979
expect(c[0]).to.include.members([
@@ -103,16 +113,16 @@ describe('completer.completer', () => {
103113
]);
104114
});
105115

106-
it('does not have a match', () => {
116+
it('does not have a match', async() => {
107117
const i = 'db.shipwrecks.aggregate([ { $so';
108-
expect(completer(noParams, i)).to.deep.equal([
118+
expect(await completer(noParams, i)).to.deep.equal([
109119
['db.shipwrecks.aggregate([ { $sort',
110120
'db.shipwrecks.aggregate([ { $sortByCount'], i]);
111121
});
112122

113-
it('is an exact match to one of shell completions', () => {
123+
it('is an exact match to one of shell completions', async() => {
114124
const i = 'db.bios.find({ field: { $exis';
115-
expect(completer(noParams, i))
125+
expect(await completer(noParams, i))
116126
.to.deep.equal([['db.bios.find({ field: { $exists'], i]);
117127
});
118128
});
@@ -137,23 +147,23 @@ describe('completer.completer', () => {
137147
BASE_COMPLETIONS.splice(0, BASE_COMPLETIONS.length, ...origBaseCompletions);
138148
});
139149

140-
it('includes them when not connected', () => {
150+
it('includes them when not connected', async() => {
141151
const i = 'db.shipwrecks.aggregate([ { $sq';
142-
expect(completer(noParams, i)).to.deep.equal([
152+
expect(await completer(noParams, i)).to.deep.equal([
143153
['db.shipwrecks.aggregate([ { $sqrt',
144154
'db.shipwrecks.aggregate([ { $sql'], i]);
145155
});
146156

147-
it('includes them when connected to DataLake', () => {
157+
it('includes them when connected to DataLake', async() => {
148158
const i = 'db.shipwrecks.aggregate([ { $sq';
149-
expect(completer(datalake440, i)).to.deep.equal([
159+
expect(await completer(datalake440, i)).to.deep.equal([
150160
['db.shipwrecks.aggregate([ { $sqrt',
151161
'db.shipwrecks.aggregate([ { $sql'], i]);
152162
});
153163

154-
it('does not include them when connected to a standalone node', () => {
164+
it('does not include them when connected to a standalone node', async() => {
155165
const i = 'db.shipwrecks.aggregate([ { $sq';
156-
expect(completer(standalone440, i)).to.deep.equal([
166+
expect(await completer(standalone440, i)).to.deep.equal([
157167
['db.shipwrecks.aggregate([ { $sqrt'], i]);
158168
});
159169
});
@@ -162,21 +172,21 @@ describe('completer.completer', () => {
162172
// this should eventually encompass tests for DATABASE commands and
163173
// COLLECTION names.
164174
// for now, this will only return the current input.
165-
it('matches a database command', () => {
175+
it('matches a database command', async() => {
166176
const i = 'db.agg';
167-
expect(completer(standalone440, i)).to.deep.equal([['db.aggregate'], i]);
177+
expect(await completer(standalone440, i)).to.deep.equal([['db.aggregate'], i]);
168178
});
169179

170-
it('returns all suggestions', () => {
180+
it('returns all suggestions', async() => {
171181
const i = 'db.';
172182
const dbComplete = Object.keys(shellSignatures.Database.attributes as any);
173183
const adjusted = dbComplete.map(c => `${i}${c}`);
174-
expect(completer(noParams, i)).to.deep.equal([adjusted, i]);
184+
expect(await completer(noParams, i)).to.deep.equal([adjusted, i]);
175185
});
176186

177-
it('matches several suggestions', () => {
187+
it('matches several suggestions', async() => {
178188
const i = 'db.get';
179-
expect(completer(standalone440, i)[0]).to.include.members(
189+
expect((await completer(standalone440, i))[0]).to.include.members(
180190
[
181191
'db.getCollectionNames',
182192
'db.getCollection',
@@ -185,70 +195,76 @@ describe('completer.completer', () => {
185195
]);
186196
});
187197

188-
it('returns current input and no suggestions', () => {
198+
it('returns current input and no suggestions', async() => {
199+
const i = 'db.shipw';
200+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
201+
});
202+
203+
it('includes collection names', async() => {
204+
collections = ['shipwrecks'];
189205
const i = 'db.shipw';
190-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
206+
expect(await completer(standalone440, i)).to.deep.equal([['db.shipwrecks'], i]);
191207
});
192208
});
193209

194210
context('when context is collections', () => {
195-
it('matches a collection command', () => {
211+
it('matches a collection command', async() => {
196212
const i = 'db.shipwrecks.findAnd';
197-
expect(completer(standalone440, i)).to.deep.equal([['db.shipwrecks.findAndModify'], i]);
213+
expect(await completer(standalone440, i)).to.deep.equal([['db.shipwrecks.findAndModify'], i]);
198214
});
199215

200-
it('matches a collection command if part of an expression', () => {
216+
it('matches a collection command if part of an expression', async() => {
201217
const i = 'var result = db.shipwrecks.findAnd';
202-
expect(completer(standalone440, i)).to.deep.equal([['var result = db.shipwrecks.findAndModify'], i]);
218+
expect(await completer(standalone440, i)).to.deep.equal([['var result = db.shipwrecks.findAndModify'], i]);
203219
});
204220

205-
it('returns all suggestions', () => {
221+
it('returns all suggestions', async() => {
206222
const i = 'db.shipwrecks.';
207223
const collComplete = Object.keys(shellSignatures.Collection.attributes as any);
208224
const adjusted = collComplete.filter(c => !['count', 'update', 'remove'].includes(c)).map(c => `${i}${c}`);
209225

210-
expect(completer(sharded440, i)).to.deep.equal([adjusted, i]);
226+
expect(await completer(sharded440, i)).to.deep.equal([adjusted, i]);
211227
});
212228

213-
it('matches several collection commands', () => {
229+
it('matches several collection commands', async() => {
214230
const i = 'db.shipwrecks.find';
215-
expect(completer(standalone440, i)).to.deep.equal([
231+
expect(await completer(standalone440, i)).to.deep.equal([
216232
[
217233
'db.shipwrecks.find', 'db.shipwrecks.findAndModify',
218234
'db.shipwrecks.findOne', 'db.shipwrecks.findOneAndDelete',
219235
'db.shipwrecks.findOneAndReplace', 'db.shipwrecks.findOneAndUpdate'
220236
], i]);
221237
});
222238

223-
it('does not have a match', () => {
239+
it('does not have a match', async() => {
224240
const i = 'db.shipwrecks.pr';
225-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
241+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
226242
});
227243
});
228244

229245
context('when context is collections and aggregation cursor', () => {
230-
it('matches an aggregation cursor command', () => {
246+
it('matches an aggregation cursor command', async() => {
231247
const i = 'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).has';
232-
expect(completer(standalone440, i)).to.deep.equal([
248+
expect(await completer(standalone440, i)).to.deep.equal([
233249
['db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).hasNext'], i]);
234250
});
235251

236-
it('returns all suggestions', () => {
252+
it('returns all suggestions', async() => {
237253
const i = 'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).';
238254
const aggCursorComplete = Object.keys(shellSignatures.AggregationCursor.attributes as any);
239255
const adjusted = aggCursorComplete.map(c => `${i}${c}`);
240256

241-
expect(completer(standalone440, i)).to.deep.equal([adjusted, i]);
257+
expect(await completer(standalone440, i)).to.deep.equal([adjusted, i]);
242258
});
243259

244-
it('does not have a match', () => {
260+
it('does not have a match', async() => {
245261
const i = 'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).w';
246-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
262+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
247263
});
248264

249-
it('has several matches', () => {
265+
it('has several matches', async() => {
250266
const i = 'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).i';
251-
expect(completer(standalone440, i)).to.deep.equal([
267+
expect(await completer(standalone440, i)).to.deep.equal([
252268
[
253269
'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).isClosed',
254270
'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).isExhausted',
@@ -258,29 +274,29 @@ describe('completer.completer', () => {
258274
});
259275

260276
context('when context is aggregation query', () => {
261-
it('has several matches', () => {
277+
it('has several matches', async() => {
262278
const i = 'db.shipwrecks.aggregate([ { $so';
263-
expect(completer(standalone440, i)).to.deep.equal([
279+
expect(await completer(standalone440, i)).to.deep.equal([
264280
['db.shipwrecks.aggregate([ { $sort',
265281
'db.shipwrecks.aggregate([ { $sortByCount'], i]);
266282
});
267283

268-
it('does not have a match', () => {
284+
it('does not have a match', async() => {
269285
const i = 'db.shipwrecks.aggregate([ { $cat';
270-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
286+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
271287
});
272288

273-
it('matches an aggregation stage', () => {
289+
it('matches an aggregation stage', async() => {
274290
const i = 'db.shipwrecks.aggregate([ { $proj';
275-
expect(completer(standalone440, i)).to.deep.equal([
291+
expect(await completer(standalone440, i)).to.deep.equal([
276292
[ 'db.shipwrecks.aggregate([ { $project' ], i]);
277293
});
278294
});
279295

280296
context('when context is a collection query', () => {
281-
it('returns all suggestions', () => {
297+
it('returns all suggestions', async() => {
282298
const i = 'db.shipwrecks.find({ ';
283-
expect(completer(standalone440, i)[0]).to.include.members(
299+
expect((await completer(standalone440, i))[0]).to.include.members(
284300
[ 'db.shipwrecks.find({ $all',
285301
'db.shipwrecks.find({ $and',
286302
'db.shipwrecks.find({ $bitsAllClear',
@@ -328,9 +344,9 @@ describe('completer.completer', () => {
328344
'db.shipwrecks.find({ RegExp' ]);
329345
});
330346

331-
it('has several matches', () => {
347+
it('has several matches', async() => {
332348
const i = 'db.bios.find({ birth: { $g';
333-
expect(completer(standalone440, i)).to.deep.equal([
349+
expect(await completer(standalone440, i)).to.deep.equal([
334350
[
335351
'db.bios.find({ birth: { $geoIntersects',
336352
'db.bios.find({ birth: { $geoWithin',
@@ -339,26 +355,26 @@ describe('completer.completer', () => {
339355
], i]);
340356
});
341357

342-
it('does not have a match', () => {
358+
it('does not have a match', async() => {
343359
const i = 'db.bios.find({ field: { $cat';
344-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
360+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
345361
});
346362

347-
it('matches an aggregation stage', () => {
363+
it('matches an aggregation stage', async() => {
348364
const i = 'db.bios.find({ field: { $exis';
349-
expect(completer(standalone440, i)).to.deep.equal([
365+
expect(await completer(standalone440, i)).to.deep.equal([
350366
[ 'db.bios.find({ field: { $exists' ], i]);
351367
});
352368
});
353369

354370
context('when context is collections and collection cursor', () => {
355-
it('matches a collection cursor command', () => {
371+
it('matches a collection cursor command', async() => {
356372
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).for';
357-
expect(completer(standalone440, i)).to.deep.equal([
373+
expect(await completer(standalone440, i)).to.deep.equal([
358374
['db.shipwrecks.find({feature_type: "Wrecks - Visible"}).forEach'], i]);
359375
});
360376

361-
it('returns all suggestions running on 4.4.0 version', () => {
377+
it('returns all suggestions running on 4.4.0 version', async() => {
362378
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).';
363379

364380
const result = [
@@ -397,10 +413,10 @@ describe('completer.completer', () => {
397413
'db.shipwrecks.find({feature_type: \"Wrecks - Visible\"}).readConcern',
398414
];
399415

400-
expect(completer(standalone440, i)[0]).to.include.members(result);
416+
expect((await completer(standalone440, i))[0]).to.include.members(result);
401417
});
402418

403-
it('returns all suggestions matching 3.0.0 version', () => {
419+
it('returns all suggestions matching 3.0.0 version', async() => {
404420
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).';
405421

406422
const result = [
@@ -432,17 +448,17 @@ describe('completer.completer', () => {
432448
'db.shipwrecks.find({feature_type: \"Wrecks - Visible\"}).toArray',
433449
];
434450

435-
expect(completer(standalone300, i)[0]).to.include.members(result);
451+
expect((await completer(standalone300, i))[0]).to.include.members(result);
436452
});
437453

438-
it('does not have a match', () => {
454+
it('does not have a match', async() => {
439455
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).gre';
440-
expect(completer(standalone440, i)).to.deep.equal([[], i]);
456+
expect(await completer(standalone440, i)).to.deep.equal([[], i]);
441457
});
442458

443-
it('has several matches', () => {
459+
it('has several matches', async() => {
444460
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).cl';
445-
expect(completer(standalone440, i)).to.deep.equal([
461+
expect(await completer(standalone440, i)).to.deep.equal([
446462
[
447463
'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).close'
448464
], i]);

0 commit comments

Comments
 (0)