1
- const paging = require ( '../' ) ;
2
- const dbUtils = require ( './support/db' ) ;
3
- const _ = require ( 'underscore' ) ;
4
1
const { ObjectId } = require ( 'mongoist' ) ;
5
- const driver = process . env . DRIVER ;
2
+ const _ = require ( 'underscore' ) ;
6
3
7
- let mongod ;
4
+ const dbUtils = require ( './support/db' ) ;
5
+ const paging = require ( '../' ) ;
6
+ const driver = process . env . DRIVER ;
8
7
9
8
describe ( 'find' , ( ) => {
9
+ let mongod ;
10
+ let client ;
10
11
const t = { } ;
11
12
beforeAll ( async ( ) => {
12
13
mongod = dbUtils . start ( ) ;
13
- t . db = await dbUtils . db ( mongod , driver ) ;
14
+ ( { db : t . db , client } = await dbUtils . db ( mongod , driver ) ) ;
14
15
15
16
// Set up collections once for testing later.
16
17
await Promise . all ( [
17
- t . db . collection ( 'test_paging' ) . insert ( [
18
+ t . db . collection ( 'test_paging' ) . insertMany ( [
18
19
{
19
20
counter : 1 ,
20
21
} ,
@@ -45,7 +46,7 @@ describe('find', () => {
45
46
color : 'blue' ,
46
47
} ,
47
48
] ) ,
48
- t . db . collection ( 'test_duplicate_custom_fields' ) . insert ( [
49
+ t . db . collection ( 'test_duplicate_custom_fields' ) . insertMany ( [
49
50
{
50
51
_id : 6 ,
51
52
counter : 6 ,
@@ -77,7 +78,7 @@ describe('find', () => {
77
78
timestamp : 1477347772077 ,
78
79
} ,
79
80
] ) ,
80
- t . db . collection ( 'test_paging_custom_fields' ) . insert ( [
81
+ t . db . collection ( 'test_paging_custom_fields' ) . insertMany ( [
81
82
{
82
83
counter : 6 ,
83
84
timestamp : 1477347800603 ,
@@ -103,7 +104,7 @@ describe('find', () => {
103
104
timestamp : 1477347755654 ,
104
105
} ,
105
106
] ) ,
106
- t . db . collection ( 'test_paging_date' ) . insert ( [
107
+ t . db . collection ( 'test_paging_date' ) . insertMany ( [
107
108
{
108
109
counter : 2 ,
109
110
date : new Date ( 1477347763813 ) ,
@@ -121,7 +122,7 @@ describe('find', () => {
121
122
date : new Date ( 1477347755654 ) ,
122
123
} ,
123
124
] ) ,
124
- t . db . collection ( 'test_paging_date_in_object' ) . insert ( [
125
+ t . db . collection ( 'test_paging_date_in_object' ) . insertMany ( [
125
126
{
126
127
counter : 2 ,
127
128
start : { date : new Date ( 1477347763813 ) } ,
@@ -139,7 +140,7 @@ describe('find', () => {
139
140
start : { date : new Date ( 1477347755654 ) } ,
140
141
} ,
141
142
] ) ,
142
- t . db . collection ( 'test_paging_limits' ) . insert ( [
143
+ t . db . collection ( 'test_paging_limits' ) . insertMany ( [
143
144
{
144
145
counter : 6 ,
145
146
} ,
@@ -159,7 +160,7 @@ describe('find', () => {
159
160
counter : 1 ,
160
161
} ,
161
162
] ) ,
162
- t . db . collection ( 'test_sorting' ) . insert ( [
163
+ t . db . collection ( 'test_sorting' ) . insertMany ( [
163
164
{
164
165
name : 'Alpha' ,
165
166
} ,
@@ -179,7 +180,7 @@ describe('find', () => {
179
180
name : 'aleph' ,
180
181
} ,
181
182
] ) ,
182
- t . db . collection ( 'test_null_values' ) . insert (
183
+ t . db . collection ( 'test_null_values' ) . insertMany (
183
184
[
184
185
undefined ,
185
186
undefined ,
@@ -196,7 +197,10 @@ describe('find', () => {
196
197
] ) ;
197
198
} ) ;
198
199
199
- afterAll ( ( ) => mongod . stop ( ) ) ;
200
+ afterAll ( async ( ) => {
201
+ await ( client ? client . close ( ) : t . db . close ( ) ) ;
202
+ await mongod . stop ( ) ;
203
+ } ) ;
200
204
201
205
beforeEach ( ( ) => {
202
206
paging . config . COLLATION = undefined ;
@@ -519,7 +523,7 @@ describe('find', () => {
519
523
520
524
it ( 'uses the hint parameter' , async ( ) => {
521
525
const collection = t . db . collection ( 'test_paging' ) ;
522
- await t . db . collection ( 'test_paging' ) . ensureIndex ( { color : 1 } , { name : 'color_1' } ) ;
526
+ await t . db . collection ( 'test_paging' ) . createIndex ( { color : 1 } , { name : 'color_1' } ) ;
523
527
// First page.
524
528
const res = await paging . find ( collection , {
525
529
query : {
@@ -710,7 +714,7 @@ describe('find', () => {
710
714
711
715
describe ( 'when using strings as _ids' , ( ) => {
712
716
beforeEach ( async ( ) => {
713
- await t . db . collection ( 'test_paging_string_ids' ) . insert ( [
717
+ await t . db . collection ( 'test_paging_string_ids' ) . insertMany ( [
714
718
{
715
719
_id : new ObjectId ( ) . toString ( ) ,
716
720
counter : 1 ,
@@ -1072,7 +1076,7 @@ describe('find', () => {
1072
1076
const collection = t . db . collection ( 'test_paging_string_ids' ) ;
1073
1077
await t . db
1074
1078
. collection ( 'test_paging_string_ids' )
1075
- . ensureIndex ( { color : 1 } , { name : 'color_1' } ) ;
1079
+ . createIndex ( { color : 1 } , { name : 'color_1' } ) ;
1076
1080
// First page.
1077
1081
const res = await paging . find ( collection , {
1078
1082
query : {
0 commit comments