Skip to content

Commit be8fe94

Browse files
committed
test: fix index test
1 parent 7013ac4 commit be8fe94

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

src/operations/command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,15 @@ export abstract class ModernizedCommandOperation<T> extends ModernizedOperation<
223223
abstract buildCommandDocument(connection: Connection, session?: ClientSession): Document;
224224

225225
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
226-
return {
226+
const options = {
227227
...this.options,
228228
...this.bsonOptions,
229229
timeoutContext,
230230
readPreference: this.readPreference,
231231
session: this.session
232232
};
233+
console.log(options);
234+
return options;
233235
}
234236

235237
override buildCommand(connection: Connection, session?: ClientSession): Document {
@@ -261,6 +263,8 @@ export abstract class ModernizedCommandOperation<T> extends ModernizedOperation<
261263
return decorateWithExplain(command, this.explain);
262264
}
263265

266+
console.log(command);
267+
264268
return command;
265269
}
266270
}

test/integration/node-specific/mongo_client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ describe('class MongoClient', function () {
916916
expect(result2).to.have.property('ok', 1);
917917
});
918918

919-
it('sends endSessions with noResponse set', async () => {
919+
it.only('sends endSessions with noResponse set', async () => {
920920
const session = client.startSession(); // make a session to be ended
921921
await client.db('test').command({ ping: 1 }, { session });
922922
await session.endSession();

test/unit/collection.test.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ describe('Collection', function () {
1515
});
1616

1717
context('#createIndex', () => {
18-
it('should error when createIndex fails', function (done) {
18+
let client;
19+
20+
before(function () {
21+
client = new MongoClient(`mongodb://${server.uri()}`);
22+
});
23+
24+
after(async function () {
25+
await client.close();
26+
});
27+
28+
it('should error when createIndex fails', async function () {
1929
const ERROR_RESPONSE = {
2030
ok: 0,
2131
errmsg:
@@ -39,27 +49,11 @@ describe('Collection', function () {
3949
}
4050
});
4151

42-
const client = new MongoClient(`mongodb://${server.uri()}`);
43-
44-
const close = e => client.close().then(() => done(e));
45-
46-
client
47-
.connect()
48-
.then(() => client.db('foo').collection('bar'))
49-
.then(coll => coll.createIndex({ a: 1 }))
50-
.then(
51-
() => close('Expected createIndex to fail, but it succeeded'),
52-
e => {
53-
try {
54-
expect(e).to.have.property('ok', ERROR_RESPONSE.ok);
55-
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg);
56-
expect(e).to.have.property('code', ERROR_RESPONSE.code);
57-
close(null);
58-
} catch (err) {
59-
close(err);
60-
}
61-
}
62-
);
52+
const coll = client.db('foo').collection('bar');
53+
const e = await coll.createIndex({ a: 1 }).catch(e => e);
54+
expect(e).to.have.property('ok', ERROR_RESPONSE.ok);
55+
expect(e).to.have.property('errmsg', ERROR_RESPONSE.errmsg);
56+
expect(e).to.have.property('code', ERROR_RESPONSE.code);
6357
});
6458
});
6559

0 commit comments

Comments
 (0)