|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -describe('test.not.js', function () { |
4 | | - it('works with simple syntax', function () { |
5 | | - var db = context.db; |
6 | | - var index = { |
| 3 | +describe('test.not.js', () => { |
| 4 | + it('works with simple syntax', async () => { |
| 5 | + const db = context.db; |
| 6 | + const index = { |
7 | 7 | "index": { |
8 | 8 | "fields": ["age"] |
9 | 9 | }, |
10 | 10 | "name": "age-index", |
11 | 11 | "type": "json" |
12 | 12 | }; |
13 | 13 |
|
14 | | - return db.createIndex(index).then(function () { |
15 | | - return db.bulkDocs([ |
16 | | - { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}}, |
| 14 | + await db.createIndex(index); |
| 15 | + await db.bulkDocs([ |
| 16 | + { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}}, |
| 17 | + { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
| 18 | + { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}}, |
| 19 | + { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
| 20 | + ]); |
| 21 | + const resp = await db.find({ |
| 22 | + selector: { |
| 23 | + age:{$gte: 40}, |
| 24 | + $not:{age: 75}, |
| 25 | + } |
| 26 | + }); |
| 27 | + const docs = resp.docs.map((doc) => { |
| 28 | + delete doc._rev; |
| 29 | + return doc; |
| 30 | + }); |
| 31 | + |
| 32 | + docs.should.deep.equal([ |
17 | 33 | { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
18 | | - { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}}, |
19 | 34 | { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
20 | | - ]); |
21 | | - }).then(function () { |
22 | | - return db.find({ |
23 | | - selector: { |
24 | | - age:{$gte: 40}, |
25 | | - $not:{age: 75}, |
26 | | - } |
27 | | - }); |
28 | | - }).then(function (resp) { |
29 | | - var docs = resp.docs.map(function (doc) { |
30 | | - delete doc._rev; |
31 | | - return doc; |
32 | | - }); |
33 | | - |
34 | | - docs.should.deep.equal([ |
35 | | - { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
36 | | - { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
37 | | - { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}} |
38 | | - ]); |
39 | | - }); |
| 35 | + { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}} |
| 36 | + ]); |
40 | 37 | }); |
41 | 38 |
|
42 | | - it('works with $and', function () { |
43 | | - var db = context.db; |
44 | | - var index = { |
| 39 | + it('works with $and', async () => { |
| 40 | + const db = context.db; |
| 41 | + const index = { |
45 | 42 | "index": { |
46 | 43 | "fields": ["age"] |
47 | 44 | }, |
48 | 45 | "name": "age-index", |
49 | 46 | "type": "json" |
50 | 47 | }; |
51 | 48 |
|
52 | | - return db.createIndex(index).then(function () { |
53 | | - return db.bulkDocs([ |
54 | | - { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}}, |
| 49 | + await db.createIndex(index); |
| 50 | + await db.bulkDocs([ |
| 51 | + { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}}, |
| 52 | + { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
| 53 | + { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}}, |
| 54 | + { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
| 55 | + ]); |
| 56 | + const resp = await db.find({ |
| 57 | + selector: { |
| 58 | + $and: [ |
| 59 | + {age:{$gte: 40}}, |
| 60 | + {$not:{age: {$eq: 75}}}, |
| 61 | + ] |
| 62 | + } |
| 63 | + }); |
| 64 | + const docs = resp.docs.map((doc) => { |
| 65 | + delete doc._rev; |
| 66 | + return doc; |
| 67 | + }); |
| 68 | + |
| 69 | + docs.should.deep.equal([ |
55 | 70 | { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
56 | | - { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}}, |
57 | 71 | { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
58 | | - ]); |
59 | | - }).then(function () { |
60 | | - return db.find({ |
61 | | - selector: { |
62 | | - $and: [ |
63 | | - {age:{$gte: 40}}, |
64 | | - {$not:{age: {$eq: 75}}}, |
65 | | - ] |
66 | | - } |
67 | | - }); |
68 | | - }).then(function (resp) { |
69 | | - var docs = resp.docs.map(function (doc) { |
70 | | - delete doc._rev; |
71 | | - return doc; |
72 | | - }); |
73 | | - |
74 | | - docs.should.deep.equal([ |
75 | | - { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
76 | | - { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
77 | | - { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}} |
78 | | - ]); |
79 | | - }); |
| 72 | + { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}} |
| 73 | + ]); |
80 | 74 | }); |
81 | 75 |
|
82 | | - it('works with another combinational field', function () { |
83 | | - var db = context.db; |
84 | | - var index = { |
| 76 | + it('works with another combinational field', async () => { |
| 77 | + const db = context.db; |
| 78 | + const index = { |
85 | 79 | "index": { |
86 | 80 | "fields": ["age"] |
87 | 81 | }, |
88 | 82 | "name": "age-index", |
89 | 83 | "type": "json" |
90 | 84 | }; |
91 | 85 |
|
92 | | - return db.createIndex(index).then(function () { |
93 | | - return db.bulkDocs([ |
94 | | - { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}}, |
95 | | - { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
96 | | - { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}}, |
97 | | - { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
98 | | - ]); |
99 | | - }).then(function () { |
100 | | - return db.find({ |
101 | | - selector: { |
102 | | - $and: [ |
103 | | - {age:{$gte: 0}}, |
104 | | - {$not:{age: {$eq: 75}}}, |
105 | | - {$or: [ |
106 | | - {"name.first": "Eddie"}, |
107 | | - ]} |
108 | | - ] |
109 | | - } |
110 | | - }); |
111 | | - }).then(function (resp) { |
112 | | - var docs = resp.docs.map(function (doc) { |
113 | | - delete doc._rev; |
114 | | - return doc; |
115 | | - }); |
116 | | - |
117 | | - docs.should.deep.equal([ |
118 | | - { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
119 | | - ]); |
| 86 | + await db.createIndex(index); |
| 87 | + await db.bulkDocs([ |
| 88 | + { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}}, |
| 89 | + { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
| 90 | + { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}}, |
| 91 | + { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}, |
| 92 | + ]); |
| 93 | + const resp = await db.find({ |
| 94 | + selector: { |
| 95 | + $and: [ |
| 96 | + {age:{$gte: 0}}, |
| 97 | + {$not:{age: {$eq: 75}}}, |
| 98 | + {$or: [ |
| 99 | + {"name.first": "Eddie"}, |
| 100 | + ]} |
| 101 | + ] |
| 102 | + } |
| 103 | + }); |
| 104 | + const docs = resp.docs.map((doc) => { |
| 105 | + delete doc._rev; |
| 106 | + return doc; |
120 | 107 | }); |
| 108 | + |
| 109 | + docs.should.deep.equal([ |
| 110 | + { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}}, |
| 111 | + ]); |
121 | 112 | }); |
122 | 113 | }); |
0 commit comments