Skip to content

Commit

Permalink
test(NODE-3150): reformatted tests for bsonRegExp option
Browse files Browse the repository at this point in the history
  • Loading branch information
andymina committed Jun 22, 2021
1 parent 5e730c8 commit aadbabb
Showing 1 changed file with 27 additions and 59 deletions.
86 changes: 27 additions & 59 deletions test/unit/bson_regex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,32 @@ const { BSONRegExp } = require('../../src/index');

describe('BSONRegExp', () => {
describe('bsonRegExp option', () => {
it('should respond with BSONRegExp class with option passed to db', async function () {
let client;
try {
// create and connect to client
client = this.configuration.newClient();
await client.connect();

const db = client.db('a', { bsonRegExp: true });
const collection = db.collection('b');

await collection.insertOne({ regex: new BSONRegExp('abc', 'imx') });
const res = await collection.findOne({ regex: new BSONRegExp('abc', 'imx') });

expect(res).has.property('regex').that.is.instanceOf(BSONRegExp);
} finally {
await client.close();
}
});

it('should respond with BSONRegExp class with option passed to collection', async function () {
let client;
try {
// create and connect to client
client = this.configuration.newClient(); // bsonRegex
await client.connect();

const db = client.db('a');
const collection = db.collection('b', { bsonRegExp: true });

await collection.insertOne({ regex: new BSONRegExp('abc', 'imx') });
const res = await collection.findOne({ regex: new BSONRegExp('abc', 'imx') });

expect(res).has.property('regex').that.is.instanceOf(BSONRegExp);
} finally {
await client.close();
}
});

it('should respond with BSONRegExp class with option passed to operation', async function () {
let client;
try {
// create and connect to client
client = this.configuration.newClient(); // bsonRegex
await client.connect();

const db = client.db('a');
const collection = db.collection('b');

await collection.insertOne({ regex: new BSONRegExp('abc', 'imx') });
const res = await collection.findOne(
{ regex: new BSONRegExp('abc', 'imx') },
{ bsonRegExp: true }
);

expect(res).has.property('regex').that.is.instanceOf(BSONRegExp);
} finally {
await client.close();
}
});
// define client and option for tests to use
let client;
const option = { bsonRegExp: true };
for (const passOptionTo of ['client', 'db', 'collection', 'operation']) {
it(`should respond with BSONRegExp class with option passed to ${passOptionTo}`, async function () {
try {
client = this.configuration.newClient(passOptionTo === 'client' ? option : undefined);
await client.connect();

const db = client.db('bson_regex_db', passOptionTo === 'db' ? option : undefined);
const collection = db.collection(
'bson_regex_coll',
passOptionTo === 'collection' ? option : undefined
);

await collection.insertOne({ regex: new BSONRegExp('abc', 'imx') });
const res = await collection.findOne(
{ regex: new BSONRegExp('abc', 'imx') },
passOptionTo === 'operation' ? option : undefined
);

expect(res).has.property('regex').that.is.instanceOf(BSONRegExp);
} finally {
await client.close();
}
});
}
});
});

0 comments on commit aadbabb

Please sign in to comment.