-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(NODE-3150): reformatted bsonRegExp tests
- Loading branch information
Showing
1 changed file
with
30 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,38 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const BSON = require('bson'); | ||
const BSONRegExp = require('bson').BSONRegExp; | ||
|
||
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 BSON.BSONRegExp('abc', 'imx') }); | ||
const res = await collection.findOne({ regex: new BSON.BSONRegExp('abc', 'imx') }); | ||
|
||
expect(res) | ||
.has.property('regex') | ||
.that.is.instanceOf(BSON.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 BSON.BSONRegExp('abc', 'imx') }); | ||
const res = await collection.findOne({ regex: new BSON.BSONRegExp('abc', 'imx') }); | ||
|
||
expect(res) | ||
.has.property('regex') | ||
.that.is.instanceOf(BSON.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 BSON.BSONRegExp('abc', 'imx') }); | ||
const res = await collection.findOne( | ||
{ regex: new BSON.BSONRegExp('abc', 'imx') }, | ||
{ bsonRegExp: true } | ||
); | ||
|
||
expect(res) | ||
.has.property('regex') | ||
.that.is.instanceOf(BSON.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(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); |