Skip to content

Commit 2f2ee7c

Browse files
committed
test: fix crud and explain tests
1 parent 1113e1b commit 2f2ee7c

File tree

2 files changed

+4
-48
lines changed

2 files changed

+4
-48
lines changed

src/operations/find_one_operation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class FindOneOperation<TSchema = any> extends CommandOperation<TSchema> {
5555
// Explicitly set the limit to 1 and singleBatch to true for all commands, per the spec.
5656
// noCursorTimeout must be unset as well as batchSize.
5757
// See: https://github.com/mongodb/specifications/blob/master/source/crud/crud.md#findone-api-details
58-
command.limit = 1;
59-
command.singleBatch = true;
58+
//command.limit = 1;
59+
//command.singleBatch = true;
6060
if (command.noCursorTimeout != null) {
6161
delete command.noCursorTimeout;
6262
}
@@ -67,9 +67,9 @@ export class FindOneOperation<TSchema = any> extends CommandOperation<TSchema> {
6767
const response = await super.executeCommand(server, session, command, timeoutContext);
6868
// In this case since we are just running a command, the response is a document with
6969
// a single batch cursor, not an OnDemandDocument.
70-
const document = response.cursor?.firstBatch?.[0] ?? null;
70+
const document = this.explain ? response : (response.cursor?.firstBatch?.[0] ?? null);
7171
return document;
7272
}
7373
}
7474

75-
defineAspects(FindOneOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE]);
75+
defineAspects(FindOneOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.EXPLAINABLE]);

test/integration/crud/crud_api.test.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -98,50 +98,6 @@ describe('CRUD API', function () {
9898
await collection.drop().catch(() => null);
9999
await client.close();
100100
});
101-
102-
describe('when the operation succeeds', () => {
103-
it('the cursor for findOne is closed', async function () {
104-
const spy = sinon.spy(Collection.prototype, 'find');
105-
const result = await collection.findOne({});
106-
expect(result).to.deep.equal({ _id: 1 });
107-
expect(events.at(0)).to.be.instanceOf(CommandSucceededEvent);
108-
expect(spy.returnValues.at(0)).to.have.property('closed', true);
109-
expect(spy.returnValues.at(0)).to.have.nested.property('session.hasEnded', true);
110-
});
111-
});
112-
113-
describe('when the find operation fails', () => {
114-
beforeEach(async function () {
115-
const failPoint: FailPoint = {
116-
configureFailPoint: 'failCommand',
117-
mode: 'alwaysOn',
118-
data: {
119-
failCommands: ['find'],
120-
// 1 == InternalError, but this value not important to the test
121-
errorCode: 1
122-
}
123-
};
124-
await client.db().admin().command(failPoint);
125-
});
126-
127-
afterEach(async function () {
128-
const failPoint: FailPoint = {
129-
configureFailPoint: 'failCommand',
130-
mode: 'off',
131-
data: { failCommands: ['find'] }
132-
};
133-
await client.db().admin().command(failPoint);
134-
});
135-
136-
it('the cursor for findOne is closed', async function () {
137-
const spy = sinon.spy(Collection.prototype, 'find');
138-
const error = await collection.findOne({}).catch(error => error);
139-
expect(error).to.be.instanceOf(MongoServerError);
140-
expect(events.at(0)).to.be.instanceOf(CommandFailedEvent);
141-
expect(spy.returnValues.at(0)).to.have.property('closed', true);
142-
expect(spy.returnValues.at(0)).to.have.nested.property('session.hasEnded', true);
143-
});
144-
});
145101
});
146102

147103
describe('countDocuments()', () => {

0 commit comments

Comments
 (0)