Skip to content

Commit e90b545

Browse files
committed
chore: remove dead code
1 parent a6bf329 commit e90b545

File tree

4 files changed

+45
-92
lines changed

4 files changed

+45
-92
lines changed

src/cmap/wire_protocol/responses.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,3 @@ export class ClientBulkWriteCursorResponse extends CursorResponse {
391391
return this.get('writeConcernError', BSONType.object, false);
392392
}
393393
}
394-
395-
export class ExplainResponse extends MongoDBResponse {
396-
get queryPlanner() {
397-
return this.get('queryPlanner', BSONType.object, false);
398-
}
399-
}

src/operations/find.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ export class FindOperation extends CommandOperation<CursorResponse> {
152152
}
153153
}
154154

155-
export function makeFindCommand(
156-
ns: MongoDBNamespace,
157-
filter: Document,
158-
options: FindOptions
159-
): Document {
155+
function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOptions): Document {
160156
const findCommand: Document = {
161157
find: ns.collection,
162158
filter

src/operations/find_one.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

test/integration/crud/crud_api.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,50 @@ 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+
});
101145
});
102146

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

0 commit comments

Comments
 (0)