Skip to content

Commit 59c04f3

Browse files
committed
fix tests
1 parent 198fb06 commit 59c04f3

27 files changed

+247
-149
lines changed

packages/autocomplete/src/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('completer.completer', function () {
294294

295295
it('returns all suggestions', async function () {
296296
const i = 'db.';
297-
const attr = shellSignatures.Database.attributes as any;
297+
const attr = shellSignatures.DatabaseImpl.attributes as any;
298298
const dbComplete = Object.keys(attr);
299299
const adjusted = dbComplete
300300
.filter((c) => !attr[c].deprecated)
@@ -347,7 +347,7 @@ describe('completer.completer', function () {
347347
it('returns all suggestions', async function () {
348348
const i = 'db.shipwrecks.';
349349
const collComplete = Object.keys(
350-
shellSignatures.Collection.attributes as any
350+
shellSignatures.CollectionImpl.attributes as any
351351
);
352352
const adjusted = collComplete
353353
.filter(

packages/autocomplete/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ async function completer(
8484
): Promise<[string[], string, 'exclusive'] | [string[], string]> {
8585
const SHELL_COMPLETIONS = shellSignatures.ShellApi
8686
.attributes as TypeSignatureAttributes;
87-
const COLL_COMPLETIONS = shellSignatures.Collection
87+
const COLL_COMPLETIONS = shellSignatures.CollectionImpl
8888
.attributes as TypeSignatureAttributes;
89-
const DB_COMPLETIONS = shellSignatures.Database
89+
const DB_COMPLETIONS = shellSignatures.DatabaseImpl
9090
.attributes as TypeSignatureAttributes;
9191
const AGG_CURSOR_COMPLETIONS = shellSignatures.AggregationCursor
9292
.attributes as TypeSignatureAttributes;

packages/cli-repl/src/cli-repl.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ describe('CliRepl', function () {
16671667
)
16681668
.flat();
16691669
expect(apiEvents).to.have.lengthOf(1);
1670-
expect(apiEvents[0].properties.class).to.equal('Database');
1670+
expect(apiEvents[0].properties.class).to.equal('DatabaseImpl');
16711671
expect(apiEvents[0].properties.method).to.equal(
16721672
'printShardingStatus'
16731673
);
@@ -1738,8 +1738,8 @@ describe('CliRepl', function () {
17381738
e.properties.count,
17391739
])
17401740
).to.deep.equal([
1741-
['Database', 'hello', 2],
1742-
['Database', 'hello', 1],
1741+
['DatabaseImpl', 'hello', 2],
1742+
['DatabaseImpl', 'hello', 1],
17431743
]);
17441744
});
17451745

@@ -2466,8 +2466,8 @@ describe('CliRepl', function () {
24662466
});
24672467

24682468
afterEach(async function () {
2469-
expect(output).not.to.include('Tab completion error');
2470-
expect(output).not.to.include(
2469+
expect(output, output).not.to.include('Tab completion error');
2470+
expect(output, output).not.to.include(
24712471
'listCollections requires authentication'
24722472
);
24732473
await cliRepl.mongoshRepl.close();

packages/cli-repl/src/mongosh-repl.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { MongoshCommandFailed } from '@mongosh/errors';
33
import type { ServiceProvider } from '@mongosh/service-provider-core';
44
import { bson } from '@mongosh/service-provider-core';
5-
import { ADMIN_DB } from '@mongosh/shell-api/lib/enums';
5+
import { ADMIN_DB } from '../../shell-api/lib/enums';
66
import { CliUserConfig } from '@mongosh/types';
77
import { EventEmitter, once } from 'events';
88
import path from 'path';

packages/shell-api/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
"description": "MongoDB Shell API Classes Package",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
7+
"exports": {
8+
".": {
9+
"default": "./lib/index.js",
10+
"types": "./lib/index.d.ts"
11+
},
12+
"./api": {
13+
"default": "./lib/api.js",
14+
"types": "./lib/api.d.ts"
15+
}
16+
},
717
"config": {
818
"unsafe-perm": true
919
},

packages/shell-api/src/aggregation-cursor.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('AggregationCursor', function () {
3636
type: 'function',
3737
returnsPromise: false,
3838
deprecated: false,
39+
inherited: true,
3940
returnType: 'AggregationCursor',
4041
platforms: ALL_PLATFORMS,
4142
topologies: ALL_TOPOLOGIES,

packages/shell-api/src/bulk.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { EventEmitter } from 'events';
1111
import type { StubbedInstance } from 'ts-sinon';
1212
import { stubInterface } from 'ts-sinon';
1313
import Bulk, { BulkFindOp } from './bulk';
14-
import Collection from './collection';
14+
import { CollectionImpl } from './collection';
1515
import { ALL_PLATFORMS, ALL_SERVER_VERSIONS, ALL_TOPOLOGIES } from './enums';
1616
import { signatures, toShellResult } from './index';
1717
import { BulkWriteResult } from './result';
@@ -57,7 +57,7 @@ describe('Bulk API', function () {
5757
});
5858
describe('Metadata', function () {
5959
describe('toShellResult', function () {
60-
const collection = stubInterface<Collection>();
60+
const collection = stubInterface<CollectionImpl>();
6161
const b = new Bulk(collection, {
6262
batches: [1, 2, 3, 4],
6363
} as any);
@@ -77,7 +77,7 @@ describe('Bulk API', function () {
7777
['ordered', 'unordered'].forEach((t) => {
7878
describe(t, function () {
7979
describe('commands', function () {
80-
let collection: Collection;
80+
let collection: CollectionImpl;
8181
let serviceProvider: StubbedInstance<ServiceProvider>;
8282
let bulk: Bulk;
8383
let bus: StubbedInstance<EventEmitter>;
@@ -101,7 +101,7 @@ describe('Bulk API', function () {
101101
serviceProvider.runCommand.resolves({ ok: 1 });
102102
instanceState = new ShellInstanceState(serviceProvider, bus);
103103
const db = instanceState.currentDb;
104-
collection = new Collection(db._mongo, db, 'coll1');
104+
collection = new CollectionImpl(db._mongo, db, 'coll1');
105105
innerStub = stubInterface<any>();
106106
innerStub.batches = [
107107
{ originalZeroIndex: 0 },

packages/shell-api/src/collection.spec.ts

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
shellApiType,
1212
ADMIN_DB,
1313
} from './enums';
14-
import Database from './database';
14+
import { DatabaseImpl } from './database';
1515
import Mongo from './mongo';
16-
import Collection from './collection';
16+
import { CollectionImpl } from './collection';
1717
import ChangeStreamCursor from './change-stream-cursor';
1818
import Explainable from './explainable';
1919
import type {
@@ -33,24 +33,26 @@ import {
3333
MongoshInvalidInputError,
3434
MongoshRuntimeError,
3535
} from '@mongosh/errors';
36+
import type { StringKey } from './helpers';
3637

3738
const sinonChai = require('sinon-chai'); // weird with import
3839

3940
use(sinonChai);
4041
describe('Collection', function () {
4142
describe('help', function () {
42-
const apiClass = new Collection({} as any, {} as any, 'name');
43+
const apiClass = new CollectionImpl({} as any, {} as any, 'name');
4344
it('calls help function', async function () {
4445
expect((await toShellResult(apiClass.help())).type).to.equal('Help');
4546
expect((await toShellResult(apiClass.help)).type).to.equal('Help');
4647
});
4748
});
4849
describe('signatures', function () {
4950
it('type', function () {
50-
expect(signatures.Collection.type).to.equal('Collection');
51+
// TODO: do we want the signatures to be CollectionImpl or Collection?
52+
expect(signatures.CollectionImpl.type).to.equal('CollectionImpl');
5153
});
5254
it('attributes', function () {
53-
expect(signatures.Collection.attributes?.aggregate).to.deep.equal({
55+
expect(signatures.CollectionImpl.attributes?.aggregate).to.deep.equal({
5456
type: 'function',
5557
returnsPromise: true,
5658
deprecated: false,
@@ -68,10 +70,14 @@ describe('Collection', function () {
6870
describe('metadata', function () {
6971
describe('toShellResult', function () {
7072
const mongo = sinon.spy();
71-
const db = new Database(mongo as any, 'myDB');
72-
const coll = new Collection(mongo as any, db, 'myCollection');
73+
const db = new DatabaseImpl(mongo as any, 'myDB');
74+
const coll = new CollectionImpl(
75+
mongo as any,
76+
db._typeLaunder(),
77+
'myCollection'
78+
);
7379
it('toShellResult', async function () {
74-
expect((await toShellResult(coll)).type).to.equal('Collection');
80+
expect((await toShellResult(coll)).type).to.equal('CollectionImpl');
7581
expect((await toShellResult(coll)).printable).to.equal(
7682
'myDB.myCollection'
7783
);
@@ -80,21 +86,25 @@ describe('Collection', function () {
8086
});
8187
describe('.collections', function () {
8288
it('allows to get a collection as property if is not one of the existing methods', function () {
83-
const database = new Database(
89+
const database = new DatabaseImpl(
8490
{ _instanceState: { emitApiCallWithArgs: (): void => {} } } as any,
8591
'db1'
8692
);
87-
const coll: any = new Collection({} as any, database, 'coll');
88-
expect(coll.someCollection).to.have.instanceOf(Collection);
93+
const coll: any = new CollectionImpl(
94+
{} as any,
95+
database._typeLaunder(),
96+
'coll'
97+
);
98+
expect(coll.someCollection).to.have.instanceOf(CollectionImpl);
8999
expect(coll.someCollection._name).to.equal('coll.someCollection');
90100
});
91101

92102
it('reuses collections', function () {
93-
const database: any = new Database(
103+
const database: any = new DatabaseImpl(
94104
{ _instanceState: { emitApiCallWithArgs: (): void => {} } } as any,
95105
'db1'
96106
);
97-
const coll: any = new Collection({} as any, database, 'coll');
107+
const coll: any = new CollectionImpl({} as any, database, 'coll');
98108
expect(coll.someCollection).to.equal(
99109
database.getCollection('coll.someCollection')
100110
);
@@ -103,36 +113,47 @@ describe('Collection', function () {
103113

104114
it('does not return a collection starting with _', function () {
105115
// this is the behaviour in the old shell
106-
const database: any = new Database({} as any, 'db1');
107-
const coll: any = new Collection({} as any, database, 'coll');
116+
const database: any = new DatabaseImpl({} as any, 'db1');
117+
const coll: any = new CollectionImpl({} as any, database, 'coll');
108118
expect(coll._someProperty).to.equal(undefined);
109119
});
110120

111121
it('does not return a collection for symbols', function () {
112-
const database: any = new Database({} as any, 'db1');
113-
const coll: any = new Collection({} as any, database, 'coll');
122+
const database: any = new DatabaseImpl({} as any, 'db1');
123+
const coll: any = new CollectionImpl({} as any, database, 'coll');
114124
expect(coll[Symbol('someProperty')]).to.equal(undefined);
115125
});
116126

117127
it('does not return a collection with invalid name', function () {
118-
const database: any = new Database({} as any, 'db1');
119-
const coll: any = new Collection({} as any, database, 'coll');
128+
const database: any = new DatabaseImpl({} as any, 'db1');
129+
const coll: any = new CollectionImpl({} as any, database, 'coll');
120130
expect(coll.foo$bar).to.equal(undefined);
121131
});
122132

123133
it('allows to access _name', function () {
124-
const database: any = new Database({} as any, 'db1');
125-
const coll: any = new Collection({} as any, database, 'coll');
134+
const database: any = new DatabaseImpl({} as any, 'db1');
135+
const coll: any = new CollectionImpl({} as any, database, 'coll');
126136
expect(coll._name).to.equal('coll');
127137
});
128138
});
129139
describe('commands', function () {
130-
let mongo: Mongo;
140+
type ServerSchema = {
141+
db1: {
142+
coll1: {
143+
schema: {};
144+
};
145+
};
146+
};
147+
let mongo: Mongo<ServerSchema>;
131148
let serviceProvider: StubbedInstance<ServiceProvider>;
132-
let database: Database;
149+
let database: DatabaseImpl<ServerSchema, ServerSchema['db1']>;
133150
let bus: StubbedInstance<EventEmitter>;
134151
let instanceState: ShellInstanceState;
135-
let collection: Collection;
152+
let collection: CollectionImpl<
153+
ServerSchema,
154+
ServerSchema['db1'],
155+
ServerSchema['db1']['coll1']
156+
>;
136157

137158
beforeEach(function () {
138159
bus = stubInterface<EventEmitter>();
@@ -149,8 +170,15 @@ describe('Collection', function () {
149170
undefined,
150171
serviceProvider
151172
);
152-
database = new Database(mongo, 'db1');
153-
collection = new Collection(mongo, database, 'coll1');
173+
database = new DatabaseImpl<ServerSchema, ServerSchema['db1']>(
174+
mongo,
175+
'db1' as StringKey<ServerSchema>
176+
);
177+
collection = new CollectionImpl<
178+
ServerSchema,
179+
ServerSchema['db1'],
180+
ServerSchema['db1']['coll1']
181+
>(mongo, database._typeLaunder(), 'coll1');
154182
});
155183
describe('aggregate', function () {
156184
let serviceProviderCursor: StubbedInstance<ServiceProviderAggregationCursor>;
@@ -2802,13 +2830,24 @@ describe('Collection', function () {
28022830
});
28032831

28042832
describe('fle2', function () {
2805-
let mongo1: Mongo;
2806-
let mongo2: Mongo;
2833+
type ServerSchema = {
2834+
db1: {
2835+
collfle2: {
2836+
schema: {};
2837+
};
2838+
};
2839+
};
2840+
let mongo1: Mongo<ServerSchema>;
2841+
let mongo2: Mongo<ServerSchema>;
28072842
let serviceProvider: StubbedInstance<ServiceProvider>;
2808-
let database: Database;
2843+
let database: DatabaseImpl<ServerSchema, ServerSchema['db1']>;
28092844
let bus: StubbedInstance<EventEmitter>;
28102845
let instanceState: ShellInstanceState;
2811-
let collection: Collection;
2846+
let collection: CollectionImpl<
2847+
ServerSchema,
2848+
ServerSchema['db1'],
2849+
ServerSchema['db1']['collfle2']
2850+
>;
28122851
let keyId: any[];
28132852
beforeEach(function () {
28142853
bus = stubInterface<EventEmitter>();
@@ -2821,7 +2860,8 @@ describe('Collection', function () {
28212860
keyId = [
28222861
{ $binary: { base64: 'oh3caogGQ4Sf34ugKnZ7Xw==', subType: '04' } },
28232862
];
2824-
mongo1 = new Mongo(
2863+
2864+
mongo1 = new Mongo<ServerSchema>(
28252865
instanceState,
28262866
undefined,
28272867
{
@@ -2836,8 +2876,15 @@ describe('Collection', function () {
28362876
undefined,
28372877
serviceProvider
28382878
);
2839-
database = new Database(mongo1, 'db1');
2840-
collection = new Collection(mongo1, database, 'collfle2');
2879+
database = new DatabaseImpl<ServerSchema, ServerSchema['db1']>(
2880+
mongo1,
2881+
'db1' as StringKey<ServerSchema>
2882+
);
2883+
collection = new CollectionImpl(
2884+
mongo1,
2885+
database._typeLaunder(),
2886+
'collfle2' as StringKey<ServerSchema['db1']>
2887+
);
28412888
mongo2 = new Mongo(
28422889
instanceState,
28432890
undefined,
@@ -2896,10 +2943,10 @@ describe('Collection', function () {
28962943
});
28972944
describe('with session', function () {
28982945
let serviceProvider: StubbedInstance<ServiceProvider>;
2899-
let collection: Collection;
2946+
let collection: CollectionImpl;
29002947
let internalSession: StubbedInstance<ServiceProviderSession>;
29012948
const exceptions: {
2902-
[key in keyof (typeof Collection)['prototype']]?: {
2949+
[key in keyof (typeof CollectionImpl)['prototype']]?: {
29032950
a?: any;
29042951
m?: string;
29052952
i?: number;
@@ -2961,7 +3008,7 @@ describe('Collection', function () {
29613008
getSearchIndexes: { i: 3 },
29623009
checkMetadataConsistency: { m: 'runCursorCommand', i: 2 },
29633010
};
2964-
const ignore: (keyof (typeof Collection)['prototype'])[] = [
3011+
const ignore: (keyof (typeof CollectionImpl)['prototype'])[] = [
29653012
'getShardDistribution',
29663013
'stats',
29673014
'isCapped',
@@ -3034,8 +3081,8 @@ describe('Collection', function () {
30343081
});
30353082
context('all commands that use the same command in sp', function () {
30363083
for (const method of (
3037-
Object.getOwnPropertyNames(Collection.prototype) as (string &
3038-
keyof (typeof Collection)['prototype'])[]
3084+
Object.getOwnPropertyNames(CollectionImpl.prototype) as (string &
3085+
keyof (typeof CollectionImpl)['prototype'])[]
30393086
).filter(
30403087
(k) =>
30413088
typeof k === 'string' &&
@@ -3045,7 +3092,7 @@ describe('Collection', function () {
30453092
if (
30463093
!method.startsWith('_') &&
30473094
!method.startsWith('print') &&
3048-
Collection.prototype[method].returnsPromise
3095+
CollectionImpl.prototype[method].returnsPromise
30493096
) {
30503097
it(`passes the session through for ${method}`, async function () {
30513098
try {

0 commit comments

Comments
 (0)