Skip to content

Commit 6557032

Browse files
fix(shell-api): the explainable cursor should reflect simple collation MONGOSH-1670 (#2050)
1 parent 61d7214 commit 6557032

File tree

3 files changed

+88
-33
lines changed

3 files changed

+88
-33
lines changed

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

Lines changed: 71 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,46 +110,86 @@ describe('Explainable', function () {
110110
});
111111

112112
describe('find', function () {
113-
let cursorStub;
114-
let explainResult;
115-
beforeEach(async function () {
116-
explainResult = { ok: 1 };
113+
context('without options', function () {
114+
let cursorStub;
115+
let explainResult;
117116

118-
const cursorSpy = {
119-
explain: sinon.spy(() => explainResult),
120-
} as unknown;
121-
collection.find = sinon.spy(() => Promise.resolve(cursorSpy as Cursor));
117+
beforeEach(async function () {
118+
explainResult = { ok: 1 };
122119

123-
cursorStub = await explainable.find({ query: 1 }, { projection: 1 });
124-
});
120+
const cursorSpy = {
121+
explain: sinon.spy(() => explainResult),
122+
} as unknown;
123+
collection.find = sinon.spy(() =>
124+
Promise.resolve(cursorSpy as Cursor)
125+
);
125126

126-
it('calls collection.find with arguments', function () {
127-
expect(collection.find).to.have.been.calledOnceWithExactly(
128-
{ query: 1 },
129-
{ projection: 1 }
130-
);
131-
});
127+
cursorStub = await explainable.find({ query: 1 }, { projection: 1 });
128+
});
129+
130+
it('calls collection.find with arguments', function () {
131+
expect(collection.find).to.have.been.calledOnceWithExactly(
132+
{ query: 1 },
133+
{ projection: 1 },
134+
{}
135+
);
136+
});
137+
138+
it('returns an cursor that has toShellResult when evaluated', async function () {
139+
expect((await toShellResult(cursorStub)).type).to.equal(
140+
'ExplainableCursor'
141+
);
142+
});
143+
144+
context(
145+
'when calling toShellResult().printable on the result',
146+
function () {
147+
it('calls explain with verbosity', function () {
148+
expect(cursorStub._verbosity).to.equal('queryPlanner');
149+
});
132150

133-
it('returns an cursor that has toShellResult when evaluated', async function () {
134-
expect((await toShellResult(cursorStub)).type).to.equal(
135-
'ExplainableCursor'
151+
it('returns the explain result', async function () {
152+
expect((await toShellResult(cursorStub)).printable).to.equal(
153+
explainResult
154+
);
155+
});
156+
}
136157
);
137158
});
138159

139-
context(
140-
'when calling toShellResult().printable on the result',
141-
function () {
142-
it('calls explain with verbosity', function () {
143-
expect(cursorStub._verbosity).to.equal('queryPlanner');
144-
});
160+
context('with options', function () {
161+
let cursorStub;
162+
let explainResult;
163+
164+
beforeEach(async function () {
165+
explainResult = { ok: 1 };
166+
167+
const cursorSpy = {
168+
explain: sinon.spy(() => explainResult),
169+
} as unknown;
170+
collection.find = sinon.spy(() =>
171+
Promise.resolve(cursorSpy as Cursor)
172+
);
145173

146-
it('returns the explain result', async function () {
147-
expect((await toShellResult(cursorStub)).printable).to.equal(
148-
explainResult
149-
);
174+
cursorStub = await explainable.find({}, undefined, {
175+
collation: { locale: 'simple' },
150176
});
151-
}
152-
);
177+
});
178+
179+
it('calls collection.find with arguments', function () {
180+
expect(collection.find).to.have.been.calledOnceWithExactly(
181+
{},
182+
undefined,
183+
{ collation: { locale: 'simple' } }
184+
);
185+
});
186+
187+
it('returns an cursor that has toShellResult when evaluated', async function () {
188+
expect((await toShellResult(cursorStub)).type).to.equal(
189+
'ExplainableCursor'
190+
);
191+
});
192+
});
153193
});
154194

155195
describe('aggregate', function () {

packages/shell-api/src/explainable.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
FindOneAndDeleteOptions,
3232
FindOneAndReplaceOptions,
3333
FindOneAndUpdateOptions,
34+
FindOptions,
3435
} from '@mongosh/service-provider-core';
3536

3637
@shellApiClassDefault
@@ -97,11 +98,12 @@ export default class Explainable extends ShellApiWithMongoClass {
9798
@returnsPromise
9899
async find(
99100
query?: Document,
100-
projection?: Document
101+
projection?: Document,
102+
options: FindOptions = {}
101103
): Promise<ExplainableCursor> {
102104
this._emitExplainableApiCall('find', { query, projection });
103105

104-
const cursor = await this._collection.find(query, projection);
106+
const cursor = await this._collection.find(query, projection, options);
105107
return new ExplainableCursor(this._mongo, cursor, this._verbosity);
106108
}
107109

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,19 @@ describe('Shell API (integration)', function () {
15681568
'serverInfo',
15691569
]);
15701570
});
1571+
1572+
describe('after server 4.4', function () {
1573+
skipIfServerVersion(testServer, '<= 4.4');
1574+
it('the explainable cursor reflects collation', async function () {
1575+
const cursor = await explainable.find({}, undefined, {
1576+
collation: { locale: 'simple' },
1577+
});
1578+
const result = await toShellResult(cursor);
1579+
expect(result.printable.command.collation.locale).to.be.equal(
1580+
'simple'
1581+
);
1582+
});
1583+
});
15711584
});
15721585

15731586
describe('aggregate', function () {

0 commit comments

Comments
 (0)