1
1
'use strict' ;
2
2
const test = require ( './shared' ) . assert ;
3
3
const { expect } = require ( 'chai' ) ;
4
- const { ReturnDocument } = require ( '../../src' ) ;
4
+ const { ReturnDocument, ObjectId } = require ( '../../src' ) ;
5
5
const setupDatabase = require ( './shared' ) . setupDatabase ;
6
6
7
7
// instanceof cannot be use reliably to detect the new models in js due to scoping and new
@@ -14,6 +14,27 @@ describe('CRUD API', function () {
14
14
return setupDatabase ( this . configuration ) ;
15
15
} ) ;
16
16
17
+ it ( 'should correctly execute findOne method using crud api' , async function ( ) {
18
+ const configuration = this . configuration ;
19
+ const client = configuration . newClient ( ) ;
20
+ await client . connect ( ) ;
21
+ const db = client . db ( configuration . db ) ;
22
+ const collection = db . collection ( 't' ) ;
23
+
24
+ await collection . insertOne ( { findOneTest : 1 } ) ;
25
+
26
+ const findOneResult = await collection . findOne ( { findOneTest : 1 } ) ;
27
+
28
+ expect ( findOneResult ) . to . have . property ( 'findOneTest' , 1 ) ;
29
+ expect ( findOneResult ) . to . have . property ( '_id' ) . that . is . instanceOf ( ObjectId ) ;
30
+
31
+ const findNoneResult = await collection . findOne ( { findOneTest : 2 } ) ;
32
+ expect ( findNoneResult ) . to . be . null ;
33
+
34
+ await collection . drop ( ) ;
35
+ await client . close ( ) ;
36
+ } ) ;
37
+
17
38
it ( 'should correctly execute find method using crud api' , {
18
39
// Add a tag that our runner can trigger on
19
40
// in this case we are setting that node needs to be higher than 0.10.X to run
0 commit comments