@@ -3,21 +3,24 @@ import { signatures as shellSignatures, Topologies } from '@mongosh/shell-api';
3
3
4
4
import { expect } from 'chai' ;
5
5
6
+ let collections : string [ ] ;
6
7
const standalone440 = {
7
8
topology : ( ) => Topologies . Standalone ,
8
9
connectionInfo : ( ) => ( {
9
10
is_atlas : false ,
10
11
is_data_lake : false ,
11
12
server_version : '4.4.0'
12
- } )
13
+ } ) ,
14
+ getCollectionCompletionsForCurrentDb : ( ) => collections
13
15
} ;
14
16
const sharded440 = {
15
17
topology : ( ) => Topologies . Sharded ,
16
18
connectionInfo : ( ) => ( {
17
19
is_atlas : false ,
18
20
is_data_lake : false ,
19
21
server_version : '4.4.0'
20
- } )
22
+ } ) ,
23
+ getCollectionCompletionsForCurrentDb : ( ) => collections
21
24
} ;
22
25
23
26
const standalone300 = {
@@ -26,44 +29,51 @@ const standalone300 = {
26
29
is_atlas : false ,
27
30
is_data_lake : false ,
28
31
server_version : '3.0.0'
29
- } )
32
+ } ) ,
33
+ getCollectionCompletionsForCurrentDb : ( ) => collections
30
34
} ;
31
35
const datalake440 = {
32
36
topology : ( ) => Topologies . Sharded ,
33
37
connectionInfo : ( ) => ( {
34
38
is_atlas : true ,
35
39
is_data_lake : true ,
36
40
server_version : '4.4.0'
37
- } )
41
+ } ) ,
42
+ getCollectionCompletionsForCurrentDb : ( ) => collections
38
43
} ;
39
44
40
45
const noParams = {
41
46
topology : ( ) => Topologies . Standalone ,
42
- connectionInfo : ( ) => undefined
47
+ connectionInfo : ( ) => undefined ,
48
+ getCollectionCompletionsForCurrentDb : ( ) => collections
43
49
} ;
44
50
45
51
describe ( 'completer.completer' , ( ) => {
52
+ beforeEach ( ( ) => {
53
+ collections = [ ] ;
54
+ } ) ;
55
+
46
56
context ( 'when context is top level shell api' , ( ) => {
47
- it ( 'matches shell completions' , ( ) => {
57
+ it ( 'matches shell completions' , async ( ) => {
48
58
const i = 'u' ;
49
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [ [ 'use' ] , i ] ) ;
59
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ 'use' ] , i ] ) ;
50
60
} ) ;
51
61
52
- it ( 'does not have a match' , ( ) => {
62
+ it ( 'does not have a match' , async ( ) => {
53
63
const i = 'ad' ;
54
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [ [ ] , i ] ) ;
64
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ ] , i ] ) ;
55
65
} ) ;
56
66
57
- it ( 'is an exact match to one of shell completions' , ( ) => {
67
+ it ( 'is an exact match to one of shell completions' , async ( ) => {
58
68
const i = 'use' ;
59
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [ [ i ] , i ] ) ;
69
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ i ] , i ] ) ;
60
70
} ) ;
61
71
} ) ;
62
72
63
73
context ( 'when no version is passed to completer' , ( ) => {
64
- it ( 'matches all db completions' , ( ) => {
74
+ it ( 'matches all db completions' , async ( ) => {
65
75
const i = 'db.' ;
66
- const c = completer ( noParams , i ) ;
76
+ const c = await completer ( noParams , i ) ;
67
77
expect ( c . length ) . to . equal ( 2 ) ;
68
78
expect ( c [ 1 ] ) . to . equal ( i ) ;
69
79
expect ( c [ 0 ] ) . to . include . members ( [
@@ -103,16 +113,16 @@ describe('completer.completer', () => {
103
113
] ) ;
104
114
} ) ;
105
115
106
- it ( 'does not have a match' , ( ) => {
116
+ it ( 'does not have a match' , async ( ) => {
107
117
const i = 'db.shipwrecks.aggregate([ { $so' ;
108
- expect ( completer ( noParams , i ) ) . to . deep . equal ( [
118
+ expect ( await completer ( noParams , i ) ) . to . deep . equal ( [
109
119
[ 'db.shipwrecks.aggregate([ { $sort' ,
110
120
'db.shipwrecks.aggregate([ { $sortByCount' ] , i ] ) ;
111
121
} ) ;
112
122
113
- it ( 'is an exact match to one of shell completions' , ( ) => {
123
+ it ( 'is an exact match to one of shell completions' , async ( ) => {
114
124
const i = 'db.bios.find({ field: { $exis' ;
115
- expect ( completer ( noParams , i ) )
125
+ expect ( await completer ( noParams , i ) )
116
126
. to . deep . equal ( [ [ 'db.bios.find({ field: { $exists' ] , i ] ) ;
117
127
} ) ;
118
128
} ) ;
@@ -137,23 +147,23 @@ describe('completer.completer', () => {
137
147
BASE_COMPLETIONS . splice ( 0 , BASE_COMPLETIONS . length , ...origBaseCompletions ) ;
138
148
} ) ;
139
149
140
- it ( 'includes them when not connected' , ( ) => {
150
+ it ( 'includes them when not connected' , async ( ) => {
141
151
const i = 'db.shipwrecks.aggregate([ { $sq' ;
142
- expect ( completer ( noParams , i ) ) . to . deep . equal ( [
152
+ expect ( await completer ( noParams , i ) ) . to . deep . equal ( [
143
153
[ 'db.shipwrecks.aggregate([ { $sqrt' ,
144
154
'db.shipwrecks.aggregate([ { $sql' ] , i ] ) ;
145
155
} ) ;
146
156
147
- it ( 'includes them when connected to DataLake' , ( ) => {
157
+ it ( 'includes them when connected to DataLake' , async ( ) => {
148
158
const i = 'db.shipwrecks.aggregate([ { $sq' ;
149
- expect ( completer ( datalake440 , i ) ) . to . deep . equal ( [
159
+ expect ( await completer ( datalake440 , i ) ) . to . deep . equal ( [
150
160
[ 'db.shipwrecks.aggregate([ { $sqrt' ,
151
161
'db.shipwrecks.aggregate([ { $sql' ] , i ] ) ;
152
162
} ) ;
153
163
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 ( ) => {
155
165
const i = 'db.shipwrecks.aggregate([ { $sq' ;
156
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [
166
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [
157
167
[ 'db.shipwrecks.aggregate([ { $sqrt' ] , i ] ) ;
158
168
} ) ;
159
169
} ) ;
@@ -162,21 +172,21 @@ describe('completer.completer', () => {
162
172
// this should eventually encompass tests for DATABASE commands and
163
173
// COLLECTION names.
164
174
// for now, this will only return the current input.
165
- it ( 'matches a database command' , ( ) => {
175
+ it ( 'matches a database command' , async ( ) => {
166
176
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 ] ) ;
168
178
} ) ;
169
179
170
- it ( 'returns all suggestions' , ( ) => {
180
+ it ( 'returns all suggestions' , async ( ) => {
171
181
const i = 'db.' ;
172
182
const dbComplete = Object . keys ( shellSignatures . Database . attributes as any ) ;
173
183
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 ] ) ;
175
185
} ) ;
176
186
177
- it ( 'matches several suggestions' , ( ) => {
187
+ it ( 'matches several suggestions' , async ( ) => {
178
188
const i = 'db.get' ;
179
- expect ( completer ( standalone440 , i ) [ 0 ] ) . to . include . members (
189
+ expect ( ( await completer ( standalone440 , i ) ) [ 0 ] ) . to . include . members (
180
190
[
181
191
'db.getCollectionNames' ,
182
192
'db.getCollection' ,
@@ -185,70 +195,76 @@ describe('completer.completer', () => {
185
195
] ) ;
186
196
} ) ;
187
197
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' ] ;
189
205
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 ] ) ;
191
207
} ) ;
192
208
} ) ;
193
209
194
210
context ( 'when context is collections' , ( ) => {
195
- it ( 'matches a collection command' , ( ) => {
211
+ it ( 'matches a collection command' , async ( ) => {
196
212
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 ] ) ;
198
214
} ) ;
199
215
200
- it ( 'matches a collection command if part of an expression' , ( ) => {
216
+ it ( 'matches a collection command if part of an expression' , async ( ) => {
201
217
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 ] ) ;
203
219
} ) ;
204
220
205
- it ( 'returns all suggestions' , ( ) => {
221
+ it ( 'returns all suggestions' , async ( ) => {
206
222
const i = 'db.shipwrecks.' ;
207
223
const collComplete = Object . keys ( shellSignatures . Collection . attributes as any ) ;
208
224
const adjusted = collComplete . filter ( c => ! [ 'count' , 'update' , 'remove' ] . includes ( c ) ) . map ( c => `${ i } ${ c } ` ) ;
209
225
210
- expect ( completer ( sharded440 , i ) ) . to . deep . equal ( [ adjusted , i ] ) ;
226
+ expect ( await completer ( sharded440 , i ) ) . to . deep . equal ( [ adjusted , i ] ) ;
211
227
} ) ;
212
228
213
- it ( 'matches several collection commands' , ( ) => {
229
+ it ( 'matches several collection commands' , async ( ) => {
214
230
const i = 'db.shipwrecks.find' ;
215
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [
231
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [
216
232
[
217
233
'db.shipwrecks.find' , 'db.shipwrecks.findAndModify' ,
218
234
'db.shipwrecks.findOne' , 'db.shipwrecks.findOneAndDelete' ,
219
235
'db.shipwrecks.findOneAndReplace' , 'db.shipwrecks.findOneAndUpdate'
220
236
] , i ] ) ;
221
237
} ) ;
222
238
223
- it ( 'does not have a match' , ( ) => {
239
+ it ( 'does not have a match' , async ( ) => {
224
240
const i = 'db.shipwrecks.pr' ;
225
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [ [ ] , i ] ) ;
241
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ ] , i ] ) ;
226
242
} ) ;
227
243
} ) ;
228
244
229
245
context ( 'when context is collections and aggregation cursor' , ( ) => {
230
- it ( 'matches an aggregation cursor command' , ( ) => {
246
+ it ( 'matches an aggregation cursor command' , async ( ) => {
231
247
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 ( [
233
249
[ 'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).hasNext' ] , i ] ) ;
234
250
} ) ;
235
251
236
- it ( 'returns all suggestions' , ( ) => {
252
+ it ( 'returns all suggestions' , async ( ) => {
237
253
const i = 'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).' ;
238
254
const aggCursorComplete = Object . keys ( shellSignatures . AggregationCursor . attributes as any ) ;
239
255
const adjusted = aggCursorComplete . map ( c => `${ i } ${ c } ` ) ;
240
256
241
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [ adjusted , i ] ) ;
257
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ adjusted , i ] ) ;
242
258
} ) ;
243
259
244
- it ( 'does not have a match' , ( ) => {
260
+ it ( 'does not have a match' , async ( ) => {
245
261
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 ] ) ;
247
263
} ) ;
248
264
249
- it ( 'has several matches' , ( ) => {
265
+ it ( 'has several matches' , async ( ) => {
250
266
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 ( [
252
268
[
253
269
'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).isClosed' ,
254
270
'db.shipwrecks.aggregate([{$sort: {feature_type: 1}}]).isExhausted' ,
@@ -258,29 +274,29 @@ describe('completer.completer', () => {
258
274
} ) ;
259
275
260
276
context ( 'when context is aggregation query' , ( ) => {
261
- it ( 'has several matches' , ( ) => {
277
+ it ( 'has several matches' , async ( ) => {
262
278
const i = 'db.shipwrecks.aggregate([ { $so' ;
263
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [
279
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [
264
280
[ 'db.shipwrecks.aggregate([ { $sort' ,
265
281
'db.shipwrecks.aggregate([ { $sortByCount' ] , i ] ) ;
266
282
} ) ;
267
283
268
- it ( 'does not have a match' , ( ) => {
284
+ it ( 'does not have a match' , async ( ) => {
269
285
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 ] ) ;
271
287
} ) ;
272
288
273
- it ( 'matches an aggregation stage' , ( ) => {
289
+ it ( 'matches an aggregation stage' , async ( ) => {
274
290
const i = 'db.shipwrecks.aggregate([ { $proj' ;
275
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [
291
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [
276
292
[ 'db.shipwrecks.aggregate([ { $project' ] , i ] ) ;
277
293
} ) ;
278
294
} ) ;
279
295
280
296
context ( 'when context is a collection query' , ( ) => {
281
- it ( 'returns all suggestions' , ( ) => {
297
+ it ( 'returns all suggestions' , async ( ) => {
282
298
const i = 'db.shipwrecks.find({ ' ;
283
- expect ( completer ( standalone440 , i ) [ 0 ] ) . to . include . members (
299
+ expect ( ( await completer ( standalone440 , i ) ) [ 0 ] ) . to . include . members (
284
300
[ 'db.shipwrecks.find({ $all' ,
285
301
'db.shipwrecks.find({ $and' ,
286
302
'db.shipwrecks.find({ $bitsAllClear' ,
@@ -328,9 +344,9 @@ describe('completer.completer', () => {
328
344
'db.shipwrecks.find({ RegExp' ] ) ;
329
345
} ) ;
330
346
331
- it ( 'has several matches' , ( ) => {
347
+ it ( 'has several matches' , async ( ) => {
332
348
const i = 'db.bios.find({ birth: { $g' ;
333
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [
349
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [
334
350
[
335
351
'db.bios.find({ birth: { $geoIntersects' ,
336
352
'db.bios.find({ birth: { $geoWithin' ,
@@ -339,26 +355,26 @@ describe('completer.completer', () => {
339
355
] , i ] ) ;
340
356
} ) ;
341
357
342
- it ( 'does not have a match' , ( ) => {
358
+ it ( 'does not have a match' , async ( ) => {
343
359
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 ] ) ;
345
361
} ) ;
346
362
347
- it ( 'matches an aggregation stage' , ( ) => {
363
+ it ( 'matches an aggregation stage' , async ( ) => {
348
364
const i = 'db.bios.find({ field: { $exis' ;
349
- expect ( completer ( standalone440 , i ) ) . to . deep . equal ( [
365
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [
350
366
[ 'db.bios.find({ field: { $exists' ] , i ] ) ;
351
367
} ) ;
352
368
} ) ;
353
369
354
370
context ( 'when context is collections and collection cursor' , ( ) => {
355
- it ( 'matches a collection cursor command' , ( ) => {
371
+ it ( 'matches a collection cursor command' , async ( ) => {
356
372
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 ( [
358
374
[ 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).forEach' ] , i ] ) ;
359
375
} ) ;
360
376
361
- it ( 'returns all suggestions running on 4.4.0 version' , ( ) => {
377
+ it ( 'returns all suggestions running on 4.4.0 version' , async ( ) => {
362
378
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).' ;
363
379
364
380
const result = [
@@ -397,10 +413,10 @@ describe('completer.completer', () => {
397
413
'db.shipwrecks.find({feature_type: \"Wrecks - Visible\"}).readConcern' ,
398
414
] ;
399
415
400
- expect ( completer ( standalone440 , i ) [ 0 ] ) . to . include . members ( result ) ;
416
+ expect ( ( await completer ( standalone440 , i ) ) [ 0 ] ) . to . include . members ( result ) ;
401
417
} ) ;
402
418
403
- it ( 'returns all suggestions matching 3.0.0 version' , ( ) => {
419
+ it ( 'returns all suggestions matching 3.0.0 version' , async ( ) => {
404
420
const i = 'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).' ;
405
421
406
422
const result = [
@@ -432,17 +448,17 @@ describe('completer.completer', () => {
432
448
'db.shipwrecks.find({feature_type: \"Wrecks - Visible\"}).toArray' ,
433
449
] ;
434
450
435
- expect ( completer ( standalone300 , i ) [ 0 ] ) . to . include . members ( result ) ;
451
+ expect ( ( await completer ( standalone300 , i ) ) [ 0 ] ) . to . include . members ( result ) ;
436
452
} ) ;
437
453
438
- it ( 'does not have a match' , ( ) => {
454
+ it ( 'does not have a match' , async ( ) => {
439
455
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 ] ) ;
441
457
} ) ;
442
458
443
- it ( 'has several matches' , ( ) => {
459
+ it ( 'has several matches' , async ( ) => {
444
460
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 ( [
446
462
[
447
463
'db.shipwrecks.find({feature_type: "Wrecks - Visible"}).close'
448
464
] , i ] ) ;
0 commit comments