11'use strict' ;
22
3- describe ( 'test.set-operations.js' , function ( ) {
4- var sortById = testUtils . sortById ;
3+ describe ( 'test.set-operations.js' , ( ) => {
4+ const sortById = testUtils . sortById ;
55
6- beforeEach ( function ( ) {
7- return context . db . bulkDocs ( [
6+ beforeEach ( async ( ) => {
7+ await context . db . bulkDocs ( [
88 { name : 'Mario' , _id : 'mario' , rank : 5 , series : 'Mario' , debut : 1981 } ,
99 { name : 'Jigglypuff' , _id : 'puff' , rank : 8 , series : 'Pokemon' , debut : 1996 } ,
1010 { name : 'Link' , rank : 10 , _id : 'link' , series : 'Zelda' , debut : 1986 } ,
@@ -20,102 +20,92 @@ describe('test.set-operations.js', function () {
2020 ] ) ;
2121 } ) ;
2222
23- it ( 'should work with $and 1' , function ( ) {
24- var db = context . db ;
25- return db . createIndex ( {
23+ it ( 'should work with $and 1' , async ( ) => {
24+ const db = context . db ;
25+ await db . createIndex ( {
2626 "index" : {
2727 "fields" : [ "series" ]
2828 }
29- } ) . then ( function ( ) {
30- return db . createIndex ( {
31- "index" : {
32- "fields" : [ "debut" ]
33- }
34- } ) ;
35- } ) . then ( function ( ) {
36- return db . find ( {
37- selector : {
38- $and : [
39- { series : 'Mario' } ,
40- { debut : { $gte : 1990 } }
41- ]
42- } ,
43- fields : [ '_id' ]
44- } ) ;
45- } ) . then ( function ( res ) {
46- res . docs . sort ( sortById ) ;
47- res . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
4829 } ) ;
30+ await db . createIndex ( {
31+ "index" : {
32+ "fields" : [ "debut" ]
33+ }
34+ } ) ;
35+ const res = await db . find ( {
36+ selector : {
37+ $and : [
38+ { series : 'Mario' } ,
39+ { debut : { $gte : 1990 } }
40+ ]
41+ } ,
42+ fields : [ '_id' ]
43+ } ) ;
44+ res . docs . sort ( sortById ) ;
45+ res . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
4946 } ) ;
5047
51- it ( 'should work with $and 2, same index' , function ( ) {
52- var db = context . db ;
53- return db . createIndex ( {
48+ it ( 'should work with $and 2, same index' , async ( ) => {
49+ const db = context . db ;
50+ await db . createIndex ( {
5451 "index" : {
5552 "fields" : [ "series" , "debut" ]
5653 }
57- } ) . then ( function ( ) {
58- return db . find ( {
59- selector : {
60- $and : [
61- { series : 'Mario' } ,
62- { debut : { $gte : 1990 } }
63- ]
64- } ,
65- fields : [ '_id' ]
66- } ) ;
67- } ) . then ( function ( res ) {
68- res . docs . sort ( sortById ) ;
69- res . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
7054 } ) ;
55+ const res = await db . find ( {
56+ selector : {
57+ $and : [
58+ { series : 'Mario' } ,
59+ { debut : { $gte : 1990 } }
60+ ]
61+ } ,
62+ fields : [ '_id' ]
63+ } ) ;
64+ res . docs . sort ( sortById ) ;
65+ res . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
7166 } ) ;
7267
73- it ( 'should work with $and 3, index/no-index' , function ( ) {
74- var db = context . db ;
75- return db . createIndex ( {
68+ it ( 'should work with $and 3, index/no-index' , async ( ) => {
69+ const db = context . db ;
70+ await db . createIndex ( {
7671 "index" : {
7772 "fields" : [ "series" ]
7873 }
79- } ) . then ( function ( ) {
80- return db . createIndex ( {
81- "index" : {
82- "fields" : [ "rank" ]
83- }
84- } ) ;
85- } ) . then ( function ( ) {
86- return db . find ( {
87- selector : {
88- $and : [
89- { series : 'Mario' } ,
90- { debut : { $gte : 1990 } }
91- ]
92- } ,
93- fields : [ '_id' ]
94- } ) ;
95- } ) . then ( function ( res ) {
96- res . docs . sort ( sortById ) ;
97- res . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
9874 } ) ;
75+ await db . createIndex ( {
76+ "index" : {
77+ "fields" : [ "rank" ]
78+ }
79+ } ) ;
80+ const res = await db . find ( {
81+ selector : {
82+ $and : [
83+ { series : 'Mario' } ,
84+ { debut : { $gte : 1990 } }
85+ ]
86+ } ,
87+ fields : [ '_id' ]
88+ } ) ;
89+ res . docs . sort ( sortById ) ;
90+ res . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
9991 } ) ;
10092
101- it ( 'should work with $and 4, wrong index' , function ( ) {
102- var db = context . db ;
103- return db . createIndex ( {
93+ it ( 'should work with $and 4, wrong index' , async ( ) => {
94+ const db = context . db ;
95+ await db . createIndex ( {
10496 "index" : {
10597 "fields" : [ "rank" ]
10698 }
107- } ) . then ( function ( ) {
108- return db . find ( {
109- selector : {
110- $and : [
111- { series : 'Mario' } ,
112- { debut : { $gte : 1990 } }
113- ]
114- } ,
115- fields : [ '_id' ]
116- } ) . then ( function ( resp ) {
117- resp . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
118- } ) ;
11999 } ) ;
100+ const resp = await db . find ( {
101+ selector : {
102+ $and : [
103+ { series : 'Mario' } ,
104+ { debut : { $gte : 1990 } }
105+ ]
106+ } ,
107+ fields : [ '_id' ]
108+ } ) ;
109+ resp . docs . should . deep . equal ( [ { _id : 'yoshi' } ] ) ;
120110 } ) ;
121111} ) ;
0 commit comments