You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by ja...@apache.org on 2026/04/23 10:12:49 UTC
(pouchdb) branch master updated: refactor/test find suite1 (#9218)
This is an automated email from the ASF dual-hosted git repository.
janl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git
The following commit(s) were added to refs/heads/master by this push:
new 071232608 refactor/test find suite1 (#9218)
071232608 is described below
commit 071232608754ef9462362713b60a628f1ef9827e
Author: Mariano <67...@users.noreply.github.com>
AuthorDate: Thu Apr 23 12:12:44 2026 +0200
refactor/test find suite1 (#9218)
* refactor: change var to const
* refactor: replace var with const , arrow functiones and update to async/await syntax
* refactor: use const, arrow functions and async/await
* refactor: modernize test suite with async/await, const and arrow functions
* refactor: use async/await, const and arrow functions
* refactor: add arrow functions, const, async/await, destructuring
* refactor: use async/await and const/arrow functions
* refactor: use async/await, const, and arrow functions
* refactor: update to async/await, const and arrow functions
* refactor: convert to async/await, const and use const/arrow functions
* refactor: use async/await and arrow functions, const
* refactor: use async/await, const and arrow functions
* refactor: use async/await, const and arrow functions
* refactor: use async/await, const, arrow functions
* refactor: use async/await, const and arrow functions
* refactor: uuse async/await, const, arrow functions
* refactor: use async/await, const and arrow syntax
* refactor: use const, async/await and arrow functions
* refactor: use const, async/await and arrow functions
* refactor: use async/await, const, and arrow functions
* refactor: update test to use async/await, const and arrow functions
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
* refactor: use async/await, const and arrow function
---
tests/find/test-suite-1/test.aaa-setup.js | 2 +-
tests/find/test-suite-1/test.and.js | 200 ++--
tests/find/test-suite-1/test.array.js | 834 +++++++-------
tests/find/test-suite-1/test.basic.js | 622 +++++------
tests/find/test-suite-1/test.basic2.js | 248 ++---
tests/find/test-suite-1/test.basic3.js | 278 +++--
tests/find/test-suite-1/test.callbacks.js | 147 ++-
tests/find/test-suite-1/test.combinational.js | 271 +++--
tests/find/test-suite-1/test.data-type-order.js | 255 +++--
tests/find/test-suite-1/test.ddoc.js | 361 +++----
tests/find/test-suite-1/test.deep-fields.js | 154 ++-
tests/find/test-suite-1/test.default-index.js | 620 +++++------
tests/find/test-suite-1/test.elem-match.js | 129 ++-
tests/find/test-suite-1/test.eq.js | 774 ++++++-------
tests/find/test-suite-1/test.errors.js | 155 ++-
tests/find/test-suite-1/test.escaping.js | 388 +++----
tests/find/test-suite-1/test.exists.js | 252 ++---
tests/find/test-suite-1/test.explain.js | 171 ++-
tests/find/test-suite-1/test.fields.js | 367 +++----
tests/find/test-suite-1/test.issue66.js | 1253 ++++++++++------------
tests/find/test-suite-1/test.limit-skip.js | 430 ++++----
tests/find/test-suite-1/test.limit.js | 392 ++++---
tests/find/test-suite-1/test.ltgt.js | 997 ++++++++---------
tests/find/test-suite-1/test.matching-indexes.js | 60 +-
tests/find/test-suite-1/test.mod.js | 199 ++--
tests/find/test-suite-1/test.ne.js | 186 ++--
tests/find/test-suite-1/test.nor.js | 52 +-
tests/find/test-suite-1/test.not.js | 167 ++-
tests/find/test-suite-1/test.or.js | 396 ++++---
tests/find/test-suite-1/test.partial.js | 8 +-
tests/find/test-suite-1/test.pick-fields.js | 84 +-
tests/find/test-suite-1/test.regex.js | 264 +++--
tests/find/test-suite-1/test.set-operations.js | 148 ++-
tests/find/test-suite-1/test.skip.js | 392 ++++---
tests/find/test-suite-1/test.sorting.js | 358 +++----
tests/find/test-suite-1/test.type.js | 120 +--
tests/find/test-suite-1/test.use-index.js | 124 +--
37 files changed, 5536 insertions(+), 6322 deletions(-)
diff --git a/tests/find/test-suite-1/test.aaa-setup.js b/tests/find/test-suite-1/test.aaa-setup.js
index c7df53775..af1cb5878 100644
--- a/tests/find/test-suite-1/test.aaa-setup.js
+++ b/tests/find/test-suite-1/test.aaa-setup.js
@@ -6,7 +6,7 @@ if (typeof process === 'undefined' || process.browser) {
beforeEach(function () {
this.timeout(60000);
- var dbName = testUtils.adapterUrl(testUtils.adapterType(), 'testdb');
+ const dbName = testUtils.adapterUrl(testUtils.adapterType(), 'testdb');
context.db = new PouchDB(dbName);
});
diff --git a/tests/find/test-suite-1/test.and.js b/tests/find/test-suite-1/test.and.js
index faa20a961..3e437123c 100644
--- a/tests/find/test-suite-1/test.and.js
+++ b/tests/find/test-suite-1/test.and.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.and.js', function () {
- it('does and for _id', function () {
- var db = context.db;
- return db.bulkDocs([
+describe('test.and.js', () => {
+ it('does and for _id', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
{ name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
{ name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
@@ -16,31 +16,29 @@ describe('test.and.js', function () {
{ name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
{ name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
{ name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ]).then(function () {
- return db.find({
- selector: {$and: [
- {_id: {$in: ['pikachu', 'puff', 'yoshi']}},
- {_id: {$gt: 'ppp'}}
- ]},
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'puff'},
- {_id: 'yoshi'},
- ]);
+ ]);
+ const resp = await db.find({
+ selector: {$and: [
+ {_id: {$in: ['pikachu', 'puff', 'yoshi']}},
+ {_id: {$gt: 'ppp'}}
+ ]},
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([
+ {_id: 'puff'},
+ {_id: 'yoshi'},
+ ]);
});
- it('does and for index', function () {
- var db = context.db;
- var index = {
+ it('does and for index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["debut"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
+ await db.createIndex(index);
+ await db.bulkDocs([
{ name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
{ name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
{ name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
@@ -53,92 +51,86 @@ describe('test.and.js', function () {
{ name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
{ name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
{ name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ]);}).then(function () {
- return db.find({
- selector: {$and: [
- {debut: {$gt: 1995}},
- {debut: {$lt: 2000}}
- ]},
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'pikachu'},
- {_id: 'puff'},
- {_id: 'falcon'},
- ]);
+ ]);
+ const resp = await db.find({
+ selector: {$and: [
+ {debut: {$gt: 1995}},
+ {debut: {$lt: 2000}}
+ ]},
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([
+ {_id: 'pikachu'},
+ {_id: 'puff'},
+ {_id: 'falcon'},
+ ]);
});
- it('does nested and for _id', function () {
- var db = context.db;
- return db.bulkDocs([
- { name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
- { name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
- { name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
- { name: 'donkey kong', rank: 7, _id: 'dk', series: 'mario', debut: 1981 },
- { name: 'pikachu', series: 'pokemon', _id: 'pikachu', rank: 1, debut: 1996 },
- { name: 'captain falcon', _id: 'falcon', rank: 4, series: 'f-zero', debut: 1990 },
- { name: 'luigi', rank: 11, _id: 'luigi', series: 'mario', debut: 1983 },
- { name: 'fox', _id: 'fox', rank: 3, series: 'star fox', debut: 1993 },
- { name: 'ness', rank: 9, _id: 'ness', series: 'earthbound', debut: 1994 },
- { name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
- { name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
- { name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ]).then(function () {
- return db.find({
- selector: {$and: [
- {debut: {$eq: 1996}},
- {$and: [
- {rank: {$eq: 8}},
- {name: {$eq: 'jigglypuff'}}
- ]}
- ]},
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'puff'},
- ]);
- });
+ it('does nested and for _id', async () => {
+ const db = context.db;
+ await db.bulkDocs([
+ { name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
+ { name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
+ { name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
+ { name: 'donkey kong', rank: 7, _id: 'dk', series: 'mario', debut: 1981 },
+ { name: 'pikachu', series: 'pokemon', _id: 'pikachu', rank: 1, debut: 1996 },
+ { name: 'captain falcon', _id: 'falcon', rank: 4, series: 'f-zero', debut: 1990 },
+ { name: 'luigi', rank: 11, _id: 'luigi', series: 'mario', debut: 1983 },
+ { name: 'fox', _id: 'fox', rank: 3, series: 'star fox', debut: 1993 },
+ { name: 'ness', rank: 9, _id: 'ness', series: 'earthbound', debut: 1994 },
+ { name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
+ { name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
+ { name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
+ ]);
+ const resp = await db.find({
+ selector: {$and: [
+ {debut: {$eq: 1996}},
+ {$and: [
+ {rank: {$eq: 8}},
+ {name: {$eq: 'jigglypuff'}}
+ ]}
+ ]},
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([
+ {_id: 'puff'},
+ ]);
+ });
- it('does nested and for index', function () {
- var db = context.db;
- var index = {
- "index": {
- "fields": ["debut"]
- }
- };
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
- { name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
- { name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
- { name: 'donkey kong', rank: 7, _id: 'dk', series: 'mario', debut: 1981 },
- { name: 'pikachu', series: 'pokemon', _id: 'pikachu', rank: 1, debut: 1996 },
- { name: 'captain falcon', _id: 'falcon', rank: 4, series: 'f-zero', debut: 1990 },
- { name: 'luigi', rank: 11, _id: 'luigi', series: 'mario', debut: 1983 },
- { name: 'fox', _id: 'fox', rank: 3, series: 'star fox', debut: 1993 },
- { name: 'ness', rank: 9, _id: 'ness', series: 'earthbound', debut: 1994 },
- { name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
- { name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
- { name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ]);}).then(function () {
- return db.find({
- selector: {$and: [
- {debut: {$eq: 1996}},
- {$and: [
- {rank: {$eq: 8}},
- {name: {$eq: 'jigglypuff'}}
- ]}
- ]},
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'puff'},
- ]);
- });
+ it('does nested and for index', async () => {
+ const db = context.db;
+ const index = {
+ "index": {
+ "fields": ["debut"]
+ }
+ };
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
+ { name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
+ { name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
+ { name: 'donkey kong', rank: 7, _id: 'dk', series: 'mario', debut: 1981 },
+ { name: 'pikachu', series: 'pokemon', _id: 'pikachu', rank: 1, debut: 1996 },
+ { name: 'captain falcon', _id: 'falcon', rank: 4, series: 'f-zero', debut: 1990 },
+ { name: 'luigi', rank: 11, _id: 'luigi', series: 'mario', debut: 1983 },
+ { name: 'fox', _id: 'fox', rank: 3, series: 'star fox', debut: 1993 },
+ { name: 'ness', rank: 9, _id: 'ness', series: 'earthbound', debut: 1994 },
+ { name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
+ { name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
+ { name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
+ ]);
+ const resp = await db.find({
+ selector: {$and: [
+ {debut: {$eq: 1996}},
+ {$and: [
+ {rank: {$eq: 8}},
+ {name: {$eq: 'jigglypuff'}}
+ ]}
+ ]},
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([
+ {_id: 'puff'},
+ ]);
+ });
});
diff --git a/tests/find/test-suite-1/test.array.js b/tests/find/test-suite-1/test.array.js
index 0f12b9bc6..06c27ba81 100644
--- a/tests/find/test-suite-1/test.array.js
+++ b/tests/find/test-suite-1/test.array.js
@@ -1,37 +1,35 @@
'use strict';
-describe('test.array.js', function () {
- beforeEach(function () {
- return context.db.bulkDocs([
+describe('test.array.js', () => {
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{ name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
{ name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
{ name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
{ name: 'William', _id: 'william', favorites: ['Mario'], age: 23}
- ]).then(function () {
- var index = {
- "index": {
- "fields": ["name"]
- },
- "name": "name-index",
- "type": "json"
- };
- return context.db.createIndex(index);
- });
+ ]);
+ const index = {
+ "index": {
+ "fields": ["name"]
+ },
+ "name": "name-index",
+ "type": "json"
+ };
+ await context.db.createIndex(index);
});
- describe('$in', function () {
- it('should return docs match single value in array', function () {
- var selector = {
+ describe('$in', () => {
+ it('should return docs match single value in array', async () => {
+ const selector = {
selector: {
favorites: {
$in: ["Mario"]
}
},
};
- var db = context.db;
- return db.find(selector)
- .then(function (resp) {
- var docs = resp.docs.map(function (doc) {
+ const db = context.db;
+ const findResp = await db.find(selector);
+ const docs = findResp.docs.map((doc) => {
delete doc._rev;
return doc;
});
@@ -41,16 +39,13 @@ describe('test.array.js', function () {
{ name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
]);
- return db.explain(selector);
- })
- .then(function (resp) {
- resp.index.name.should.deep.equal('_all_docs');
- });
+ const explainResp = await db.explain(selector);
+ explainResp.index.name.should.deep.equal('_all_docs');
});
- it('should use name index', function () {
- var db = context.db;
- var selector = {
+ it('should use name index', async () => {
+ const db = context.db;
+ const selector = {
selector: {
name: {
$in: ['James', 'Link']
@@ -60,58 +55,52 @@ describe('test.array.js', function () {
}
},
};
- return db.explain(selector)
- .then(function (resp) {
- resp.index.name.should.deep.equal('name-index');
- return db.find(selector);
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
- ]);
+ const explainResp = await db.explain(selector);
+ explainResp.index.name.should.deep.equal('name-index');
+ const findResp = await db.find(selector);
+ const docs = findResp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
});
+
+ docs.should.deep.equal([
+ { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
+ ]);
});
- it('should return docs match single value in array with defined index', function () {
- var db = context.db;
- var index = {
+ it('should return docs match single value in array with defined index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["name", "favorites"]
},
"type": "json"
};
- return db.createIndex(index)
- .then(function () {
- return db.find({
- selector: {
- name: {
- $eq: 'James'
- },
- favorites: {
- $in: ["Mario"]
- }
+ await db.createIndex(index);
+ const resp = await db.find({
+ selector: {
+ name: {
+ $eq: 'James'
},
- });
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20}
- ]);
+ favorites: {
+ $in: ["Mario"]
+ }
+ },
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20}
+ ]);
});
- it('should return docs match single field that is not an array', function () {
- var db = context.db;
- return db.find({
+ it('should return docs match single field that is not an array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
_id: {
$gt: 'a'
@@ -120,404 +109,385 @@ describe('test.array.js', function () {
$in: ['James', 'William']
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
- { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
+ { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
+ ]);
});
- it('should return docs match single field that is not an array and number', function () {
- var db = context.db;
- return db.find({
+ it('should return docs match single field that is not an array and number', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
age: {
$in: [20, 23]
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
- { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
+ { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
+ ]);
});
- it('should return docs match two values in array', function () {
- var db = context.db;
- return db.find({
+ it('should return docs match two values in array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$in: ["Mario", "Zelda"]
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
- { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
- { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
+ { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
+ { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
+ ]);
});
- it('should return no docs for no $in match', function () {
- var db = context.db;
- return db.find({
+ it('should return no docs for no $in match', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$in: ["TMNT"]
}
},
- }).then(function (resp) {
- resp.docs.should.have.length(0);
});
+ resp.docs.should.have.length(0);
});
- it('should error for non-array query value', function () {
- var db = context.db;
- return db.find({
- selector: {
- favorites: {
- $in: 'a'
- }
- },
- }).then(function () {
+ it('should error for non-array query value', async () => {
+ const db = context.db;
+ try {
+ await db.find({
+ selector: {
+ favorites: {
+ $in: 'a'
+ }
+ },
+ });
throw new Error('Function should throw');
- }, function (err) {
+ } catch (err) {
err.message.should.eq('Query operator $in must be an array. Received string: a');
- });
+ }
});
- it('should NOT error for "invalid operators" inside', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('should NOT error for "invalid operators" inside', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ _id: "1", list: [ { $or: "allowed" } ] }
- ]).then(function () {
- return db.find({
- selector: {
- list: { $in: [ { $or: "allowed" } ] },
- },
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal([ "1" ]);
- });
+ ]);
+ const resp = await db.find({
+ selector: {
+ list: { $in: [ { $or: "allowed" } ] },
+ },
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal([ "1" ]);
});
});
- describe('$all', function () {
- it('should return docs that match single value in $all array', function () {
- var db = context.db;
- return db.find({
+ describe('$all', () => {
+ it('should return docs that match single value in $all array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$all: ["Mario"]
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20},
- { name: 'William', _id: 'william', favorites: ['Mario'], age: 23}
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20},
+ { name: 'William', _id: 'william', favorites: ['Mario'], age: 23}
+ ]);
});
- it('should return docs match two values in $all array', function () {
- var db = context.db;
- return db.find({
+ it('should return docs match two values in $all array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$all: ['Mario', 'Pokemon']
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20},
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20},
+ ]);
});
- it('should return no docs for no match for $all', function () {
- var db = context.db;
- return db.find({
+ it('should return no docs for no match for $all', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$all: ["Mario", "Zelda"]
}
},
- }).then(function (resp) {
- resp.docs.should.have.length(0);
});
+ resp.docs.should.have.length(0);
});
- it('should error for non-array query value', function () {
- var db = context.db;
- return db.find({
- selector: {
- favorites: {
- $all: 'a'
- }
- },
- }).then(function () {
+ it('should error for non-array query value', async () => {
+ const db = context.db;
+ try {
+ await db.find({
+ selector: {
+ favorites: {
+ $all: 'a'
+ }
+ },
+ });
throw new Error('Function should throw');
- }, function (err) {
+ } catch (err) {
err.message.should.eq('Query operator $all must be an array. Received string: a');
- });
+ }
});
- it('should NOT error for "invalid operators" inside', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('should NOT error for "invalid operators" inside', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ _id: "1", list: [ { $or: "allowed" } ] }
- ]).then(function () {
- return db.find({
- selector: {
- list: { $all: [ { $or: "allowed" } ] },
- },
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal([ "1" ]);
- });
+ ]);
+ const resp = await db.find({
+ selector: {
+ list: { $all: [ { $or: "allowed" } ] },
+ },
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal([ "1" ]);
});
});
- describe('$size', function () {
- it('should return docs with array length 1', function () {
- var db = context.db;
- return db.find({
+ describe('$size', () => {
+ it('should return docs with array length 1', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$size: 1
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
- { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
+ { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
+ ]);
});
- it('should return docs array length 2', function () {
- var db = context.db;
- return db.find({
+ it('should return docs array length 2', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$size: 2
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
- { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22 },
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'James', _id: 'james', favorites: ['Mario', 'Pokemon'], age: 20 },
+ { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22 },
+ ]);
});
- it('should return no docs for length 5', function () {
- var db = context.db;
- return db.find({
+ it('should return no docs for length 5', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$size: 5
}
},
- }).then(function (resp) {
- resp.docs.should.have.length(0);
});
+ resp.docs.should.have.length(0);
});
- it('should error on non-int query values', function () {
- var db = context.db;
- return db.find({
- selector: {
- favorites: {
- $size: 2.1
- }
- },
- }).then(function () {
+ it('should error on non-int query values', async () => {
+ const db = context.db;
+ try {
+ await db.find({
+ selector: {
+ favorites: {
+ $size: 2.1
+ }
+ },
+ });
throw new Error('Function should throw');
- }, function (err) {
+ } catch (err) {
err.message.should.eq('Query operator $size must be a integer. Received number: 2.1');
- });
+ }
});
- it('should ignore non-array field values', function () {
- var db = context.db;
- return context.db.bulkDocs([
+ it('should ignore non-array field values', async () => {
+ const db = context.db;
+ await context.db.bulkDocs([
{ _id: "string", unknown: "str" },
{ _id: "array", unknown: [ "a", "b", "c" ] },
- ]).then(function () {
- return db.find({
- selector: {
- unknown: { $size: 3 }
- },
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { _id: "array", unknown: [ "a", "b", "c" ] },
- ]);
- });
+ ]);
+ const resp = await db.find({
+ selector: {
+ unknown: { $size: 3 }
+ },
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { _id: "array", unknown: [ "a", "b", "c" ] },
+ ]);
});
});
- describe('$nin', function () {
- it('should return docs match single value $nin array', function () {
- var db = context.db;
- return db.find({
+ describe('$nin', () => {
+ it('should return docs match single value $nin array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$nin: ["Mario"]
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
- { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
+ { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
+ ]);
});
- it('should return docs that do not match single field that is not an array', function () {
- var db = context.db;
- return db.find({
+ it('should return docs that do not match single field that is not an array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
name: {
$nin: ['James', 'William']
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
- { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
+ { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
+ ]);
});
- it('should return docs with single field that is not an array and number', function () {
- var db = context.db;
- return db.find({
+ it('should return docs with single field that is not an array and number', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
age: {
$nin: [20, 23]
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
- { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'Link', _id: 'link', favorites: ['Zelda', 'Pokemon'], age: 22},
+ { name: 'Mary', _id: 'mary', favorites: ['Pokemon'], age: 21 },
+ ]);
});
- it('should return docs that do not match two values $nin array', function () {
- var db = context.db;
- return db.find({
+ it('should return docs that do not match two values $nin array', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$nin: ["Pokemon", "Zelda"]
}
},
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
- ]);
});
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
+ { name: 'William', _id: 'william', favorites: ['Mario'], age: 23 }
+ ]);
});
- it('should return all docs for no match for $nin', function () {
- var db = context.db;
- return db.find({
+ it('should return all docs for no match for $nin', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$nin: ["TMNT"]
}
},
- }).then(function (resp) {
- resp.docs.should.have.length(4);
});
+ resp.docs.should.have.length(4);
});
- it('should work for _id field', function () {
- var db = context.db;
- return db.find({
+ it('should work for _id field', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
_id: {
$nin: ['james', 'mary']
}
},
fields: ["_id"]
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'link'},
- {_id: 'william'},
- ]);
});
+ resp.docs.should.deep.equal([
+ {_id: 'link'},
+ {_id: 'william'},
+ ]);
});
- it('$nin work with complex array #6280', function () {
- var db = context.db;
- return context.db.bulkDocs([
+ it('$nin work with complex array #6280', async () => {
+ const db = context.db;
+ await context.db.bulkDocs([
{
_id: 'smith',
lastName: 'Smith',
@@ -539,73 +509,66 @@ describe('test.array.js', function () {
year: 2013,
type: 'person'
}
- ])
- .then(function () {
- return db.createIndex({
- index: {
- fields: ['lastName','absents','year','type'],
- name: 'myIndex',
- ddoc: 'myIndex'
- }
- });
- })
- .then(function () {
- return db.find({
- selector: {
- lastName: {$gt: null},
- year: {$gt: null},
- type: 'person',
- absents: {
- $nin: ['10/10/15']
- }
- },
- fields: ["_id"]
+ ]);
+ await db.createIndex({
+ index: {
+ fields: ['lastName','absents','year','type'],
+ name: 'myIndex',
+ ddoc: 'myIndex'
+ }
});
- })
- .then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'jones'},
- {_id: 'roberts'},
- ]);
- });
- });
- it('should error for non-array query value', function () {
- var db = context.db;
- return db.find({
+ const resp = await db.find({
selector: {
- favorites: {
- $nin: 'a'
+ lastName: {$gt: null},
+ year: {$gt: null},
+ type: 'person',
+ absents: {
+ $nin: ['10/10/15']
}
},
- }).then(function () {
- throw new Error('Function should throw');
- }, function (err) {
- err.message.should.eq('Query operator $nin must be an array. Received string: a');
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([
+ {_id: 'jones'},
+ {_id: 'roberts'},
+ ]);
});
- it('should NOT error for "invalid operators" inside', function () {
- var db = context.db;
- return db.bulkDocs([
- { _id: "1", list: [ { $or: "allowed" } ] },
- { _id: "2", list: [ { $or: "not-allowed" } ] }
- ]).then(function () {
- return db.find({
+ it('should error for non-array query value', async () => {
+ const db = context.db;
+ try {
+ await db.find({
selector: {
- list: { $nin: [ { $or: "not-allowed" } ] },
+ favorites: {
+ $nin: 'a'
+ }
},
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal([ "1" ]);
});
+ throw new Error('Function should throw');
+ } catch (err) {
+ err.message.should.eq('Query operator $nin must be an array. Received string: a');
+ }
+ });
+ it('should NOT error for "invalid operators" inside', async () => {
+ const db = context.db;
+ await db.bulkDocs([
+ { _id: "1", list: [ { $or: "allowed" } ] },
+ { _id: "2", list: [ { $or: "not-allowed" } ] }
+ ]);
+ const resp = await db.find({
+ selector: {
+ list: { $nin: [ { $or: "not-allowed" } ] },
+ },
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal([ "1" ]);
});
});
- describe("$allMatch", function () {
- it("returns zero docs for field that is not an array", function () {
- var db = context.db;
- return db.find({
+ describe("$allMatch", () => {
+ it("returns zero docs for field that is not an array", async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
name: {
$allMatch: {
@@ -613,41 +576,35 @@ describe('test.array.js', function () {
}
}
}
- })
- .then(function (resp) {
- resp.docs.length.should.equal(0);
});
+ resp.docs.length.should.equal(0);
});
//CouchDB is returing a different result
- it.skip("returns false if field isn't in doc", function () {
- var docs = [
+ it.skip("returns false if field isn't in doc", async () => {
+ const docs = [
{
"user_id": "a",
"bang": []
}
];
- var db = context.db;
- return db.bulkDocs(docs)
- .then(function () {
- return db.find({
- selector: {
- bang: {
- "$allMatch": {
- "$eq": "Pokemon",
- }
+ const db = context.db;
+ await db.bulkDocs(docs);
+ const resp = await db.find({
+ selector: {
+ bang: {
+ "$allMatch": {
+ "$eq": "Pokemon",
}
}
- });
- })
- .then(function (resp) {
- resp.docs.length.should.equal(0);
+ }
});
+ resp.docs.length.should.equal(0);
});
- it("matches against array", function () {
- var db = context.db;
- return db.find({
+ it("matches against array", async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
favorites: {
$allMatch: {
@@ -656,16 +613,14 @@ describe('test.array.js', function () {
}
},
fields: ["_id"]
- })
- .then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'mary'},
- ]);
});
+ resp.docs.should.deep.equal([
+ {_id: 'mary'},
+ ]);
});
- it("works with object array", function () {
- var docs = [
+ it("works with object array", async () => {
+ const docs = [
{
"user_id": "a",
"bang": [
@@ -693,62 +648,57 @@ describe('test.array.js', function () {
]
}
];
- var db = context.db;
- return db.bulkDocs(docs)
- .then(function () {
- return db.find({
- selector: {
- bang: {
- "$allMatch": {
- "foo": {"$mod": [2,1]},
- "bar": {"$mod": [2,0]}
- }
+ const db = context.db;
+ await db.bulkDocs(docs);
+ const resp = await db.find({
+ selector: {
+ bang: {
+ "$allMatch": {
+ "foo": {"$mod": [2,1]},
+ "bar": {"$mod": [2,0]}
}
- },
- fields: ["user_id"]
- });
- })
- .then(function (resp) {
- resp.docs.should.deep.equal([
- {user_id: "a"}
- ]);
+ }
+ },
+ fields: ["user_id"]
});
+ resp.docs.should.deep.equal([
+ {user_id: "a"}
+ ]);
});
- it('should error for non-object query value', function () {
- var db = context.db;
- return db.find({
- selector: {
- bang: {
- "$allMatch": 'a'
- }
- },
- }).then(function () {
+ it('should error for non-object query value', async () => {
+ const db = context.db;
+ try {
+ await db.find({
+ selector: {
+ bang: {
+ "$allMatch": 'a'
+ }
+ },
+ });
throw new Error('Function should throw');
- }, function (err) {
+ } catch (err) {
err.message.should.eq('Query operator $allMatch must be an object. Received string: a');
- });
+ }
});
- it('with null value in array', function () {
- var db = context.db;
- var docs = [
+ it('with null value in array', async () => {
+ const db = context.db;
+ const docs = [
{_id: '1', values: [null, null]},
{_id: '2', values: [1, null, 3]},
{_id: '3', values: [1, 2, 3]}
];
- return db.bulkDocs(docs).then(function () {
- return db.find({
- selector: {
- values: {$allMatch: {$eq: null}},
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal(['1']);
- });
+ await db.bulkDocs(docs);
+ const resp = await db.find({
+ selector: {
+ values: {$allMatch: {$eq: null}},
+ },
+ fields: ['_id']
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal(['1']);
});
});
});
diff --git a/tests/find/test-suite-1/test.basic.js b/tests/find/test-suite-1/test.basic.js
index d6e4ed51b..521333d5d 100644
--- a/tests/find/test-suite-1/test.basic.js
+++ b/tests/find/test-suite-1/test.basic.js
@@ -1,81 +1,76 @@
'use strict';
-describe('test.basic.js', function () {
- it('should create an index', function () {
- var db = context.db;
- var index = {
+describe('test.basic.js', () => {
+ it('should create an index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return db.createIndex(index);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('exists');
- });
+ const createResp = await db.createIndex(index);
+ createResp.id.should.match(/^_design\//);
+ createResp.name.should.equal('foo-index');
+ createResp.result.should.equal('created');
+ const existsResp = await db.createIndex(index);
+ existsResp.id.should.match(/^_design\//);
+ existsResp.name.should.equal('foo-index');
+ existsResp.result.should.equal('exists');
});
- it('should not update an existing index', function () {
- var db = context.db;
- var index = {
+ it('should not update an existing index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return db.createIndex(index);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('exists');
- return response.id;
- }).then(function (ddocId) {
- return db.get(ddocId);
- }).then(function (doc) {
- doc._rev.slice(0, 1).should.equal('1');
- });
+ const createResp = await db.createIndex(index);
+ createResp.id.should.match(/^_design\//);
+ createResp.name.should.equal('foo-index');
+ createResp.result.should.equal('created');
+ const existsResp = await db.createIndex(index);
+ existsResp.id.should.match(/^_design\//);
+ existsResp.name.should.equal('foo-index');
+ existsResp.result.should.equal('exists');
+ const doc = await db.get(existsResp.id);
+ doc._rev.slice(0, 1).should.equal('1');
});
- it('throws an error for an invalid index creation', function () {
- var db = context.db;
- return db.createIndex('yo yo yo').then(function () {
+ it('throws an error for an invalid index creation', async () => {
+ const db = context.db;
+ try {
+ await db.createIndex('yo yo yo');
throw new Error('expected an error');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('throws an error for an invalid index deletion', function () {
- var db = context.db;
- return db.deleteIndex('yo yo yo').then(function () {
+ it('throws an error for an invalid index deletion', async () => {
+ const db = context.db;
+ try {
+ await db.deleteIndex('yo yo yo');
throw new Error('expected an error');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('should not recognize duplicate indexes', function () {
- var db = context.db;
- var index = {
+ it('should not recognize duplicate indexes', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- var index2 = {
+ const index2 = {
"index": {
"fields": ["foo"]
},
@@ -83,175 +78,161 @@ describe('test.basic.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return db.createIndex(index2);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('bar-index');
- response.result.should.equal('created');
- return db.getIndexes();
- }).then(function (res) {
- res.indexes.should.have.length(3);
- var ddoc1 = res.indexes[1].ddoc;
- var ddoc2 = res.indexes[2].ddoc;
- ddoc1.should.not.equal(ddoc2,
- 'essentially duplicate indexes are not md5summed to the' +
- 'same ddoc');
- });
+ const fooResp = await db.createIndex(index);
+ fooResp.id.should.match(/^_design\//);
+ fooResp.name.should.equal('foo-index');
+ fooResp.result.should.equal('created');
+ const barResp = await db.createIndex(index2);
+ barResp.id.should.match(/^_design\//);
+ barResp.name.should.equal('bar-index');
+ barResp.result.should.equal('created');
+ const res = await db.getIndexes();
+ res.indexes.should.have.length(3);
+ const ddoc1 = res.indexes[1].ddoc;
+ const ddoc2 = res.indexes[2].ddoc;
+ ddoc1.should.not.equal(ddoc2,
+ `essentially duplicate indexes are not md5summed to the` +
+ `same ddoc`);
});
- it.skip('should find existing indexes', function () {
- var db = context.db;
- return db.getIndexes().then(function (response) {
- response.should.deep.equal({
- "total_rows": 1,
- indexes: [{
- ddoc: null,
- name: '_all_docs',
- type: 'special',
- def: {fields: [{_id: 'asc'}]}
- }]
- });
- var index = {
- "index": {
- "fields": ["foo"]
+ it.skip('should find existing indexes', async () => {
+ const db = context.db;
+ const initialResp = await db.getIndexes();
+ initialResp.should.deep.equal({
+ "total_rows": 1,
+ indexes: [{
+ ddoc: null,
+ name: '_all_docs',
+ type: 'special',
+ def: {fields: [{_id: 'asc'}]}
+ }]
+ });
+ const index = {
+ "index": {
+ "fields": ["foo"]
+ },
+ "name": "foo-index",
+ "type": "json"
+ };
+ await db.createIndex(index);
+ const resp = await db.getIndexes();
+ const ddoc = resp.indexes[1].ddoc;
+ ddoc.should.match(/_design\/.+/);
+ delete resp.indexes[1].ddoc;
+ console.log(JSON.stringify(resp));
+ resp.should.deep.equal({
+ "total_rows": 2,
+ "indexes": [
+ {
+ "ddoc": null,
+ "name": "_all_docs",
+ "type": "special",
+ "def": {
+ "fields": [
+ {
+ "_id": "asc"
+ }
+ ]
+ }
},
- "name": "foo-index",
- "type": "json"
- };
- return db.createIndex(index);
- }).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- var ddoc = resp.indexes[1].ddoc;
- ddoc.should.match(/_design\/.+/);
- delete resp.indexes[1].ddoc;
- console.log(JSON.stringify(resp));
- resp.should.deep.equal({
- "total_rows": 2,
- "indexes": [
- {
- "ddoc": null,
- "name": "_all_docs",
- "type": "special",
- "def": {
- "fields": [
- {
- "_id": "asc"
- }
- ]
- }
- },
- {
- "name": "foo-index",
- "type": "json",
- "def": {
- "fields": [
- {
- "foo": "asc"
- }
- ]
- }
+ {
+ "name": "foo-index",
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "foo": "asc"
+ }
+ ]
}
- ]
- });
+ }
+ ]
});
});
- it.skip('should create ddocs automatically', function () {
- var db = context.db;
- var index = {
+ it.skip('should create ddocs automatically', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- var ddocId;
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- ddocId = resp.indexes[1].ddoc;
- return db.get(ddocId);
- }).then(function (ddoc) {
- ddoc._id.should.equal(ddocId);
- should.exist(ddoc._rev);
- delete ddoc._id;
- delete ddoc._rev;
- delete ddoc.views['foo-index'].options.w; // wtf is this?
- ddoc.should.deep.equal({
- "language": "query",
- "views": {
- "foo-index": {
- "map": {
- "fields": {
- "foo": "asc"
- }
- },
- "reduce": "_count",
- "options": {
- "def": {
- "fields": [
- "foo"
- ]
- }
+ await db.createIndex(index);
+ const indexesResp = await db.getIndexes();
+ const ddocId = indexesResp.indexes[1].ddoc;
+ const ddoc = await db.get(ddocId);
+ ddoc._id.should.equal(ddocId);
+ should.exist(ddoc._rev);
+ delete ddoc._id;
+ delete ddoc._rev;
+ delete ddoc.views['foo-index'].options.w; // wtf is this?
+ ddoc.should.deep.equal({
+ "language": "query",
+ "views": {
+ "foo-index": {
+ "map": {
+ "fields": {
+ "foo": "asc"
+ }
+ },
+ "reduce": "_count",
+ "options": {
+ "def": {
+ "fields": [
+ "foo"
+ ]
}
}
}
- });
+ }
});
});
- it.skip('should create ddocs automatically 2', function () {
- var db = context.db;
- var index = {
+ it.skip('should create ddocs automatically 2', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [{"foo": "asc"}]
},
"name": "foo-index",
"type": "json"
};
- var ddocId;
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- ddocId = resp.indexes[1].ddoc;
- return db.get(ddocId);
- }).then(function (ddoc) {
- ddoc._id.should.equal(ddocId);
- should.exist(ddoc._rev);
- delete ddoc._id;
- delete ddoc._rev;
- delete ddoc.views['foo-index'].options.w; // wtf is this?
- ddoc.should.deep.equal({
- "language": "query",
- "views": {
- "foo-index": {
- "map": {
- "fields": {
- "foo": "asc"
- }
- },
- "reduce": "_count",
- "options": {
- "def": {
- "fields": [
- {"foo": "asc"}
- ]
- }
+ await db.createIndex(index);
+ const indexesResp = await db.getIndexes();
+ const ddocId = indexesResp.indexes[1].ddoc;
+ const ddoc = await db.get(ddocId);
+ ddoc._id.should.equal(ddocId);
+ should.exist(ddoc._rev);
+ delete ddoc._id;
+ delete ddoc._rev;
+ delete ddoc.views['foo-index'].options.w; // wtf is this?
+ ddoc.should.deep.equal({
+ "language": "query",
+ "views": {
+ "foo-index": {
+ "map": {
+ "fields": {
+ "foo": "asc"
+ }
+ },
+ "reduce": "_count",
+ "options": {
+ "def": {
+ "fields": [
+ {"foo": "asc"}
+ ]
}
}
}
- });
+ }
});
});
- it.skip('should create ddocs automatically 3', function () {
- var db = context.db;
- var index = {
+ it.skip('should create ddocs automatically 3', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
{"foo": "asc"},
@@ -261,232 +242,207 @@ describe('test.basic.js', function () {
"name": "foo-index",
"type": "json"
};
- var ddocId;
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- ddocId = resp.indexes[1].ddoc;
- return db.get(ddocId);
- }).then(function (ddoc) {
- ddoc._id.should.equal(ddocId);
- should.exist(ddoc._rev);
- delete ddoc._id;
- delete ddoc._rev;
- delete ddoc.views['foo-index'].options.w; // wtf is this?
- ddoc.should.deep.equal({
- "language": "query",
- "views": {
- "foo-index": {
- "map": {
- "fields": {
- "foo": "asc",
- "bar": "asc"
- }
- },
- "reduce": "_count",
- "options": {
- "def": {
- "fields": [
- {"foo": "asc"},
- "bar"
- ]
- }
+ await db.createIndex(index);
+ const indexesResp = await db.getIndexes();
+ const ddocId = indexesResp.indexes[1].ddoc;
+ const ddoc = await db.get(ddocId);
+ ddoc._id.should.equal(ddocId);
+ should.exist(ddoc._rev);
+ delete ddoc._id;
+ delete ddoc._rev;
+ delete ddoc.views['foo-index'].options.w; // wtf is this?
+ ddoc.should.deep.equal({
+ "language": "query",
+ "views": {
+ "foo-index": {
+ "map": {
+ "fields": {
+ "foo": "asc",
+ "bar": "asc"
+ }
+ },
+ "reduce": "_count",
+ "options": {
+ "def": {
+ "fields": [
+ {"foo": "asc"},
+ "bar"
+ ]
}
}
}
- });
+ }
});
});
- it.skip('deletes indexes, callback style', function () {
- var db = context.db;
- var index = {
+ it.skip('deletes indexes, callback style', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return new Promise(function (resolve, reject) {
- db.createIndex(index, function (err) {
+ await new Promise((resolve, reject) => {
+ db.createIndex(index, (err) => {
if (err) {
return reject(err);
}
resolve();
});
- }).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- return new Promise(function (resolve, reject) {
- db.deleteIndex(resp.indexes[1], function (err, resp) {
- if (err) {
- return reject(err);
- }
- resolve(resp);
- });
- });
- }).then(function (resp) {
- resp.should.deep.equal({ok: true});
- return db.getIndexes();
- }).then(function (resp) {
- resp.should.deep.equal({
- "total_rows": 1,
- "indexes":[{
- "ddoc": null,
- "name":"_all_docs",
- "type":"special",
- "def":{ "fields": [{"_id": "asc"}] }
- }]
+ });
+ const getResp = await db.getIndexes();
+ const deleteResp = await new Promise((resolve, reject) => {
+ db.deleteIndex(getResp.indexes[1], (err, resp) => {
+ if (err) {
+ return reject(err);
+ }
+ resolve(resp);
});
});
+ deleteResp.should.deep.equal({ok: true});
+ const finalResp = await db.getIndexes();
+ finalResp.should.deep.equal({
+ "total_rows": 1,
+ "indexes":[{
+ "ddoc": null,
+ "name":"_all_docs",
+ "type":"special",
+ "def":{ "fields": [{"_id": "asc"}] }
+ }]
+ });
});
- it('deletes indexes', function () {
- var db = context.db;
- var index = {
+ it('deletes indexes', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- return db.deleteIndex(resp.indexes[1]);
- }).then(function (resp) {
- resp.should.deep.equal({ok: true});
- return db.getIndexes();
- }).then(function (resp) {
- resp.should.deep.equal({
- "total_rows": 1,
- "indexes":[{
- "ddoc": null,
- "name":"_all_docs",
- "type":"special",
- "def":{ "fields": [{"_id": "asc"}] }
- }]
- });
+ await db.createIndex(index);
+ const getResp = await db.getIndexes();
+ const deleteResp = await db.deleteIndex(getResp.indexes[1]);
+ deleteResp.should.deep.equal({ok: true});
+ const finalResp = await db.getIndexes();
+ finalResp.should.deep.equal({
+ "total_rows": 1,
+ "indexes":[{
+ "ddoc": null,
+ "name":"_all_docs",
+ "type":"special",
+ "def":{ "fields": [{"_id": "asc"}] }
+ }]
});
});
- it.skip('deletes indexes, no type', function () {
- var db = context.db;
- var index = {
+ it.skip('deletes indexes, no type', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index"
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- delete resp.indexes[1].type;
- return db.deleteIndex(resp.indexes[1]);
- }).then(function (resp) {
- resp.should.deep.equal({ok: true});
- return db.getIndexes();
- }).then(function (resp) {
- resp.should.deep.equal({
- "total_rows": 1,
- "indexes":[{
- "ddoc": null,
- "name":"_all_docs",
- "type":"special",
- "def":{ "fields": [{"_id": "asc"}] }
- }]
- });
+ await db.createIndex(index);
+ const getResp = await db.getIndexes();
+ delete getResp.indexes[1].type;
+ const deleteResp = await db.deleteIndex(getResp.indexes[1]);
+ deleteResp.should.deep.equal({ok: true});
+ const finalResp = await db.getIndexes();
+ finalResp.should.deep.equal({
+ "total_rows": 1,
+ "indexes":[{
+ "ddoc": null,
+ "name":"_all_docs",
+ "type":"special",
+ "def":{ "fields": [{"_id": "asc"}] }
+ }]
});
});
- it('deletes indexes, no ddoc', function () {
- var db = context.db;
- var index = {
+ it('deletes indexes, no ddoc', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index"
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- delete resp.indexes[1].ddoc;
- return db.deleteIndex(resp.indexes[1]);
- }).then(function () {
+ await db.createIndex(index);
+ const getResp = await db.getIndexes();
+ delete getResp.indexes[1].ddoc;
+ try {
+ await db.deleteIndex(getResp.indexes[1]);
throw new Error('expected an error due to no ddoc');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('deletes indexes, no name', function () {
- var db = context.db;
- var index = {
+ it('deletes indexes, no name', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index"
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- delete resp.indexes[1].name;
- return db.deleteIndex(resp.indexes[1]);
- }).then(function () {
+ await db.createIndex(index);
+ const getResp = await db.getIndexes();
+ delete getResp.indexes[1].name;
+ try {
+ await db.deleteIndex(getResp.indexes[1]);
throw new Error('expected an error due to no name');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('deletes indexes, one name per ddoc', function () {
- var db = context.db;
- var index = {
+ it('deletes indexes, one name per ddoc', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "myname",
"ddoc": "myddoc"
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- return db.deleteIndex(resp.indexes[1]);
- }).then(function () {
- return db.get('_design/myddoc');
- }).then(function () {
+ await db.createIndex(index);
+ const getResp = await db.getIndexes();
+ await db.deleteIndex(getResp.indexes[1]);
+ try {
+ await db.get('_design/myddoc');
throw new Error('expected an error');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('deletes indexes, many names per ddoc', function () {
- var db = context.db;
- var index = {
+ it('deletes indexes, many names per ddoc', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "myname",
"ddoc": "myddoc"
};
- var index2 = {
+ const index2 = {
"index": {
"fields": ["bar"]
},
"name": "myname2",
"ddoc": "myddoc"
};
- return db.createIndex(index).then(function () {
- return db.createIndex(index2);
- }).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- return db.deleteIndex(resp.indexes[1]);
- }).then(function () {
- return db.get('_design/myddoc');
- }).then(function (ddoc) {
- Object.keys(ddoc.views).should.deep.equal(['myname2']);
- });
+ await db.createIndex(index);
+ await db.createIndex(index2);
+ const getResp = await db.getIndexes();
+ await db.deleteIndex(getResp.indexes[1]);
+ const ddoc = await db.get('_design/myddoc');
+ Object.keys(ddoc.views).should.deep.equal(['myname2']);
});
});
diff --git a/tests/find/test-suite-1/test.basic2.js b/tests/find/test-suite-1/test.basic2.js
index 85a87d53c..e404c7440 100644
--- a/tests/find/test-suite-1/test.basic2.js
+++ b/tests/find/test-suite-1/test.basic2.js
@@ -1,10 +1,10 @@
'use strict';
-describe('test.basic2.js', function () {
- var sortById = testUtils.sortById;
+describe('test.basic2.js', () => {
+ const sortById = testUtils.sortById;
- beforeEach(function () {
- return context.db.bulkDocs([
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{ name: 'Mario', _id: 'mario', rank: 5, series: 'Mario', debut: 1981 },
{ name: 'Jigglypuff', _id: 'puff', rank: 8, series: 'Pokemon', debut: 1996 },
{ name: 'Link', rank: 10, _id: 'link', series: 'Zelda', debut: 1986 },
@@ -20,173 +20,155 @@ describe('test.basic2.js', function () {
]);
});
- it('should not include ddocs in _id results', function () {
- var db = context.db;
- var index = {
+ it('should not include ddocs in _id results', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function () {
- return db.find({
- selector: {_id: {$gt: '\u0000'}},
- fields: ['_id'],
- sort: ['_id']
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id": "dk"},
- {"_id": "falcon"},
- {"_id": "fox"},
- {"_id": "kirby"},
- {"_id": "link"},
- {"_id": "luigi"},
- {"_id": "mario"},
- {"_id": "ness"},
- {"_id": "pikachu"},
- {"_id": "puff"},
- {"_id": "samus"},
- {"_id": "yoshi"}
- ]);
- });
+ await db.createIndex(index);
+ await db.getIndexes();
+ const response = await db.find({
+ selector: {_id: {$gt: '\u0000'}},
+ fields: ['_id'],
+ sort: ['_id']
});
+ response.docs.should.deep.equal([
+ {"_id": "dk"},
+ {"_id": "falcon"},
+ {"_id": "fox"},
+ {"_id": "kirby"},
+ {"_id": "link"},
+ {"_id": "luigi"},
+ {"_id": "mario"},
+ {"_id": "ness"},
+ {"_id": "pikachu"},
+ {"_id": "puff"},
+ {"_id": "samus"},
+ {"_id": "yoshi"}
+ ]);
});
- it('should find debut > 1990', function () {
- var db = context.db;
- return db.createIndex({
+ it('should find debut > 1990', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["name"]
}
- }).then(function () {
- return db.createIndex({
- index: {fields: ['debut']}
- });
- }).then(function () {
- return db.find({
- selector: {debut: {$gt: 1990}},
- fields: ['_id'],
- sort: ['debut']
- });
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id":"kirby"},
- {"_id":"fox"},
- {"_id":"ness"},
- {"_id":"pikachu"},
- {"_id":"puff"}
- ]);
});
+ await db.createIndex({
+ index: {fields: ['debut']}
+ });
+ const response = await db.find({
+ selector: {debut: {$gt: 1990}},
+ fields: ['_id'],
+ sort: ['debut']
+ });
+ response.docs.should.deep.equal([
+ {"_id":"kirby"},
+ {"_id":"fox"},
+ {"_id":"ness"},
+ {"_id":"pikachu"},
+ {"_id":"puff"}
+ ]);
});
- it('should find debut > 1990 2', function () {
- var db = context.db;
- return db.createIndex({
+ it('should find debut > 1990 2', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["name"]
}
- }).then(function () {
- return db.createIndex({
- index: {fields: ['debut']}
- });
- }).then(function () {
- return db.createIndex({
- index: {fields: ['series', 'debut']}
- });
- }).then(function () {
- return db.find({
- selector: {debut: {$gt: 1990}},
- fields: ['_id'],
- sort: ['debut']
- });
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id":"kirby"},
- {"_id":"fox"},
- {"_id":"ness"},
- {"_id":"pikachu"},
- {"_id":"puff"}
- ]);
});
+ await db.createIndex({
+ index: {fields: ['debut']}
+ });
+ await db.createIndex({
+ index: {fields: ['series', 'debut']}
+ });
+ const response = await db.find({
+ selector: {debut: {$gt: 1990}},
+ fields: ['_id'],
+ sort: ['debut']
+ });
+ response.docs.should.deep.equal([
+ {"_id":"kirby"},
+ {"_id":"fox"},
+ {"_id":"ness"},
+ {"_id":"pikachu"},
+ {"_id":"puff"}
+ ]);
});
- it('should find debut > 1990 3', function () {
- var db = context.db;
- return db.createIndex({
+ it('should find debut > 1990 3', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["name"]
}
- }).then(function () {
- return db.createIndex({
- index: {fields: ['debut']}
- });
- }).then(function () {
- return db.createIndex({
- index: {fields: ['series', 'debut']}
- });
- }).then(function () {
- return db.find({
- selector: {debut: {$gt: 1990}},
- fields: ['_id']
- });
- }).then(function (response) {
- response.docs.sort(sortById);
- response.docs.should.deep.equal([
- {"_id":"fox"},
- {"_id":"kirby"},
- {"_id":"ness"},
- {"_id":"pikachu"},
- {"_id":"puff"}
- ]);
});
+ await db.createIndex({
+ index: {fields: ['debut']}
+ });
+ await db.createIndex({
+ index: {fields: ['series', 'debut']}
+ });
+ const response = await db.find({
+ selector: {debut: {$gt: 1990}},
+ fields: ['_id']
+ });
+ response.docs.sort(sortById);
+ response.docs.should.deep.equal([
+ {"_id":"fox"},
+ {"_id":"kirby"},
+ {"_id":"ness"},
+ {"_id":"pikachu"},
+ {"_id":"puff"}
+ ]);
});
- it('should find series == mario', function () {
- var db = context.db;
- return db.createIndex({
+ it('should find series == mario', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["name"]
}
- }).then(function () {
- return db.createIndex({
- index: {fields: ['debut']}
- });
- }).then(function () {
- return db.createIndex({
- index: {fields: ['series', 'debut']}
- });
- }).then(function () {
- return db.find({
- selector: {series: {$eq: 'Mario'}},
- fields: ['_id', 'debut'],
- sort: [{series: 'desc'}, {debut: 'desc'}]
- });
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id":"yoshi","debut":1990},
- {"_id":"luigi","debut":1983},
- {"_id":"mario","debut":1981},
- {"_id":"dk","debut":1981}
- ]);
});
+ await db.createIndex({
+ index: {fields: ['debut']}
+ });
+ await db.createIndex({
+ index: {fields: ['series', 'debut']}
+ });
+ const response = await db.find({
+ selector: {series: {$eq: 'Mario'}},
+ fields: ['_id', 'debut'],
+ sort: [{series: 'desc'}, {debut: 'desc'}]
+ });
+ response.docs.should.deep.equal([
+ {"_id":"yoshi","debut":1990},
+ {"_id":"luigi","debut":1983},
+ {"_id":"mario","debut":1981},
+ {"_id":"dk","debut":1981}
+ ]);
});
- it('throws an error for an invalid selector/sort', function () {
- var db = context.db;
- return db.createIndex({
+ it('throws an error for an invalid selector/sort', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {fields: ['series', 'debut']}
- }).then(function () {
- return db.find({
+ });
+ try {
+ await db.find({
selector: {series: 'Mario', debut: 1981},
sort: ['name']
});
- }).then(function () {
throw new Error('expected an error');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
});
diff --git a/tests/find/test-suite-1/test.basic3.js b/tests/find/test-suite-1/test.basic3.js
index f94b4a412..af661ac66 100644
--- a/tests/find/test-suite-1/test.basic3.js
+++ b/tests/find/test-suite-1/test.basic3.js
@@ -1,10 +1,10 @@
'use strict';
-describe('test.basic3.js', function () {
- var sortById = testUtils.sortById;
+describe('test.basic3.js', () => {
+ const sortById = testUtils.sortById;
- beforeEach(function () {
- return context.db.bulkDocs([
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{ name: 'Mario', _id: 'mario', rank: 5, series: 'Mario', debut: 1981, awesome: true },
{ name: 'Jigglypuff', _id: 'puff', rank: 8, series: 'Pokemon', debut: 1996,
awesome: false },
@@ -24,219 +24,183 @@ describe('test.basic3.js', function () {
]);
});
- it('should be able to search for numbers', function () {
- var db = context.db;
- var index = {
+ it('should be able to search for numbers', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["rank"]
}
};
- return db.createIndex(index).then(function () {
- return db.find({
- selector: {rank: 12},
- fields: ['_id']
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id": "samus"}
- ]);
- });
+ await db.createIndex(index);
+ const response = await db.find({
+ selector: {rank: 12},
+ fields: ['_id']
});
+ response.docs.should.deep.equal([
+ {"_id": "samus"}
+ ]);
});
- it('should use $exists for an in-memory filter', function () {
- var db = context.db;
- var index = {
+ it('should use $exists for an in-memory filter', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["rank"]
}
};
- return db.createIndex(index).then(function () {
- return db.find({
- selector: {rank: 12, name: {$exists: true}},
- fields: ['_id']
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id": "samus"}
- ]);
- });
+ await db.createIndex(index);
+ const response = await db.find({
+ selector: {rank: 12, name: {$exists: true}},
+ fields: ['_id']
});
+ response.docs.should.deep.equal([
+ {"_id": "samus"}
+ ]);
});
- it('should be able to search for 0', function () {
- var db = context.db;
- var index = {
+ it('should be able to search for 0', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["rank"]
}
};
- return db.createIndex(index).then(function () {
- return db.find({
- selector: {rank: 0},
- fields: ['_id']
- }).then(function (response) {
- response.docs.should.deep.equal([
- {"_id": "master_hand"}
- ]);
- });
+ await db.createIndex(index);
+ const response = await db.find({
+ selector: {rank: 0},
+ fields: ['_id']
});
+ response.docs.should.deep.equal([
+ {"_id": "master_hand"}
+ ]);
});
- it('should be able to search for boolean true', function () {
- var db = context.db;
- var index = {
+ it('should be able to search for boolean true', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["awesome"]
}
};
- return db.createIndex(index).then(function () {
- return db.find({
- selector: {awesome: true},
- fields: ['_id']
- }).then(function (response) {
- response.docs.sort(sortById);
- response.docs.should.deep.equal([{"_id":"falcon"},{"_id":"fox"},{"_id":"kirby"},
- {"_id":"link"},{"_id":"mario"},{"_id":"ness"},{"_id":"pikachu"},
- {"_id":"samus"},{"_id":"yoshi"}]);
- });
+ await db.createIndex(index);
+ const response = await db.find({
+ selector: {awesome: true},
+ fields: ['_id']
});
+ response.docs.sort(sortById);
+ response.docs.should.deep.equal([{"_id":"falcon"},{"_id":"fox"},{"_id":"kirby"},
+ {"_id":"link"},{"_id":"mario"},{"_id":"ness"},{"_id":"pikachu"},
+ {"_id":"samus"},{"_id":"yoshi"}]);
});
- it('should be able to search for boolean true', function () {
- var db = context.db;
- var index = {
+ it('should be able to search for boolean true', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["awesome"]
}
};
- return db.createIndex(index).then(function () {
- return db.find({
- selector: {awesome: false},
- fields: ['_id']
- }).then(function (response) {
- response.docs.sort(sortById);
- response.docs.should.deep.equal([{"_id":"dk"},{"_id":"luigi"},
- {"_id":"master_hand"},{"_id":"puff"}]);
- });
+ await db.createIndex(index);
+ const response = await db.find({
+ selector: {awesome: false},
+ fields: ['_id']
});
+ response.docs.sort(sortById);
+ response.docs.should.deep.equal([{"_id":"dk"},{"_id":"luigi"},
+ {"_id":"master_hand"},{"_id":"puff"}]);
});
- it('#73 should be able to create a custom index name', function () {
- var db = context.db;
- var index = {
+ it('#73 should be able to create a custom index name', async () => {
+ const db = context.db;
+ const index = {
index: {
fields: ["awesome"],
name: 'myindex',
ddoc: 'mydesigndoc'
}
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (res) {
- var indexes = res.indexes.map(function (index) {
- return {
- name: index.name,
- ddoc: index.ddoc,
- type: index.type
- };
- });
- indexes.should.deep.equal([
- {
- name: '_all_docs',
- type: 'special',
- ddoc: null
- },
- {
- name: 'myindex',
- ddoc: '_design/mydesigndoc',
- type: 'json'
- }
- ]);
- return db.get('_design/mydesigndoc');
- });
+ await db.createIndex(index);
+ const res = await db.getIndexes();
+ const indexes = res.indexes.map(({ name, ddoc, type }) => ({ name, ddoc, type }));
+ indexes.should.deep.equal([
+ {
+ name: '_all_docs',
+ type: 'special',
+ ddoc: null
+ },
+ {
+ name: 'myindex',
+ ddoc: '_design/mydesigndoc',
+ type: 'json'
+ }
+ ]);
+ await db.get('_design/mydesigndoc');
});
- it('#73 should be able to create a custom index, alt style', function () {
- var db = context.db;
- var index = {
+ it('#73 should be able to create a custom index, alt style', async () => {
+ const db = context.db;
+ const index = {
index: {
fields: ["awesome"],
},
name: 'myindex',
ddoc: 'mydesigndoc'
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (res) {
- var indexes = res.indexes.map(function (index) {
- return {
- name: index.name,
- ddoc: index.ddoc,
- type: index.type
- };
- });
- indexes.should.deep.equal([
- {
- name: '_all_docs',
- type: 'special',
- ddoc: null
- },
- {
- name: 'myindex',
- ddoc: '_design/mydesigndoc',
- type: 'json'
- }
- ]);
- return db.get('_design/mydesigndoc');
- });
+ await db.createIndex(index);
+ const res = await db.getIndexes();
+ const indexes = res.indexes.map(({ name, ddoc, type }) => ({ name, ddoc, type }));
+ indexes.should.deep.equal([
+ {
+ name: '_all_docs',
+ type: 'special',
+ ddoc: null
+ },
+ {
+ name: 'myindex',
+ ddoc: '_design/mydesigndoc',
+ type: 'json'
+ }
+ ]);
+ await db.get('_design/mydesigndoc');
});
- it('#73 should be able to create a custom index, alt style 2', function () {
- var db = context.db;
- var index = {
+ it('#73 should be able to create a custom index, alt style 2', async () => {
+ const db = context.db;
+ const index = {
name: 'myindex',
ddoc: 'mydesigndoc',
fields: ["awesome"]
};
- return db.createIndex(index).then(function () {
- return db.getIndexes();
- }).then(function (res) {
- var indexes = res.indexes.map(function (index) {
- return {
- name: index.name,
- ddoc: index.ddoc,
- type: index.type
- };
- });
- indexes.should.deep.equal([
- {
- name: '_all_docs',
- type: 'special',
- ddoc: null
- },
- {
- name: 'myindex',
- ddoc: '_design/mydesigndoc',
- type: 'json'
- }
- ]);
- return db.get('_design/mydesigndoc');
- });
+ await db.createIndex(index);
+ const res = await db.getIndexes();
+ const indexes = res.indexes.map(({ name, ddoc, type }) => ({ name, ddoc, type }));
+ indexes.should.deep.equal([
+ {
+ name: '_all_docs',
+ type: 'special',
+ ddoc: null
+ },
+ {
+ name: 'myindex',
+ ddoc: '_design/mydesigndoc',
+ type: 'json'
+ }
+ ]);
+ await db.get('_design/mydesigndoc');
});
- it('#6277 selector as an empty object', function () {
- var db = context.db;
- return db.createIndex({
+ it('#6277 selector as an empty object', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['rank', 'awesome']
},
- }).then(function () {
- return db.find({
- selector: { rank: 8, awesome: null }
- });
- }).then(function () {
- return db.find({
- selector: { rank: 8, awesome: {} }
- });
+ });
+ await db.find({
+ selector: { rank: 8, awesome: null }
+ });
+ await db.find({
+ selector: { rank: 8, awesome: {} }
});
});
});
diff --git a/tests/find/test-suite-1/test.callbacks.js b/tests/find/test-suite-1/test.callbacks.js
index d86a3287e..f5bc32b02 100644
--- a/tests/find/test-suite-1/test.callbacks.js
+++ b/tests/find/test-suite-1/test.callbacks.js
@@ -1,102 +1,97 @@
'use strict';
-describe('test.callbacks.js', function () {
- it('should create an index', function () {
- var db = context.db;
- var index = {
+describe('test.callbacks.js', () => {
+ it('should create an index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return new Promise(function (resolve, reject) {
- return db.createIndex(index, function (err, res) {
+ const createResp = await new Promise((resolve, reject) => {
+ db.createIndex(index, (err, res) => {
if (err) {
return reject(err);
}
- return resolve(res);
+ resolve(res);
});
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return new Promise(function (resolve, reject) {
- db.createIndex(index, function (err, res) {
- if (err) {
- return reject(err);
- }
- return resolve(res);
- });
+ });
+ createResp.id.should.match(/^_design\//);
+ createResp.name.should.equal('foo-index');
+ createResp.result.should.equal('created');
+ const existsResp = await new Promise((resolve, reject) => {
+ db.createIndex(index, (err, res) => {
+ if (err) {
+ return reject(err);
+ }
+ resolve(res);
});
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('exists');
});
+ existsResp.id.should.match(/^_design\//);
+ existsResp.name.should.equal('foo-index');
+ existsResp.result.should.equal('exists');
});
- it.skip('should find existing indexes', function () {
- var db = context.db;
- return new Promise(function (resolve, reject) {
- db.getIndexes(function (err, response) {
+ it.skip('should find existing indexes', async () => {
+ const db = context.db;
+ const initialResp = await new Promise((resolve, reject) => {
+ db.getIndexes((err, response) => {
if (err) {
return reject(err);
}
resolve(response);
});
- }).then(function (response) {
- response.should.deep.equal({
- "total_rows": 1,
- indexes: [{
- ddoc: null,
- name: '_all_docs',
- type: 'special',
- def: {fields: [{_id: 'asc'}]}
- }]
- });
- var index = {
- "index": {
- "fields": ["foo"]
+ });
+ initialResp.should.deep.equal({
+ "total_rows": 1,
+ indexes: [{
+ ddoc: null,
+ name: '_all_docs',
+ type: 'special',
+ def: {fields: [{_id: 'asc'}]}
+ }]
+ });
+ const index = {
+ "index": {
+ "fields": ["foo"]
+ },
+ "name": "foo-index",
+ "type": "json"
+ };
+ await db.createIndex(index);
+ const resp = await db.getIndexes();
+ const ddoc = resp.indexes[1].ddoc;
+ ddoc.should.match(/_design\/.+/);
+ delete resp.indexes[1].ddoc;
+ resp.should.deep.equal({
+ "total_rows": 2,
+ "indexes": [
+ {
+ "ddoc": null,
+ "name": "_all_docs",
+ "type": "special",
+ "def": {
+ "fields": [
+ {
+ "_id": "asc"
+ }
+ ]
+ }
},
- "name": "foo-index",
- "type": "json"
- };
- return db.createIndex(index);
- }).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- var ddoc = resp.indexes[1].ddoc;
- ddoc.should.match(/_design\/.+/);
- delete resp.indexes[1].ddoc;
- resp.should.deep.equal({
- "total_rows": 2,
- "indexes": [
- {
- "ddoc": null,
- "name": "_all_docs",
- "type": "special",
- "def": {
- "fields": [
- {
- "_id": "asc"
- }
- ]
- }
- },
- {
- "name": "foo-index",
- "type": "json",
- "def": {
- "fields": [
- {
- "foo": "asc"
- }
- ]
- }
+ {
+ "name": "foo-index",
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "foo": "asc"
+ }
+ ]
}
- ]
- });
+ }
+ ]
});
});
});
diff --git a/tests/find/test-suite-1/test.combinational.js b/tests/find/test-suite-1/test.combinational.js
index e618020b0..3e90fc4aa 100644
--- a/tests/find/test-suite-1/test.combinational.js
+++ b/tests/find/test-suite-1/test.combinational.js
@@ -1,11 +1,11 @@
'use strict';
-describe('test.combinational.js', function () {
- describe('$or', function () {
+describe('test.combinational.js', () => {
+ describe('$or', () => {
- it('does $or queries', function () {
- var db = context.db;
- var index = {
+ it('does $or queries', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["age"]
},
@@ -13,41 +13,38 @@ describe('test.combinational.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
+ { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
+ { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
+ ]);
+ const resp = await db.find({
+ selector: {
+ $and:[
+ {age:{$gte: 75}},
+ {$or: [
+ {"name.first": "Nancy"},
+ {"name.first": "Mick"}
+ ]}
+ ]
+ }
+ });
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
{ _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
- { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
- { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
- { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
+ { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}
]);
- }).then(function () {
- return db.find({
- selector: {
- $and:[
- {age:{$gte: 75}},
- {$or: [
- {"name.first": "Nancy"},
- {"name.first": "Mick"}
- ]}
- ]
- }
- });
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
- { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}}
- ]);
- });
});
- it('does $or queries 2', function () {
- var db = context.db;
- var index = {
+ it('does $or queries 2', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["_id"]
},
@@ -55,47 +52,44 @@ describe('test.combinational.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
+ { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
+ { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
+ { _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
+ ]);
+ const resp = await db.find({
+ selector: {
+ $and:[
+ {_id:{$gte: '0'}},
+ {$or: [
+ {"name.first": "Nancy"},
+ {age : {$lte: 40}}
+ ]}
+ ]
+ }
+ });
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
{ _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
{ _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
- { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
- { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
{ _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
]);
- }).then(function () {
- return db.find({
- selector: {
- $and:[
- {_id:{$gte: '0'}},
- {$or: [
- {"name.first": "Nancy"},
- {age : {$lte: 40}}
- ]}
- ]
- }
- });
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
- { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
- { _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
- ]);
- });
});
});
- describe('$nor', function () {
+ describe('$nor', () => {
- it('does $nor queries', function () {
- var db = context.db;
- var index = {
+ it('does $nor queries', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["age"]
},
@@ -103,40 +97,37 @@ describe('test.combinational.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
- { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
+ { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
+ { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
+ ]);
+ const resp = await db.find({
+ selector: {
+ $and:[
+ {age:{$gte: 75}},
+ {$nor: [
+ {"name.first": "Nancy"},
+ {"name.first": "Mick"}
+ ]}
+ ]
+ }
+ });
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
{ _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
- { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
]);
- }).then(function () {
- return db.find({
- selector: {
- $and:[
- {age:{$gte: 75}},
- {$nor: [
- {"name.first": "Nancy"},
- {"name.first": "Mick"}
- ]}
- ]
- }
- });
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
- ]);
- });
});
- it('does $nor queries 2', function () {
- var db = context.db;
- var index = {
+ it('does $nor queries 2', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["_id"]
},
@@ -144,42 +135,39 @@ describe('test.combinational.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
- { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
+ { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
+ { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
+ { _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
+ ]);
+ const resp = await db.find({
+ selector: {
+ $and:[
+ {_id:{$lte: '6'}},
+ {$nor: [
+ {"name.first": "Nancy"},
+ {age : {$lte: 40}}
+ ]}
+ ]
+ }
+ });
+ const docs = resp.docs.map((doc) => {
+ delete doc._rev;
+ return doc;
+ });
+
+ docs.should.deep.equal([
{ _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
{ _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
- { _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
]);
- }).then(function () {
- return db.find({
- selector: {
- $and:[
- {_id:{$lte: '6'}},
- {$nor: [
- {"name.first": "Nancy"},
- {age : {$lte: 40}}
- ]}
- ]
- }
- });
- }).then(function (resp) {
- var docs = resp.docs.map(function (doc) {
- delete doc._rev;
- return doc;
- });
-
- docs.should.deep.equal([
- { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
- { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
- ]);
- });
});
- it('handles $or/$nor typos', function () {
- var db = context.db;
- var index = {
+ it('handles $or/$nor typos', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["_id"]
},
@@ -187,16 +175,16 @@ describe('test.combinational.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
- { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
- { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
- { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
- { _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
- ]);
- }).then(function () {
- return db.find({
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
+ { _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
+ { _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
+ { _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
+ { _id: '5', age: 40, name: {first: 'Dave', surname: 'Grohl'}}
+ ]);
+ try {
+ await db.find({
selector: {
$and:[
{_id:{$lte: '6'}},
@@ -207,11 +195,10 @@ describe('test.combinational.js', function () {
]
}
});
- }).then(function () {
throw new Error('expected an error');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
});
diff --git a/tests/find/test-suite-1/test.data-type-order.js b/tests/find/test-suite-1/test.data-type-order.js
index 0176ee4d5..6e2608235 100644
--- a/tests/find/test-suite-1/test.data-type-order.js
+++ b/tests/find/test-suite-1/test.data-type-order.js
@@ -1,58 +1,53 @@
'use strict';
-describe('test.data-type-order.js', function () {
- it('Orders different data types correctly', function () {
- var db = context.db;
- return db.createIndex({
+describe('test.data-type-order.js', () => {
+ it('Orders different data types correctly', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- // intentional random bulk order
- {_id: '8', foo: 'foo'},
- {_id: '5', foo: 0},
- {_id: '3', foo: true},
- {_id: '2', foo: false},
- {_id: '6', foo: 42},
- {_id: '9', foo: [0]},
- {_id: '10', foo: ['foo']},
- {_id: '7', foo: ''},
- {_id: '4', foo: -42},
- {_id: '1', foo: null},
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$lt: 0}
- },
- sort: [{foo: 'desc'}],
- fields: ['_id'],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: '4'},
- {_id: '3'},
- {_id: '2'},
- {_id: '1'},
- ]);
- }).then(function () {
- return db.find({
- selector: {
- foo: {$gt: 0}
- },
- fields: ['_id'],
- });
- }).then(function (resp) {
- console.log(JSON.stringify(resp.docs, null, 2));
- resp.docs.should.deep.equal([
- {_id: '6'},
- {_id: '7'},
- {_id: '8'},
- {_id: '9'},
- {_id: '10'},
- ]);
- });
});
+ await db.bulkDocs([
+ // intentional random bulk order
+ {_id: '8', foo: 'foo'},
+ {_id: '5', foo: 0},
+ {_id: '3', foo: true},
+ {_id: '2', foo: false},
+ {_id: '6', foo: 42},
+ {_id: '9', foo: [0]},
+ {_id: '10', foo: ['foo']},
+ {_id: '7', foo: ''},
+ {_id: '4', foo: -42},
+ {_id: '1', foo: null},
+ ]);
+ const resp1 = await db.find({
+ selector: {
+ foo: {$lt: 0}
+ },
+ sort: [{foo: 'desc'}],
+ fields: ['_id'],
+ });
+ resp1.docs.should.deep.equal([
+ {_id: '4'},
+ {_id: '3'},
+ {_id: '2'},
+ {_id: '1'},
+ ]);
+ const resp2 = await db.find({
+ selector: {
+ foo: {$gt: 0}
+ },
+ fields: ['_id'],
+ });
+ console.log(JSON.stringify(resp2.docs, null, 2));
+ resp2.docs.should.deep.equal([
+ {_id: '6'},
+ {_id: '7'},
+ {_id: '8'},
+ {_id: '9'},
+ {_id: '10'},
+ ]);
});
// IndexedDB does not index obejcts, so this test fails in idbnext. It is probably
@@ -61,62 +56,57 @@ describe('test.data-type-order.js', function () {
// a) they aren't constants, they could have anything in them
// b) because someone else might want them to actually index on the inner parts
// of the object (in this case, foo.foo)
- it.skip('Orders different data types correctly, including objects', function () {
- var db = context.db;
- return db.createIndex({
+ it.skip('Orders different data types correctly, including objects', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- // intentional random bulk order
- {_id: '8', foo: 'foo'},
- {_id: '5', foo: 0},
- {_id: '11', foo: {foo: 0}},
- {_id: '3', foo: true},
- {_id: '2', foo: false},
- {_id: '6', foo: 42},
- {_id: '12', foo: {foo: 'foo'}},
- {_id: '9', foo: [0]},
- {_id: '10', foo: ['foo']},
- {_id: '7', foo: ''},
- {_id: '4', foo: -42},
- {_id: '1', foo: null},
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$lt: 0}
- },
- sort: [{foo: 'desc'}],
- fields: ['_id'],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: '4'},
- {_id: '3'},
- {_id: '2'},
- {_id: '1'},
- ]);
- }).then(function () {
- return db.find({
- selector: {
- foo: {$gt: 0}
- },
- fields: ['_id'],
- });
- }).then(function (resp) {
- console.log(JSON.stringify(resp.docs, null, 2));
- resp.docs.should.deep.equal([
- {_id: '6'},
- {_id: '7'},
- {_id: '8'},
- {_id: '9'},
- {_id: '10'},
- {_id: '11'},
- {_id: '12'},
- ]);
- });
});
+ await db.bulkDocs([
+ // intentional random bulk order
+ {_id: '8', foo: 'foo'},
+ {_id: '5', foo: 0},
+ {_id: '11', foo: {foo: 0}},
+ {_id: '3', foo: true},
+ {_id: '2', foo: false},
+ {_id: '6', foo: 42},
+ {_id: '12', foo: {foo: 'foo'}},
+ {_id: '9', foo: [0]},
+ {_id: '10', foo: ['foo']},
+ {_id: '7', foo: ''},
+ {_id: '4', foo: -42},
+ {_id: '1', foo: null},
+ ]);
+ const resp1 = await db.find({
+ selector: {
+ foo: {$lt: 0}
+ },
+ sort: [{foo: 'desc'}],
+ fields: ['_id'],
+ });
+ resp1.docs.should.deep.equal([
+ {_id: '4'},
+ {_id: '3'},
+ {_id: '2'},
+ {_id: '1'},
+ ]);
+ const resp2 = await db.find({
+ selector: {
+ foo: {$gt: 0}
+ },
+ fields: ['_id'],
+ });
+ console.log(JSON.stringify(resp2.docs, null, 2));
+ resp2.docs.should.deep.equal([
+ {_id: '6'},
+ {_id: '7'},
+ {_id: '8'},
+ {_id: '9'},
+ {_id: '10'},
+ {_id: '11'},
+ {_id: '12'},
+ ]);
});
// In IndexedDB we rewrite true, false and null as Number.MIN_SAFE_INTEGER
@@ -126,42 +116,39 @@ describe('test.data-type-order.js', function () {
//
// IMO this is low priority to fix, since it isn't likely to occur and requires
// either a heavy weight sort in many cases, or careful custom sorting
- it.skip('Orders min numbers correctly', function () {
- var db = context.db;
- return db.createIndex({
+ it.skip('Orders min numbers correctly', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- // intentional random order
- {_id: '4', foo: Number.MIN_SAFE_INTEGER},
- {_id: '7', foo: null},
- {_id: '2', foo: Number.MIN_SAFE_INTEGER + 2},
- {_id: '5', foo: true},
- {_id: '6', foo: false},
- {_id: '1', foo: -42},
- {_id: '3', foo: Number.MIN_SAFE_INTEGER + 1},
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$lt: 0}
- },
- sort: [{foo: 'desc'}],
- fields: ['_id'],
- });
- }).then(function (resp) {
- console.log(JSON.stringify(resp.docs, null, 2));
- resp.docs.should.deep.equal([
- {_id: '1'},
- {_id: '2'},
- {_id: '3'},
- {_id: '4'},
- {_id: '5'},
- {_id: '6'},
- {_id: '7'},
- ]);
- });
});
+ await db.bulkDocs([
+ // intentional random order
+ {_id: '4', foo: Number.MIN_SAFE_INTEGER},
+ {_id: '7', foo: null},
+ {_id: '2', foo: Number.MIN_SAFE_INTEGER + 2},
+ {_id: '5', foo: true},
+ {_id: '6', foo: false},
+ {_id: '1', foo: -42},
+ {_id: '3', foo: Number.MIN_SAFE_INTEGER + 1},
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$lt: 0}
+ },
+ sort: [{foo: 'desc'}],
+ fields: ['_id'],
+ });
+ console.log(JSON.stringify(resp.docs, null, 2));
+ resp.docs.should.deep.equal([
+ {_id: '1'},
+ {_id: '2'},
+ {_id: '3'},
+ {_id: '4'},
+ {_id: '5'},
+ {_id: '6'},
+ {_id: '7'},
+ ]);
});
});
diff --git a/tests/find/test-suite-1/test.ddoc.js b/tests/find/test-suite-1/test.ddoc.js
index 86675a10c..039f287e5 100644
--- a/tests/find/test-suite-1/test.ddoc.js
+++ b/tests/find/test-suite-1/test.ddoc.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.ddoc.js', function () {
- it.skip('should create an index', function () {
- var db = context.db;
- var index = {
+describe('test.ddoc.js', () => {
+ it.skip('should create an index', async () => {
+ const db = context.db;
+ const index = {
index: {
fields: ["foo"]
},
@@ -11,52 +11,49 @@ describe('test.ddoc.js', function () {
type: "json",
ddoc: 'foo'
};
- return db.createIndex(index).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return db.createIndex(index);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('exists');
- return db.getIndexes();
- }).then(function (resp) {
- resp.should.deep.equal({
- "total_rows": 2,
- "indexes": [
- {
- "ddoc": null,
- "name": "_all_docs",
- "type": "special",
- "def": {
- "fields": [
- {
- "_id": "asc"
- }
- ]
- }
- },
- {
- "ddoc": "_design/foo",
- "name": "foo-index",
- "type": "json",
- "def": {
- "fields": [
- {
- "foo": "asc"
- }
- ]
- }
+ const createResp = await db.createIndex(index);
+ createResp.id.should.match(/^_design\//);
+ createResp.name.should.equal('foo-index');
+ createResp.result.should.equal('created');
+ const existsResp = await db.createIndex(index);
+ existsResp.id.should.match(/^_design\//);
+ existsResp.name.should.equal('foo-index');
+ existsResp.result.should.equal('exists');
+ const resp = await db.getIndexes();
+ resp.should.deep.equal({
+ "total_rows": 2,
+ "indexes": [
+ {
+ "ddoc": null,
+ "name": "_all_docs",
+ "type": "special",
+ "def": {
+ "fields": [
+ {
+ "_id": "asc"
+ }
+ ]
}
- ]
- });
+ },
+ {
+ "ddoc": "_design/foo",
+ "name": "foo-index",
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "foo": "asc"
+ }
+ ]
+ }
+ }
+ ]
});
});
- it.skip('should create an index, existing ddoc', function () {
- var db = context.db;
- var index = {
+ it.skip('should create an index, existing ddoc', async () => {
+ const db = context.db;
+ const index = {
index: {
fields: ["foo"]
},
@@ -64,57 +61,53 @@ describe('test.ddoc.js', function () {
type: "json",
ddoc: 'foo'
};
- return db.put({
+ await db.put({
_id: '_design/foo',
"language": "query"
- }).then(function () {
- return db.createIndex(index);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return db.createIndex(index);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('exists');
- return db.getIndexes();
- }).then(function (resp) {
- resp.should.deep.equal({
- "total_rows": 2,
- "indexes": [
- {
- "ddoc": null,
- "name": "_all_docs",
- "type": "special",
- "def": {
- "fields": [
- {
- "_id": "asc"
- }
- ]
- }
- },
- {
- "ddoc": "_design/foo",
- "name": "foo-index",
- "type": "json",
- "def": {
- "fields": [
- {
- "foo": "asc"
- }
- ]
- }
+ });
+ const createResp = await db.createIndex(index);
+ createResp.id.should.match(/^_design\//);
+ createResp.name.should.equal('foo-index');
+ createResp.result.should.equal('created');
+ const existsResp = await db.createIndex(index);
+ existsResp.id.should.match(/^_design\//);
+ existsResp.name.should.equal('foo-index');
+ existsResp.result.should.equal('exists');
+ const resp = await db.getIndexes();
+ resp.should.deep.equal({
+ "total_rows": 2,
+ "indexes": [
+ {
+ "ddoc": null,
+ "name": "_all_docs",
+ "type": "special",
+ "def": {
+ "fields": [
+ {
+ "_id": "asc"
+ }
+ ]
+ }
+ },
+ {
+ "ddoc": "_design/foo",
+ "name": "foo-index",
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "foo": "asc"
+ }
+ ]
}
- ]
- });
+ }
+ ]
});
});
- it.skip('should create an index, reused ddoc', function () {
- var db = context.db;
- var index = {
+ it.skip('should create an index, reused ddoc', async () => {
+ const db = context.db;
+ const index = {
index: {
fields: ["foo"]
},
@@ -122,82 +115,76 @@ describe('test.ddoc.js', function () {
type: "json",
ddoc: 'myddoc'
};
- var index2 = {
+ const index2 = {
index: {
fields: ['bar']
},
name: "bar-index",
ddoc: 'myddoc'
};
- return db.createIndex(index).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('created');
- return db.createIndex(index);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('foo-index');
- response.result.should.equal('exists');
- return db.createIndex(index2);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('bar-index');
- response.result.should.equal('created');
- return db.createIndex(index2);
- }).then(function (response) {
- response.id.should.match(/^_design\//);
- response.name.should.equal('bar-index');
- response.result.should.equal('exists');
- }).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- resp.should.deep.equal({
- "total_rows":3,
- "indexes": [
- {
- "ddoc": null,
- "name": "_all_docs",
- "type": "special",
- "def": {
- "fields": [
- {
- "_id": "asc"
- }
- ]
- }
- },
- {
- "ddoc": "_design/myddoc",
- "name": "bar-index",
- "type": "json",
- "def": {
- "fields": [
- {
- "bar": "asc"
- }
- ]
- }
- },
- {
- "ddoc": "_design/myddoc",
- "name": "foo-index",
- "type": "json",
- "def": {
- "fields": [
- {
- "foo": "asc"
- }
- ]
- }
+ const fooCreateResp = await db.createIndex(index);
+ fooCreateResp.id.should.match(/^_design\//);
+ fooCreateResp.name.should.equal('foo-index');
+ fooCreateResp.result.should.equal('created');
+ const fooExistsResp = await db.createIndex(index);
+ fooExistsResp.id.should.match(/^_design\//);
+ fooExistsResp.name.should.equal('foo-index');
+ fooExistsResp.result.should.equal('exists');
+ const barCreateResp = await db.createIndex(index2);
+ barCreateResp.id.should.match(/^_design\//);
+ barCreateResp.name.should.equal('bar-index');
+ barCreateResp.result.should.equal('created');
+ const barExistsResp = await db.createIndex(index2);
+ barExistsResp.id.should.match(/^_design\//);
+ barExistsResp.name.should.equal('bar-index');
+ barExistsResp.result.should.equal('exists');
+ const resp = await db.getIndexes();
+ resp.should.deep.equal({
+ "total_rows":3,
+ "indexes": [
+ {
+ "ddoc": null,
+ "name": "_all_docs",
+ "type": "special",
+ "def": {
+ "fields": [
+ {
+ "_id": "asc"
+ }
+ ]
+ }
+ },
+ {
+ "ddoc": "_design/myddoc",
+ "name": "bar-index",
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "bar": "asc"
+ }
+ ]
+ }
+ },
+ {
+ "ddoc": "_design/myddoc",
+ "name": "foo-index",
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "foo": "asc"
+ }
+ ]
}
- ]
- });
+ }
+ ]
});
});
- it('Error: invalid ddoc lang', function () {
- var db = context.db;
- var index = {
+ it('Error: invalid ddoc lang', async () => {
+ const db = context.db;
+ const index = {
index: {
fields: ["foo"]
},
@@ -205,34 +192,29 @@ describe('test.ddoc.js', function () {
type: "json",
ddoc: 'foo'
};
- return db.put({
+ await db.put({
_id: '_design/foo'
- }).then(function () {
- return db.createIndex(index);
- }).then(function () {
+ });
+ try {
+ await db.createIndex(index);
throw new Error('shouldnt be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('handles ddoc with no views and ignores it', function () {
- var db = context.db;
+ it('handles ddoc with no views and ignores it', async () => {
+ const db = context.db;
- return db.put({
+ await db.put({
_id: '_design/missing-view',
language: 'query'
- })
- .then(function () {
- return db.getIndexes();
- })
- .then(function (resp) {
- resp.indexes.length.should.equal(1);
});
-
+ const resp = await db.getIndexes();
+ resp.indexes.length.should.equal(1);
});
- it('supports creating many indexes at the same time', function () {
+ it('supports creating many indexes at the same time', async function () {
// This will time out in IDBNext. This happens because an index creation
// also queries the view to "warm" it. This triggers our code to decide
// that the idb handle needs to be dropped and re-created. This is fine if
@@ -245,7 +227,7 @@ describe('test.ddoc.js', function () {
// same problem) are queued and don't run in parallel.
this.timeout(5000);
- return Promise.all([
+ await Promise.all([
context.db.createIndex({index: {fields: ['rank']}}),
context.db.createIndex({index: {fields: ['series']}}),
context.db.createIndex({index: {fields: ['debut']}}),
@@ -254,20 +236,19 @@ describe('test.ddoc.js', function () {
context.db.createIndex({index: {fields: ['name', 'series']}}),
context.db.createIndex({index: {fields: ['series', 'debut', 'rank']}}),
context.db.createIndex({index: {fields: ['rank', 'debut']}})
- ]).then(function () {
- // At time of writing the createIndex implentation also performs a
- // search to "warm" the indexes. If this changes to happen async, or not
- // at all, these queries will force the collision to be tested.
- return Promise.all([
- context.db.find({selector: {rank: 'foo'}}),
- context.db.find({selector: {series: 'foo'}}),
- context.db.find({selector: {debut: 'foo'}}),
- context.db.find({selector: {name: 'foo'}}),
- context.db.find({selector: {name: 'foo', rank: 'foo'}}),
- context.db.find({selector: {name: 'foo', series: 'foo'}}),
- context.db.find({selector: {series: 'foo', debut: 'foo', rank: 'foo'}}),
- context.db.find({selector: {rank: 'foo', debut: 'foo'}}),
- ]);
- });
+ ]);
+ // At time of writing the createIndex implentation also performs a
+ // search to "warm" the indexes. If this changes to happen async, or not
+ // at all, these queries will force the collision to be tested.
+ await Promise.all([
+ context.db.find({selector: {rank: 'foo'}}),
+ context.db.find({selector: {series: 'foo'}}),
+ context.db.find({selector: {debut: 'foo'}}),
+ context.db.find({selector: {name: 'foo'}}),
+ context.db.find({selector: {name: 'foo', rank: 'foo'}}),
+ context.db.find({selector: {name: 'foo', series: 'foo'}}),
+ context.db.find({selector: {series: 'foo', debut: 'foo', rank: 'foo'}}),
+ context.db.find({selector: {rank: 'foo', debut: 'foo'}}),
+ ]);
});
});
diff --git a/tests/find/test-suite-1/test.deep-fields.js b/tests/find/test-suite-1/test.deep-fields.js
index 62fef21b7..45eb43fd6 100644
--- a/tests/find/test-suite-1/test.deep-fields.js
+++ b/tests/find/test-suite-1/test.deep-fields.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.deep-fields.js', function () {
- it('deep fields', function () {
- var db = context.db;
- var index = {
+describe('test.deep-fields.js', () => {
+ it('deep fields', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo.bar"
@@ -12,23 +12,20 @@ describe('test.deep-fields.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: 'doc', foo: {bar: 'a'}},
- ]);
- }).then(function () {
- return db.find({
- selector: {'foo.bar': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{"_id": "doc"}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: 'doc', foo: {bar: 'a'}},
+ ]);
+ const res = await db.find({
+ selector: {'foo.bar': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{"_id": "doc"}]);
});
- it('deeper fields', function () {
- var db = context.db;
- var index = {
+ it('deeper fields', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo.bar.baz"
@@ -37,91 +34,78 @@ describe('test.deep-fields.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: 'doc', foo: {bar: {baz: 'a'}}},
- ]);
- }).then(function () {
- return db.find({
- selector: {'foo.bar.baz': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{"_id": "doc"}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: 'doc', foo: {bar: {baz: 'a'}}},
+ ]);
+ const res = await db.find({
+ selector: {'foo.bar.baz': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{"_id": "doc"}]);
});
- it('should create a deep multi mapper', function () {
- var db = context.db;
- var index = {
+ it('should create a deep multi mapper', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo.bar", "bar.baz"
]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: 'a', foo: {bar: 'yo'}, bar: {baz: 'hey'}},
- {_id: 'b', foo: {bar: 'sup'}, bar: {baz: 'dawg'}}
- ]);
- }).then(function () {
- return db.find({
- selector: {"foo.bar": 'yo', "bar.baz": 'hey'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{_id: 'a'}]);
- return db.find({
- selector: {"foo.bar": 'yo', "bar.baz": 'sup'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.have.length(0);
- return db.find({
- selector: {"foo.bar": 'bruh', "bar.baz": 'nah'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.have.length(0);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: 'a', foo: {bar: 'yo'}, bar: {baz: 'hey'}},
+ {_id: 'b', foo: {bar: 'sup'}, bar: {baz: 'dawg'}}
+ ]);
+ const res1 = await db.find({
+ selector: {"foo.bar": 'yo', "bar.baz": 'hey'},
+ fields: ['_id']
});
+ res1.docs.should.deep.equal([{_id: 'a'}]);
+ const res2 = await db.find({
+ selector: {"foo.bar": 'yo', "bar.baz": 'sup'},
+ fields: ['_id']
+ });
+ res2.docs.should.have.length(0);
+ const res3 = await db.find({
+ selector: {"foo.bar": 'bruh', "bar.baz": 'nah'},
+ fields: ['_id']
+ });
+ res3.docs.should.have.length(0);
});
- it('should create a deep multi mapper, tricky docs', function () {
- var db = context.db;
- var index = {
+ it('should create a deep multi mapper, tricky docs', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo.bar", "bar.baz"
]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: 'a', foo: {bar: 'yo'}, bar: {baz: 'hey'}},
- {_id: 'b', foo: {bar: 'sup'}, bar: {baz: 'dawg'}},
- {_id: 'c', foo: true, bar: "yo"},
- {_id: 'd', foo: null, bar: []}
- ]);
- }).then(function () {
- return db.find({
- selector: {"foo.bar": 'yo', "bar.baz": 'hey'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{_id: 'a'}]);
- return db.find({
- selector: {"foo.bar": 'yo', "bar.baz": 'sup'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.have.length(0);
- return db.find({
- selector: {"foo.bar": 'bruh', "bar.baz": 'nah'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.have.length(0);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: 'a', foo: {bar: 'yo'}, bar: {baz: 'hey'}},
+ {_id: 'b', foo: {bar: 'sup'}, bar: {baz: 'dawg'}},
+ {_id: 'c', foo: true, bar: "yo"},
+ {_id: 'd', foo: null, bar: []}
+ ]);
+ const res1 = await db.find({
+ selector: {"foo.bar": 'yo', "bar.baz": 'hey'},
+ fields: ['_id']
+ });
+ res1.docs.should.deep.equal([{_id: 'a'}]);
+ const res2 = await db.find({
+ selector: {"foo.bar": 'yo', "bar.baz": 'sup'},
+ fields: ['_id']
+ });
+ res2.docs.should.have.length(0);
+ const res3 = await db.find({
+ selector: {"foo.bar": 'bruh', "bar.baz": 'nah'},
+ fields: ['_id']
});
+ res3.docs.should.have.length(0);
});
});
diff --git a/tests/find/test-suite-1/test.default-index.js b/tests/find/test-suite-1/test.default-index.js
index 61700da0d..1c11ec35e 100644
--- a/tests/find/test-suite-1/test.default-index.js
+++ b/tests/find/test-suite-1/test.default-index.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.default-index.js', function () {
- it('uses all_docs with warning if no index found simple query 1', function () {
- var db = context.db;
- return db.bulkDocs([
+describe('test.default-index.js', () => {
+ it('uses all_docs with warning if no index found simple query 1', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
{ name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
{ name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
@@ -16,27 +16,25 @@ describe('test.default-index.js', function () {
{ name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
{ name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
{ name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ]).then(function () {
- return db.find({
- selector: {
- series: 'mario'
- },
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: 'dk'},
- {_id: 'luigi'},
- {_id: 'mario'},
- {_id: 'yoshi'}
- ]);
+ ]);
+ const resp = await db.find({
+ selector: {
+ series: 'mario'
+ },
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([
+ {_id: 'dk'},
+ {_id: 'luigi'},
+ {_id: 'mario'},
+ {_id: 'yoshi'}
+ ]);
});
- it('uses all_docs with warning if no index found simple query 2', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('uses all_docs with warning if no index found simple query 2', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
{ name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
{ name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
@@ -49,135 +47,127 @@ describe('test.default-index.js', function () {
{ name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
{ name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
{ name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ]).then(function () {
- return db.find({
- selector: {
- debut: {
- $gt: 1992,
- $lte: 1996
- },
- rank: {
- $gte: 3,
- $lte: 8
- }
+ ]);
+ const resp = await db.find({
+ selector: {
+ debut: {
+ $gt: 1992,
+ $lte: 1996
},
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: 'fox'}, {_id: 'puff'}]);
+ rank: {
+ $gte: 3,
+ $lte: 8
+ }
+ },
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([{_id: 'fox'}, {_id: 'puff'}]);
});
- it('works with complex query', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('works with complex query', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ _id: '1', age: 75, name: {first: 'Nancy', surname: 'Sinatra'}},
{ _id: '2', age: 40, name: {first: 'Eddie', surname: 'Vedder'}},
{ _id: '3', age: 80, name: {first: 'John', surname: 'Fogerty'}},
{ _id: '4', age: 76, name: {first: 'Mick', surname: 'Jagger'}},
- ]).then(function () {
- return db.find({
- selector: {
- $and: [
- {age:{$gte: 40}},
- {$not:{age: {$eq: 75}}},
- ]
- },
- fields: ["_id"],
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- { _id: '2'},
- { _id: '3'},
- { _id: '4'}
- ]);
+ ]);
+ const resp = await db.find({
+ selector: {
+ $and: [
+ {age:{$gte: 40}},
+ {$not:{age: {$eq: 75}}},
+ ]
+ },
+ fields: ["_id"],
});
+ resp.docs.should.deep.equal([
+ { _id: '2'},
+ { _id: '3'},
+ { _id: '4'}
+ ]);
});
- it('throws an error if a sort is required', function () {
- var db = context.db;
+ it('throws an error if a sort is required', async () => {
+ const db = context.db;
- return db.bulkDocs([
+ await db.bulkDocs([
{ _id: '1', foo: 'eyo'},
{ _id: '2', foo: 'ebb'},
{ _id: '3', foo: 'eba'},
{ _id: '4', foo: 'abo'}
- ]).then(function () {
- return db.find({
+ ]);
+ try {
+ await db.find({
selector: {foo: {$ne: "eba"}},
fields: ["_id", "foo"],
sort: [{"foo": "asc"}]
});
- }).then(function () {
throw new Error('should have thrown an error');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it.skip('sorts ok if _id used', function () {
- var db = context.db;
+ it.skip('sorts ok if _id used', async () => {
+ const db = context.db;
- return db.bulkDocs([
+ await db.bulkDocs([
{ _id: '1', foo: 'eyo'},
{ _id: '2', foo: 'ebb'},
{ _id: '3', foo: 'eba'},
{ _id: '4', foo: 'abo'}
- ]).then(function () {
- return db.find({
- selector: {foo: {$ne: "eba"}},
- fields: ["_id"],
- sort: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- { _id: '1'},
- { _id: '2'},
- { _id: '4'}
- ]);
+ ]);
+ const resp = await db.find({
+ selector: {foo: {$ne: "eba"}},
+ fields: ["_id"],
+ sort: ["_id"]
});
+ resp.docs.should.deep.equal([
+ { _id: '1'},
+ { _id: '2'},
+ { _id: '4'}
+ ]);
});
});
-it('$in works with default operator', function () {
- var db = context.db;
+it('$in works with default operator', async () => {
+ const db = context.db;
- return db.bulkDocs([
+ await db.bulkDocs([
{ _id: '1', foo: 'eyo'},
{ _id: '2', foo: 'ebb'},
{ _id: '3', foo: 'eba'},
{ _id: '4', foo: 'abo'}
- ]).then(function () {
- return db.find({
- selector: {foo: {$in: ["eba", "ebb"]}},
- fields: ["_id"],
- });
- }).then(function (resp) {
- // console.log(resp);
- // resp.should.deep.equal({
- // warning: 'No matching index found, create an index to optimize query time.',
- // docs: [
- // { _id: '2'},
- // { _id: '3'}
- // ]
- // });
- resp.warning.should.be.oneOf(
- [
- 'no matching index found, create an index to optimize query time',
- 'No matching index found, create an index to optimize query time.'
- ]
- );
- resp.docs.should.deep.equal([
- { _id: '2'},
- { _id: '3'}
- ]);
+ ]);
+ const resp = await db.find({
+ selector: {foo: {$in: ["eba", "ebb"]}},
+ fields: ["_id"],
});
+ // console.log(resp);
+ // resp.should.deep.equal({
+ // warning: 'No matching index found, create an index to optimize query time.',
+ // docs: [
+ // { _id: '2'},
+ // { _id: '3'}
+ // ]
+ // });
+ resp.warning.should.be.oneOf(
+ [
+ 'no matching index found, create an index to optimize query time',
+ 'No matching index found, create an index to optimize query time.'
+ ]
+ );
+ resp.docs.should.deep.equal([
+ { _id: '2'},
+ { _id: '3'}
+ ]);
});
//bug in mango its not sorting this on Foo but actually sorting on _id
-it.skip('ne query will work and sort', function () {
- var db = context.db;
- var index = {
+it.skip('ne query will work and sort', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -185,304 +175,274 @@ it.skip('ne query will work and sort', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 4},
- { _id: '2', foo: 3},
- { _id: '3', foo: 2},
- { _id: '4', foo: 1}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: {$ne: "eba"}},
- fields: ["_id", "foo"],
- sort: [{foo: "desc"}]
- });
- }).then(function (resp) {
- resp.warning.should.be.oneOf(
- [
- 'no matching index found, create an index to optimize query time',
- 'No matching index found, create an index to optimize query time.'
- ]
- );
- resp.docs.should.deep.equal(
- [
- { _id: '4' },
- { _id: '2' },
- { _id: '1' }
- ]
- );
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 4},
+ { _id: '2', foo: 3},
+ { _id: '3', foo: 2},
+ { _id: '4', foo: 1}
+ ]);
+ const resp = await db.find({
+ selector: {foo: {$ne: "eba"}},
+ fields: ["_id", "foo"],
+ sort: [{foo: "desc"}]
});
+ resp.warning.should.be.oneOf(
+ [
+ 'no matching index found, create an index to optimize query time',
+ 'No matching index found, create an index to optimize query time.'
+ ]
+ );
+ resp.docs.should.deep.equal(
+ [
+ { _id: '4' },
+ { _id: '2' },
+ { _id: '1' }
+ ]
+ );
});
//need to find out what the correct response for this is
-it.skip('$and empty selector returns empty docs', function () {
- var db = context.db;
+it.skip('$and empty selector returns empty docs', async () => {
+ const db = context.db;
- return db.createIndex({
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: 1},
- {_id: '2', foo: 2},
- {_id: '3', foo: 3},
- {_id: '4', foo: 4}
- ]);
- }).then(function () {
- return db.find({
- selector: {
- $and: [{}, {}]
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.warning.should.be.oneOf(
- [
- 'no matching index found, create an index to optimize query time',
- 'No matching index found, create an index to optimize query time.'
- ]
- );
- resp.docs.should.deep.equal([]
- );
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: 1},
+ {_id: '2', foo: 2},
+ {_id: '3', foo: 3},
+ {_id: '4', foo: 4}
+ ]);
+ const resp = await db.find({
+ selector: {
+ $and: [{}, {}]
+ },
+ fields: ['_id']
+ });
+ resp.warning.should.be.oneOf(
+ [
+ 'no matching index found, create an index to optimize query time',
+ 'No matching index found, create an index to optimize query time.'
+ ]
+ );
+ resp.docs.should.deep.equal([]);
});
-it.skip('empty selector returns empty docs', function () {
- var db = context.db;
+it.skip('empty selector returns empty docs', async () => {
+ const db = context.db;
- return db.createIndex({
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: 1},
- {_id: '2', foo: 2},
- {_id: '3', foo: 3},
- {_id: '4', foo: 4}
- ]);
- }).then(function () {
- return db.find({
- selector: {
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.warning.should.be.oneOf(
- [
- 'no matching index found, create an index to optimize query time',
- 'No matching index found, create an index to optimize query time.'
- ]
- );
- resp.docs.should.deep.equal([
- {_id: '1'},
- {_id: '2'},
- {_id: '3'},
- {_id: '4'}
- ]
- );
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: 1},
+ {_id: '2', foo: 2},
+ {_id: '3', foo: 3},
+ {_id: '4', foo: 4}
+ ]);
+ const resp = await db.find({
+ selector: {
+ },
+ fields: ['_id']
+ });
+ resp.warning.should.be.oneOf(
+ [
+ 'no matching index found, create an index to optimize query time',
+ 'No matching index found, create an index to optimize query time.'
+ ]
+ );
+ resp.docs.should.deep.equal([
+ {_id: '1'},
+ {_id: '2'},
+ {_id: '3'},
+ {_id: '4'}
+ ]
+ );
});
-it('$elemMatch works with no other index', function () {
- var db = context.db;
+it('$elemMatch works with no other index', async () => {
+ const db = context.db;
- return db.createIndex({
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: [1]},
- {_id: '2', foo: [2]},
- {_id: '3', foo: [3]},
- {_id: '4', foo: [4]}
- ]);
- }).then(function () {
- return db.find({
- selector: {
- foo: {$elemMatch: {$gte: 3}}
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- { _id: "3" },
- { _id: "4" }
- ]);
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: [1]},
+ {_id: '2', foo: [2]},
+ {_id: '3', foo: [3]},
+ {_id: '4', foo: [4]}
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$elemMatch: {$gte: 3}}
+ },
+ fields: ['_id']
+ });
+ resp.docs.should.deep.equal([
+ { _id: "3" },
+ { _id: "4" }
+ ]);
});
-it.skip('error - no usable index', function () {
- var db = context.db;
- var index = {
+it.skip('error - no usable index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.find({
+ await db.createIndex(index);
+ try {
+ await db.find({
"selector": {"foo": "$exists"},
"fields": ["_id", "foo"],
"sort": [{"bar": "asc"}]
});
- }).then(function () {
throw new Error('shouldnt be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
-it('handles just regex selector', function () {
- var db = context.db;
- return db.bulkDocs([
+it('handles just regex selector', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: '1', foo: 1},
{_id: '2', foo: 2},
{_id: '3', foo: 3},
{_id: '4', foo: 4}
- ]).then(function () {
- return db.find({
+ ]);
+ const resp = await db.find({
selector: {
_id: {$regex: "1"}
},
fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([{ _id: "1" }]);
});
- });
+ resp.docs.should.deep.equal([{ _id: "1" }]);
});
-it('handles zero as a valid index value', function () {
- var db = context.db;
- return db.createIndex({
+it('handles zero as a valid index value', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: 0},
- {_id: '2', foo: 1},
- {_id: '3', foo: 2},
- {_id: '4', foo: 3}
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$eq: 0}
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: "1"}]);
- });
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: 0},
+ {_id: '2', foo: 1},
+ {_id: '3', foo: 2},
+ {_id: '4', foo: 3}
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$eq: 0}
+ },
+ fields: ['_id']
+ });
+ resp.docs.should.deep.equal([{_id: "1"}]);
});
-it('handles null as a valid index value', function () {
- var db = context.db;
- return db.createIndex({
+it('handles null as a valid index value', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: null},
- {_id: '2', foo: 1},
- {_id: '3', foo: 2},
- {_id: '4', foo: 3}
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$eq: null}
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: "1"}]);
- });
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: null},
+ {_id: '2', foo: 1},
+ {_id: '3', foo: 2},
+ {_id: '4', foo: 3}
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$eq: null}
+ },
+ fields: ['_id']
+ });
+ resp.docs.should.deep.equal([{_id: "1"}]);
});
-it('null values are indexed', function () {
- var db = context.db;
- return db.createIndex({
+it('null values are indexed', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: null},
- {_id: '2', foo: 1},
- {_id: '3', foo: 2},
- {_id: '4', foo: 3}
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$lt: 2}
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: "1"},
- {_id: "2"},
- ]);
- });
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: null},
+ {_id: '2', foo: 1},
+ {_id: '3', foo: 2},
+ {_id: '4', foo: 3}
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$lt: 2}
+ },
+ fields: ['_id']
+ });
+ resp.docs.should.deep.equal([
+ {_id: "1"},
+ {_id: "2"},
+ ]);
});
-it('handles booleans as a valid index value', function () {
- var db = context.db;
- return db.createIndex({
+it('handles booleans as a valid index value', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: true},
- {_id: '2', foo: false},
- {_id: '3', foo: 2},
- {_id: '4', foo: 3}
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$eq: true}
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '1'}]);
- });
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: true},
+ {_id: '2', foo: false},
+ {_id: '3', foo: 2},
+ {_id: '4', foo: 3}
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$eq: true}
+ },
+ fields: ['_id']
+ });
+ resp.docs.should.deep.equal([{_id: '1'}]);
});
-it('boolean values are indexed', function () {
- var db = context.db;
- return db.createIndex({
+it('boolean values are indexed', async () => {
+ const db = context.db;
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: true},
- {_id: '2', foo: false},
- {_id: '3', foo: 2},
- {_id: '4', foo: 3}
- ]).then(function () {
- return db.find({
- selector: {
- foo: {$lt: 2}
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: '2'},
- {_id: '1'}
- ]);
- });
- });
});
+ await db.bulkDocs([
+ {_id: '1', foo: true},
+ {_id: '2', foo: false},
+ {_id: '3', foo: 2},
+ {_id: '4', foo: 3}
+ ]);
+ const resp = await db.find({
+ selector: {
+ foo: {$lt: 2}
+ },
+ fields: ['_id']
+ });
+ resp.docs.should.deep.equal([
+ {_id: '2'},
+ {_id: '1'}
+ ]);
});
diff --git a/tests/find/test-suite-1/test.elem-match.js b/tests/find/test-suite-1/test.elem-match.js
index 47e9c9d49..9b4c2003d 100644
--- a/tests/find/test-suite-1/test.elem-match.js
+++ b/tests/find/test-suite-1/test.elem-match.js
@@ -1,10 +1,10 @@
'use strict';
-describe('test.elem-match.js', function () {
+describe('test.elem-match.js', () => {
if (testUtils.adapterType() === 'http') { return; }
- beforeEach(function () {
- return context.db.bulkDocs([
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{'_id': 'peach', eats: ['cake', 'turnips', 'sweets'], results: [ 82, 85, 88 ]},
{'_id': 'sonic', eats: ['chili dogs'], results: [ 75, 88, 89 ]},
{'_id': 'fox', eats: []},
@@ -14,110 +14,103 @@ describe('test.elem-match.js', function () {
]);
});
- it('basic test', function () {
- var db = context.db;
- return db.find({
+ it('basic test', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
_id: {$gt: 'a'},
eats: {$elemMatch: {$eq: 'cake'}}
}
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(['mario', 'peach']);
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).sort().should.deep.equal(['mario', 'peach']);
});
- it('basic test with two operators', function () {
- var db = context.db;
- return db.find({
+ it('basic test with two operators', async () => {
+ const db = context.db;
+ const resp = await db.find({
selector: {
_id: {$gt: 'a'},
results: {$elemMatch: {$gte: 80, $lt: 85}}
}
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal(['kirby', 'peach']);
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal(['kirby', 'peach']);
});
- it('with object in array', function () {
- var db = context.db;
- var docs = [
+ it('with object in array', async () => {
+ const db = context.db;
+ const docs = [
{_id: '1', events: [{eventId: 1, status: 'completed'}, {eventId: 2, status: 'started'}]},
{_id: '2', events: [{eventId: 1, status: 'pending'}, {eventId: 2, status: 'finished'}]},
{_id: '3', events: [{eventId: 1, status: 'pending'}, {eventId: 2, status: 'started'}]},
];
- return db.bulkDocs(docs).then(function () {
- return db.find({
- selector: {
- events: {$elemMatch: {"status": {$eq: 'pending'}, "eventId": {$eq: 1}}},
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal(['2', '3']);
- });
+ await db.bulkDocs(docs);
+ const resp = await db.find({
+ selector: {
+ events: {$elemMatch: {"status": {$eq: 'pending'}, "eventId": {$eq: 1}}},
+ },
+ fields: ['_id']
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal(['2', '3']);
});
- it('with object in array couchdb style', function () {
- var db = context.db;
- var docs = [
+ it('with object in array couchdb style', async () => {
+ const db = context.db;
+ const docs = [
{_id: '1', events: [{eventId: 1, status: 'completed'}, {eventId: 2, status: 'started'}]},
{_id: '2', events: [{eventId: 1, status: 'pending'}, {eventId: 2, status: 'finished'}]},
{_id: '3', events: [{eventId: 1, status: 'pending'}, {eventId: 2, status: 'started'}]},
];
- return db.bulkDocs(docs).then(function () {
- return db.find({
- selector: {
- events: {$elemMatch: {"status": 'pending', "eventId": 1}},
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal(['2', '3']);
- });
+ await db.bulkDocs(docs);
+ const resp = await db.find({
+ selector: {
+ events: {$elemMatch: {"status": 'pending', "eventId": 1}},
+ },
+ fields: ['_id']
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal(['2', '3']);
});
- it('should error for non-object query value', function () {
- var db = context.db;
- return db.find({
- selector: {
- events: { $elemMatch: null },
- },
- }).then(function () {
+ it('should error for non-object query value', async () => {
+ const db = context.db;
+ try {
+ await db.find({
+ selector: {
+ events: { $elemMatch: null },
+ },
+ });
throw new Error('Function should throw');
- }, function (err) {
+ } catch (err) {
err.message.should.eq('Query operator $elemMatch must be an object. Received : null');
- });
+ }
});
- it('with null value in array', function () {
- var db = context.db;
- var docs = [
+ it('with null value in array', async () => {
+ const db = context.db;
+ const docs = [
{_id: '1', values: [null]},
{_id: '2', values: [1, null, 3]},
{_id: '3', values: [1, 2, 3]}
];
- return db.bulkDocs(docs).then(function () {
- return db.find({
- selector: {
- values: {$elemMatch: {$eq: null}},
- },
- fields: ['_id']
- }).then(function (resp) {
- resp.docs.map(function (doc) {
- return doc._id;
- }).should.deep.equal(['1', '2']);
- });
+ await db.bulkDocs(docs);
+ const resp = await db.find({
+ selector: {
+ values: {$elemMatch: {$eq: null}},
+ },
+ fields: ['_id']
});
+ resp.docs.map((doc) => {
+ return doc._id;
+ }).should.deep.equal(['1', '2']);
});
});
diff --git a/tests/find/test-suite-1/test.eq.js b/tests/find/test-suite-1/test.eq.js
index 04f7ba697..a3f265052 100644
--- a/tests/find/test-suite-1/test.eq.js
+++ b/tests/find/test-suite-1/test.eq.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.eq.js', function () {
- it('does eq queries', function () {
- var db = context.db;
- var index = {
+describe('test.eq.js', () => {
+ it('does eq queries', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -11,27 +11,24 @@ describe('test.eq.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo'},
- { _id: '2', foo: 'ebb'},
- { _id: '3', foo: 'eba'},
- { _id: '4', foo: 'abo'}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: "eba"},
- fields: ["_id", "foo"],
- sort: [{foo: "asc"}]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '3', foo: 'eba'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo'},
+ { _id: '2', foo: 'ebb'},
+ { _id: '3', foo: 'eba'},
+ { _id: '4', foo: 'abo'}
+ ]);
+ const resp = await db.find({
+ selector: {foo: "eba"},
+ fields: ["_id", "foo"],
+ sort: [{foo: "asc"}]
});
+ resp.docs.should.deep.equal([{_id: '3', foo: 'eba'}]);
});
- it('does explicit $eq queries', function () {
- var db = context.db;
- var index = {
+ it('does explicit $eq queries', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -39,27 +36,24 @@ describe('test.eq.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo'},
- { _id: '2', foo: 'ebb'},
- { _id: '3', foo: 'eba'},
- { _id: '4', foo: 'abo'}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: {$eq: "eba"}},
- fields: ["_id", "foo"],
- sort: [{foo: "asc"}]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{ _id: '3', foo: 'eba'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo'},
+ { _id: '2', foo: 'ebb'},
+ { _id: '3', foo: 'eba'},
+ { _id: '4', foo: 'abo'}
+ ]);
+ const resp = await db.find({
+ selector: {foo: {$eq: "eba"}},
+ fields: ["_id", "foo"],
+ sort: [{foo: "asc"}]
});
+ resp.docs.should.deep.equal([{ _id: '3', foo: 'eba'}]);
});
- it('does eq queries, no fields', function () {
- var db = context.db;
- var index = {
+ it('does eq queries, no fields', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -67,28 +61,25 @@ describe('test.eq.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo'},
- { _id: '2', foo: 'ebb'},
- { _id: '3', foo: 'eba'},
- { _id: '4', foo: 'abo'}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: "eba"},
- sort: [{foo: "asc"}]
- });
- }).then(function (resp) {
- should.exist(resp.docs[0]._rev);
- delete resp.docs[0]._rev;
- resp.docs.should.deep.equal([{_id: '3', foo: 'eba'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo'},
+ { _id: '2', foo: 'ebb'},
+ { _id: '3', foo: 'eba'},
+ { _id: '4', foo: 'abo'}
+ ]);
+ const resp = await db.find({
+ selector: {foo: "eba"},
+ sort: [{foo: "asc"}]
});
+ should.exist(resp.docs[0]._rev);
+ delete resp.docs[0]._rev;
+ resp.docs.should.deep.equal([{_id: '3', foo: 'eba'}]);
});
- it('does eq queries, no fields or sort', function () {
- var db = context.db;
- var index = {
+ it('does eq queries, no fields or sort', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -96,366 +87,328 @@ describe('test.eq.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo'},
- { _id: '2', foo: 'ebb'},
- { _id: '3', foo: 'eba'},
- { _id: '4', foo: 'abo'}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: "eba"}
- });
- }).then(function (resp) {
- should.exist(resp.docs[0]._rev);
- delete resp.docs[0]._rev;
- resp.docs.should.deep.equal([{_id: '3', foo: 'eba'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo'},
+ { _id: '2', foo: 'ebb'},
+ { _id: '3', foo: 'eba'},
+ { _id: '4', foo: 'abo'}
+ ]);
+ const resp = await db.find({
+ selector: {foo: "eba"}
});
+ should.exist(resp.docs[0]._rev);
+ delete resp.docs[0]._rev;
+ resp.docs.should.deep.equal([{_id: '3', foo: 'eba'}]);
});
- it.skip('does eq queries, no index name', function () {
- var db = context.db;
- var index = {
+ it.skip('does eq queries, no index name', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo'},
- { _id: '2', foo: 'ebb'},
- { _id: '3', foo: 'eba'},
- { _id: '4', foo: 'abo'}
- ]);
- }).then(function () {
- return db.getIndexes();
- }).then(function (resp) {
- // this is some kind of auto-generated hash
- resp.indexes[1].ddoc.should.match(/_design\/.*/);
- var ddocName = resp.indexes[1].ddoc.split('/')[1];
- resp.indexes[1].name.should.equal(ddocName);
- delete resp.indexes[1].ddoc;
- delete resp.indexes[1].name;
- resp.should.deep.equal({
- "total_rows":2,
- "indexes": [
- {
- "ddoc": null,
- "name": "_all_docs",
- "type": "special",
- "def": {
- "fields": [
- {
- "_id": "asc"
- }
- ]
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo'},
+ { _id: '2', foo: 'ebb'},
+ { _id: '3', foo: 'eba'},
+ { _id: '4', foo: 'abo'}
+ ]);
+ const getResp = await db.getIndexes();
+ // this is some kind of auto-generated hash
+ getResp.indexes[1].ddoc.should.match(/_design\/.*/);
+ const ddocName = getResp.indexes[1].ddoc.split('/')[1];
+ getResp.indexes[1].name.should.equal(ddocName);
+ delete getResp.indexes[1].ddoc;
+ delete getResp.indexes[1].name;
+ getResp.should.deep.equal({
+ "total_rows":2,
+ "indexes": [
+ {
+ "ddoc": null,
+ "name": "_all_docs",
+ "type": "special",
+ "def": {
+ "fields": [
+ {
+ "_id": "asc"
+ }
+ ]
+ }
+ },
+ {
+ "type": "json",
+ "def": {
+ "fields": [
+ {
+ "foo": "asc"
+ }
+ ]
+ }
+ }
+ ]
+ });
+ const ddoc = await db.get('_design/' + ddocName);
+ const ddocId = ddoc._id.split('/')[1];
+
+ Object.keys(ddoc.views).should.deep.equal([ddocId]);
+ delete ddoc._id;
+ delete ddoc._rev;
+ ddoc.views.theView = ddoc.views[ddocId];
+ delete ddoc.views[ddocId];
+ delete ddoc.views.theView.options.w;
+
+ ddoc.should.deep.equal({
+ "language": "query",
+ "views": {
+ theView: {
+ "map": {
+ "fields": {
+ "foo": "asc"
}
},
- {
- "type": "json",
+ "reduce": "_count",
+ "options": {
"def": {
"fields": [
- {
- "foo": "asc"
- }
+ "foo"
]
}
}
- ]
- });
- return db.get('_design/' + ddocName);
- }).then(function (ddoc) {
- var ddocId = ddoc._id.split('/')[1];
-
- Object.keys(ddoc.views).should.deep.equal([ddocId]);
- delete ddoc._id;
- delete ddoc._rev;
- ddoc.views.theView = ddoc.views[ddocId];
- delete ddoc.views[ddocId];
- delete ddoc.views.theView.options.w;
-
- ddoc.should.deep.equal({
- "language": "query",
- "views": {
- theView: {
- "map": {
- "fields": {
- "foo": "asc"
- }
- },
- "reduce": "_count",
- "options": {
- "def": {
- "fields": [
- "foo"
- ]
- }
- }
- }
}
- });
+ }
+ });
- return db.find({
- selector: {foo: "eba"}
- });
- }).then(function (resp) {
- should.exist(resp.docs[0]._rev);
- delete resp.docs[0]._rev;
- resp.should.deep.equal({
- docs: [
- {_id: '3', foo: 'eba'}
- ]
- });
+ const findResp = await db.find({
+ selector: {foo: "eba"}
+ });
+ should.exist(findResp.docs[0]._rev);
+ delete findResp.docs[0]._rev;
+ findResp.should.deep.equal({
+ docs: [
+ {_id: '3', foo: 'eba'}
+ ]
});
});
- it('#7 does eq queries 1', function () {
- var db = context.db;
- var index = {
+ it('#7 does eq queries 1', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo', bar: 'zxy'},
- { _id: '2', foo: 'ebb', bar: 'zxy'},
- { _id: '3', foo: 'eba', bar: 'zxz'},
- { _id: '4', foo: 'abo', bar: 'zxz'}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: {$gt: "a"}, bar: {$eq: 'zxy'}},
- fields: ["_id"],
- sort: [{foo: "asc"}]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{ _id: '2'}, { _id: '1'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo', bar: 'zxy'},
+ { _id: '2', foo: 'ebb', bar: 'zxy'},
+ { _id: '3', foo: 'eba', bar: 'zxz'},
+ { _id: '4', foo: 'abo', bar: 'zxz'}
+ ]);
+ const resp = await db.find({
+ selector: {foo: {$gt: "a"}, bar: {$eq: 'zxy'}},
+ fields: ["_id"],
+ sort: [{foo: "asc"}]
});
+ resp.docs.should.deep.equal([{ _id: '2'}, { _id: '1'}]);
});
- it('#7 does eq queries 2', function () {
- var db = context.db;
- var index = {
+ it('#7 does eq queries 2', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: 'eyo', bar: 'zxy'},
- {_id: '2', foo: 'ebb', bar: 'zxy'},
- {_id: '3', foo: 'eba', bar: 'zxz'},
- {_id: '4', foo: 'abo', bar: 'zxz'}
- ]);
- }).then(function () {
- return db.find({
- selector: {foo: {$gt: "a"}, bar: {$eq: 'zxy'}},
- fields: ["_id"],
- sort: [{foo: "asc"}]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '2'}, {_id: '1'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', foo: 'eyo', bar: 'zxy'},
+ {_id: '2', foo: 'ebb', bar: 'zxy'},
+ {_id: '3', foo: 'eba', bar: 'zxz'},
+ {_id: '4', foo: 'abo', bar: 'zxz'}
+ ]);
+ const resp = await db.find({
+ selector: {foo: {$gt: "a"}, bar: {$eq: 'zxy'}},
+ fields: ["_id"],
+ sort: [{foo: "asc"}]
});
+ resp.docs.should.deep.equal([{_id: '2'}, {_id: '1'}]);
});
- it('#170 does queries with a null value', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with a null value', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: "1" },
- {_id: '3', field1: "1", field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '1'}, {_id: '2'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: "1" },
+ {_id: '3', field1: "1", field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([{_id: '1'}, {_id: '2'}]);
});
- it('#170 does queries with a null value (explicit $eq)', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with a null value (explicit $eq)', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: "1" },
- {_id: '3', field1: "1", field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: {$eq: null}},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '1'}, {_id: '2'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: "1" },
+ {_id: '3', field1: "1", field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: {$eq: null}},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([{_id: '1'}, {_id: '2'}]);
});
- it('#170 does queries with multiple null values', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with multiple null values', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: "1" },
- {_id: '3', field1: "1", field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null, field2: null},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '1'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: "1" },
+ {_id: '3', field1: "1", field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null, field2: null},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([{_id: '1'}]);
});
- it('#170 does queries with multiple null values - $lte', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with multiple null values - $lte', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: "1" },
- {_id: '3', field1: "1", field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null, field2: {$lte: null}},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '1'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: "1" },
+ {_id: '3', field1: "1", field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null, field2: {$lte: null}},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([{_id: '1'}]);
});
- it('#170 does queries with multiple null values - $gte', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with multiple null values - $gte', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: "1" },
- {_id: '3', field1: "1", field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null, field2: {$gte: null}},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([
- {_id: '1'},
- {_id: '2'}
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: "1" },
+ {_id: '3', field1: "1", field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null, field2: {$gte: null}},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([
+ {_id: '1'},
+ {_id: '2'}
+ ]);
});
- it('#170 does queries with multiple null values - $ne', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with multiple null values - $ne', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: "1" },
- {_id: '3', field1: "1", field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null, field2: {$ne: null}},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '2'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: "1" },
+ {_id: '3', field1: "1", field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null, field2: {$ne: null}},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([{_id: '2'}]);
});
- it('#170 does queries with multiple null values - $mod', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with multiple null values - $mod', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: 1 },
- {_id: '3', field1: 1, field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null, field2: {$mod: [1, 0]}},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '2'}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: 1 },
+ {_id: '3', field1: 1, field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null, field2: {$mod: [1, 0]}},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([{_id: '2'}]);
});
- it('#170 does queries with multiple null values - $mod', function () {
- var db = context.db;
- var index = {
+ it('#170 does queries with multiple null values - $mod', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["field1"]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field1: null, field2: null },
- {_id: '2', field1: null, field2: null },
- {_id: '3', field1: null, field2: null },
- ]);
- }).then(function () {
- return db.find({
- selector: {field1: null, field2: {$mod: [1, 0]}},
- fields: ["_id"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field1: null, field2: null },
+ {_id: '2', field1: null, field2: null },
+ {_id: '3', field1: null, field2: null },
+ ]);
+ const resp = await db.find({
+ selector: {field1: null, field2: {$mod: [1, 0]}},
+ fields: ["_id"]
});
+ resp.docs.should.deep.equal([]);
});
it('does queries with array containing null', async () => {
@@ -471,143 +424,130 @@ describe('test.eq.js', function () {
});
describe("implicit/explicit $eq", () => {
- it('implicit $eq queries against objects recurse', function () {
- var db = context.db;
- var index = {
+ it('implicit $eq queries against objects recurse', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [ "field.a" ]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field: {a: 1, b: 2}},
- {_id: '2', field: {a: 1, b: {$eq: 1}}},
- {_id: '3', field: {a: 1, b: 1}},
- ]);
- }).then(function () {
- return db.find({
- selector: { field: {a: 1, b: {$eq: 1}} },
- fields: [ "_id" ]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([ {_id: '3'} ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field: {a: 1, b: 2}},
+ {_id: '2', field: {a: 1, b: {$eq: 1}}},
+ {_id: '3', field: {a: 1, b: 1}},
+ ]);
+ const resp = await db.find({
+ selector: { field: {a: 1, b: {$eq: 1}} },
+ fields: [ "_id" ]
});
+ resp.docs.should.deep.equal([ {_id: '3'} ]);
});
- it('implicit $eq queries against objects using dot notation recurse', function () {
- var db = context.db;
- var index = {
+
+ it('implicit $eq queries against objects using dot notation recurse', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [ "field.a" ]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field: {sub: {a: 1, b: 2}}},
- {_id: '2', field: {sub: {a: 1, b: {$eq: 1}}}},
- {_id: '3', field: {sub: {a: 1, b: 1}}},
- ]);
- }).then(function () {
- return db.find({
- selector: {field: {"sub.a": 1, "sub.b": {$eq: 1}}},
- fields: [ "_id" ]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([ {_id: '3'} ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field: {sub: {a: 1, b: 2}}},
+ {_id: '2', field: {sub: {a: 1, b: {$eq: 1}}}},
+ {_id: '3', field: {sub: {a: 1, b: 1}}},
+ ]);
+ const resp = await db.find({
+ selector: {field: {"sub.a": 1, "sub.b": {$eq: 1}}},
+ fields: [ "_id" ]
});
+ resp.docs.should.deep.equal([ {_id: '3'} ]);
});
- it('$allMatch against objects using implicit $eq recurses', function () {
- var db = context.db;
- var index = {
+
+ it('$allMatch against objects using implicit $eq recurses', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [ "field.a" ]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field:[{sub: {a: 1, b: 2}}]},
- {_id: '2', field:[{sub: {a: 1, b: {$eq: 1}}}]},
- {_id: '3', field:[{sub: {a: 1, b: 1}}]},
- ]);
- }).then(function () {
- return db.find({
- selector: {field:{ $allMatch:{sub: {a: 1, b: {$eq: 1}}}}},
- fields: [ "_id" ]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([ {_id: '3'} ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field:[{sub: {a: 1, b: 2}}]},
+ {_id: '2', field:[{sub: {a: 1, b: {$eq: 1}}}]},
+ {_id: '3', field:[{sub: {a: 1, b: 1}}]},
+ ]);
+ const resp = await db.find({
+ selector: {field:{ $allMatch:{sub: {a: 1, b: {$eq: 1}}}}},
+ fields: [ "_id" ]
});
+ resp.docs.should.deep.equal([ {_id: '3'} ]);
});
- it('explicit $eq queries against objects compare directly', function () {
- var db = context.db;
- var index = {
+
+ it('explicit $eq queries against objects compare directly', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [ "field.a" ]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field: {a: 1, b: 2}},
- {_id: '2', field: {a: 1, b: {$eq: 1}}},
- {_id: '3', field: {a: 1, b: 1}},
- ]);
- }).then(function () {
- return db.find({
- selector: {field: {$eq: {a: 1, b: {$eq: 1}}}},
- fields: [ "_id" ]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{_id: '2'} ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field: {a: 1, b: 2}},
+ {_id: '2', field: {a: 1, b: {$eq: 1}}},
+ {_id: '3', field: {a: 1, b: 1}},
+ ]);
+ const resp = await db.find({
+ selector: {field: {$eq: {a: 1, b: {$eq: 1}}}},
+ fields: [ "_id" ]
});
+ resp.docs.should.deep.equal([{_id: '2'} ]);
});
- it('explicit $eq queries against objects using dot notation compare directly', function () {
- var db = context.db;
- var index = {
+
+ it('explicit $eq queries against objects using dot notation compare directly', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [ "field.a" ]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field: {sub: {a: 1, b: 2}}},
- {_id: '2', field: {"sub.a": 1, "sub.b": {$eq: 1}}},
- {_id: '3', field: {sub: {a: 1, b: 1}}},
- ]);
- }).then(function () {
- return db.find({
- selector: {field: {$eq: {"sub.a": 1, "sub.b": {$eq: 1}}}},
- fields: [ "_id" ]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([ {_id: '2'} ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field: {sub: {a: 1, b: 2}}},
+ {_id: '2', field: {"sub.a": 1, "sub.b": {$eq: 1}}},
+ {_id: '3', field: {sub: {a: 1, b: 1}}},
+ ]);
+ const resp = await db.find({
+ selector: {field: {$eq: {"sub.a": 1, "sub.b": {$eq: 1}}}},
+ fields: [ "_id" ]
});
+ resp.docs.should.deep.equal([ {_id: '2'} ]);
});
- it('$allMatch against objects using explicit $eq compares directly', function () {
- var db = context.db;
- var index = {
+
+ it('$allMatch against objects using explicit $eq compares directly', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [ "field.a" ]
}
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: '1', field: [ {sub: {a: 1, b: 2}} ]},
- {_id: '2', field: [ {sub: {a: 1, b: {$eq: 1}}} ]},
- {_id: '3', field: [ {sub: {a: 1, b: 1}} ]},
- ]);
- }).then(function () {
- return db.find({
- selector: {field: {$allMatch: {sub: {$eq: {a: 1, b: {$eq: 1}}}}}},
- fields: [ "_id" ]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([ {_id: '2'} ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: '1', field: [ {sub: {a: 1, b: 2}} ]},
+ {_id: '2', field: [ {sub: {a: 1, b: {$eq: 1}}} ]},
+ {_id: '3', field: [ {sub: {a: 1, b: 1}} ]},
+ ]);
+ const resp = await db.find({
+ selector: {field: {$allMatch: {sub: {$eq: {a: 1, b: {$eq: 1}}}}}},
+ fields: [ "_id" ]
});
+ resp.docs.should.deep.equal([ {_id: '2'} ]);
});
});
});
diff --git a/tests/find/test-suite-1/test.errors.js b/tests/find/test-suite-1/test.errors.js
index 26243b77e..05ec585d3 100644
--- a/tests/find/test-suite-1/test.errors.js
+++ b/tests/find/test-suite-1/test.errors.js
@@ -1,27 +1,29 @@
'use strict';
-describe('test.errors.js', function () {
- it('error: gimme some args', function () {
- var db = context.db;
- return db.find().then(function () {
+describe('test.errors.js', () => {
+ it('error: gimme some args', async () => {
+ const db = context.db;
+ try {
+ await db.find();
throw Error('should not be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('error: missing required key selector', function () {
- var db = context.db;
- return db.find({}).then(function () {
+ it('error: missing required key selector', async () => {
+ const db = context.db;
+ try {
+ await db.find({});
throw Error('should not be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('error: unsupported mixed sort', function () {
- var db = context.db;
- var index = {
+ it('error: unsupported mixed sort', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
{"foo": "desc"},
@@ -31,16 +33,17 @@ describe('test.errors.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
+ try {
+ await db.createIndex(index);
throw new Error('should not be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('error: invalid sort json', function () {
- var db = context.db;
- var index = {
+ it('error: invalid sort json', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -48,71 +51,68 @@ describe('test.errors.js', function () {
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'eyo'},
- { _id: '2', foo: 'ebb'},
- { _id: '3', foo: 'eba'},
- { _id: '4', foo: 'abo'}
- ]);
- }).then(function () {
- return db.find({
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'eyo'},
+ { _id: '2', foo: 'ebb'},
+ { _id: '3', foo: 'eba'},
+ { _id: '4', foo: 'abo'}
+ ]);
+ try {
+ await db.find({
selector: {foo: {"$lte": "eba"}},
fields: ["_id", "foo"],
sort: {foo: "asc"}
});
- }).then(function () {
throw new Error('shouldnt be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it.skip('error: conflicting sort and selector', function () {
- var db = context.db;
- var index = {
+ it.skip('error: conflicting sort and selector', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.find({
- "selector": {"foo": {"$gt": "\u0000\u0000"}},
- "fields": ["_id", "foo"],
- "sort": [{"_id": "asc"}]
- });
- }).then(function (res) {
- res.warning.should.match(/no matching index found/);
+ await db.createIndex(index);
+ const res = await db.find({
+ "selector": {"foo": {"$gt": "\u0000\u0000"}},
+ "fields": ["_id", "foo"],
+ "sort": [{"_id": "asc"}]
});
+ res.warning.should.match(/no matching index found/);
});
- it('error - no selector', function () {
- var db = context.db;
- var index = {
+ it('error - no selector', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.find({
+ await db.createIndex(index);
+ try {
+ await db.find({
"fields": ["_id", "foo"],
"sort": [{"foo": "asc"}]
});
- }).then(function () {
throw new Error('shouldnt be here');
- }, function (err) {
+ } catch (err) {
should.exist(err);
- });
+ }
});
- it('invalid ddoc', function () {
- var db = context.db;
+ it('invalid ddoc', async () => {
+ const db = context.db;
- var index = {
+ const index = {
"index": {
"fields": ["foo"]
},
@@ -121,47 +121,46 @@ describe('test.errors.js', function () {
"type": "json"
};
- return db.put({
+ await db.put({
_id: '_design/myddoc',
views: {
'foo-index': {
map: "function (){emit(1)}"
}
}
- }).then(function () {
- return db.createIndex(index).then(function () {
- throw new Error('expected an error');
- }, function (err) {
- should.exist(err);
- });
});
+ try {
+ await db.createIndex(index);
+ throw new Error('expected an error');
+ } catch (err) {
+ should.exist(err);
+ }
});
- it('non-logical errors with no other selector', function () {
- var db = context.db;
+ it('non-logical errors with no other selector', async () => {
+ const db = context.db;
- return db.createIndex({
+ await db.createIndex({
index: {
fields: ['foo']
}
- }).then(function () {
- return db.bulkDocs([
- {_id: '1', foo: 1},
- {_id: '2', foo: 2},
- {_id: '3', foo: 3},
- {_id: '4', foo: 4}
- ]);
- }).then(function () {
- return db.find({
+ });
+ await db.bulkDocs([
+ {_id: '1', foo: 1},
+ {_id: '2', foo: 2},
+ {_id: '3', foo: 3},
+ {_id: '4', foo: 4}
+ ]);
+ try {
+ await db.find({
selector: {
foo: {$mod: {gte: 3}}
}
- }).then(function () {
- throw new Error('expected an error');
- }, function (err) {
- should.exist(err);
});
- });
+ throw new Error('expected an error');
+ } catch (err) {
+ should.exist(err);
+ }
});
it('should throw an instance of error if createIndex throws', async () => {
diff --git a/tests/find/test-suite-1/test.escaping.js b/tests/find/test-suite-1/test.escaping.js
index 6731b5a44..7d16e26eb 100644
--- a/tests/find/test-suite-1/test.escaping.js
+++ b/tests/find/test-suite-1/test.escaping.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.escaping.js', function () {
- it('period can be escaped', function () {
- var db = context.db;
- var index = {
+describe('test.escaping.js', () => {
+ it('period can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo\\.bar"
@@ -12,24 +12,21 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc1', foo: {bar: 'a'}},
{_id: 'doc2', 'foo.bar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'foo\\.bar': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc2"}]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'foo\\.bar': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{ "_id": "doc2"}]);
});
- it('space can be escaped', function () {
- var db = context.db;
- var index = {
+ it('space can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo bar"
@@ -38,23 +35,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', 'foo bar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'foo bar': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc"}]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'foo bar': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{ "_id": "doc"}]);
});
- it('dash can be escaped', function () {
- var db = context.db;
- var index = {
+ it('dash can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo-bar"
@@ -63,23 +57,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', 'foo-bar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'foo-bar': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc"}]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'foo-bar': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{ "_id": "doc"}]);
});
- it('initial digits can be escaped', function () {
- var db = context.db;
- var index = {
+ it('initial digits can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"0foobar"
@@ -88,23 +79,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', '0foobar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'0foobar': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc"}]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'0foobar': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{ "_id": "doc"}]);
});
- it('initial dollar sign can be escaped', function () {
- var db = context.db;
- var index = {
+ it('initial dollar sign can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"$foobar"
@@ -113,23 +101,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', '$foobar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'\\$foobar': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc"}]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'\\$foobar': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{ "_id": "doc"}]);
});
- it('unicode can be escaped', function () {
- var db = context.db;
- var index = {
+ it('unicode can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"授人以鱼不如授人以渔。"
@@ -138,23 +123,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', '授人以鱼不如授人以渔。': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'授人以鱼不如授人以渔。': 'a'},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc"}]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'授人以鱼不如授人以渔。': 'a'},
+ fields: ['_id']
});
+ res.docs.should.deep.equal([{ "_id": "doc"}]);
});
- it('deeper values can be escaped', function () {
- var db = context.db;
- var index = {
+ it('deeper values can be escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo.bar.0foobar"
@@ -163,7 +145,7 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- var doc = {
+ const doc = {
_id: 'doc',
foo: {
bar: {
@@ -175,22 +157,18 @@ describe('test.escaping.js', function () {
}
}
};
- return db.bulkDocs([doc])
- .then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'foo.bar.0foobar': 'a'},
- fields: ['_id', 'foo']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([doc]);
+ await db.bulkDocs([doc]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'foo.bar.0foobar': 'a'},
+ fields: ['_id', 'foo']
});
+ res.docs.should.deep.equal([doc]);
});
- it('internal digits are not escaped', function () {
- var db = context.db;
- var index = {
+ it('internal digits are not escaped', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo0bar"
@@ -199,23 +177,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', 'foo0bar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'foo0bar': 'a'},
- fields: ['_id', 'foo0bar']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc", "foo0bar": "a" }]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'foo0bar': 'a'},
+ fields: ['_id', 'foo0bar']
});
+ res.docs.should.deep.equal([{ "_id": "doc", "foo0bar": "a" }]);
});
- it('handles escape patterns', function () {
- var db = context.db;
- var index = {
+ it('handles escape patterns', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": [
"foo_c46_bar"
@@ -224,23 +199,20 @@ describe('test.escaping.js', function () {
"name": "foo-index",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc', 'foo_c46_bar': 'a'}
- ]).then(function () {
- return db.createIndex(index);
- }).then(function () {
- return db.find({
- selector: {'foo_c46_bar': 'a'},
- fields: ['_id', 'foo_c46_bar']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ "_id": "doc", "foo_c46_bar": "a" }]);
+ ]);
+ await db.createIndex(index);
+ const res = await db.find({
+ selector: {'foo_c46_bar': 'a'},
+ fields: ['_id', 'foo_c46_bar']
});
+ res.docs.should.deep.equal([{ "_id": "doc", "foo_c46_bar": "a" }]);
});
- it('#8808 handles escape patterns without collisions (with indexes)', function () {
- var db = context.db;
- var index1 = {
+ it('#8808 handles escape patterns without collisions (with indexes)', async () => {
+ const db = context.db;
+ const index1 = {
"index": {
"fields": [
"foo/bar"
@@ -249,7 +221,7 @@ describe('test.escaping.js', function () {
"name": "foo-index-1",
"type": "json"
};
- var index2 = {
+ const index2 = {
"index": {
"fields": [
"foo_c47_bar"
@@ -258,56 +230,46 @@ describe('test.escaping.js', function () {
"name": "foo-index-2",
"type": "json"
};
- return db.bulkDocs([
+ await db.bulkDocs([
{_id: 'doc1', 'foo/bar': 'a'},
{_id: 'doc2', 'foo_c47_bar': 'a'},
- ]).then(function () {
- return db.createIndex(index1);
- }).then(function () {
- return db.createIndex(index2);
- }).then(function () {
- return db.find({
- selector: {'foo/bar': 'a'},
- fields: ['_id', 'foo/bar', 'foo_c47_bar']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ _id: 'doc1', 'foo/bar': 'a' }]);
- }).then(function () {
- return db.find({
- selector: {'foo_c47_bar': 'a'},
- fields: ['_id', 'foo/bar', 'foo_c47_bar']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ _id: 'doc2', foo_c47_bar: 'a' }]);
+ ]);
+ await db.createIndex(index1);
+ await db.createIndex(index2);
+ const res1 = await db.find({
+ selector: {'foo/bar': 'a'},
+ fields: ['_id', 'foo/bar', 'foo_c47_bar']
+ });
+ res1.docs.should.deep.equal([{ _id: 'doc1', 'foo/bar': 'a' }]);
+ const res2 = await db.find({
+ selector: {'foo_c47_bar': 'a'},
+ fields: ['_id', 'foo/bar', 'foo_c47_bar']
});
+ res2.docs.should.deep.equal([{ _id: 'doc2', foo_c47_bar: 'a' }]);
});
- it('#8808 handles escape patterns without collisions (no indexes)', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('#8808 handles escape patterns without collisions (no indexes)', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: 'doc1', 'foo/bar': 'a'},
{_id: 'doc2', 'foo_c47_bar': 'a'},
- ]).then(function () {
- return db.find({
- selector: {'foo/bar': 'a'},
- fields: ['_id', 'foo/bar', 'foo_c47_bar']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ _id: 'doc1', 'foo/bar': 'a' }]);
- }).then(function () {
- return db.find({
- selector: {'foo_c47_bar': 'a'},
- fields: ['_id', 'foo/bar', 'foo_c47_bar']
- });
- }).then(function (res) {
- res.docs.should.deep.equal([{ _id: 'doc2', foo_c47_bar: 'a' }]);
+ ]);
+ const res1 = await db.find({
+ selector: {'foo/bar': 'a'},
+ fields: ['_id', 'foo/bar', 'foo_c47_bar']
+ });
+ res1.docs.should.deep.equal([{ _id: 'doc1', 'foo/bar': 'a' }]);
+ const res2 = await db.find({
+ selector: {'foo_c47_bar': 'a'},
+ fields: ['_id', 'foo/bar', 'foo_c47_bar']
});
+ res2.docs.should.deep.equal([{ _id: 'doc2', foo_c47_bar: 'a' }]);
});
- it('#8808 bulk docs id escaping collisions in same doc (with indexes)', function () {
- var db = context.db;
- var docs = [ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ];
- var index1 = {
+ it('#8808 bulk docs id escaping collisions in same doc (with indexes)', async () => {
+ const db = context.db;
+ const docs = [ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ];
+ const index1 = {
"index": {
"fields": [
"foo/bar"
@@ -316,7 +278,7 @@ describe('test.escaping.js', function () {
"name": "foo-index-1",
"type": "json"
};
- var index2 = {
+ const index2 = {
"index": {
"fields": [
"foo_c47_bar"
@@ -325,71 +287,47 @@ describe('test.escaping.js', function () {
"name": "foo-index-2",
"type": "json"
};
- return db.bulkDocs(docs).then(function (results) {
- results.should.have.length(1, 'results length did not match');
- results[0].ok.should.equal(true);
- }).then(function () {
- return db.allDocs({ include_docs: true });
- }).then(function (results) {
- results.rows.should.have.length(1, 'results length did not match');
+ const results = await db.bulkDocs(docs);
+ results.should.have.length(1, 'results length did not match');
+ results[0].ok.should.equal(true);
+ const allDocsResults = await db.allDocs({ include_docs: true });
+ allDocsResults.rows.should.have.length(1, 'results length did not match');
- results.rows[0].doc._id.should.equal('doc');
- results.rows[0].doc['foo/bar'].should.equal(-1);
- results.rows[0].doc['foo_c47_bar'].should.equal(2);
- }).then(function () {
- return db.createIndex(index1);
- }).then(function () {
- return db.createIndex(index2);
- }).then(function () {
- return db.find({ selector: {'foo/bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.length.should.equal(0, 'foo/bar should not be greater than 0');
- }).then(function () {
- return db.find({ selector: {'foo/bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.should.deep.equal([{ _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 }]);
- }).then(function () {
- return db.find({ selector: {'foo_c47_bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.length.should.equal(0, 'foo_c47_bar should not be less than 0');
- }).then(function () {
- return db.find({ selector: {'foo_c47_bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.should.deep.equal([{ _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ]);
- });
+ allDocsResults.rows[0].doc._id.should.equal('doc');
+ allDocsResults.rows[0].doc['foo/bar'].should.equal(-1);
+ allDocsResults.rows[0].doc['foo_c47_bar'].should.equal(2);
+ await db.createIndex(index1);
+ await db.createIndex(index2);
+ const res1 = await db.find({ selector: {'foo/bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res1.docs.length.should.equal(0, 'foo/bar should not be greater than 0');
+ const res2 = await db.find({ selector: {'foo/bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res2.docs.should.deep.equal([{ _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 }]);
+ const res3 = await db.find({ selector: {'foo_c47_bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res3.docs.length.should.equal(0, 'foo_c47_bar should not be less than 0');
+ const res4 = await db.find({ selector: {'foo_c47_bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res4.docs.should.deep.equal([{ _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ]);
});
- it('#8808 bulk docs id escaping collisions in same doc (no indexes)', function () {
- var db = context.db;
- var docs = [ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ];
- return db.bulkDocs(docs).then(function (results) {
- results.should.have.length(1, 'results length did not match');
- results[0].ok.should.equal(true);
- }).then(function () {
- return db.allDocs({ include_docs: true });
- }).then(function (results) {
- results.rows.should.have.length(1, 'results length did not match');
+ it('#8808 bulk docs id escaping collisions in same doc (no indexes)', async () => {
+ const db = context.db;
+ const docs = [ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ];
+ const results = await db.bulkDocs(docs);
+ results.should.have.length(1, 'results length did not match');
+ results[0].ok.should.equal(true);
+ const allDocsResults = await db.allDocs({ include_docs: true });
+ allDocsResults.rows.should.have.length(1, 'results length did not match');
- results.rows[0].doc._id.should.equal('doc');
- results.rows[0].doc['foo/bar'].should.equal(-1);
- results.rows[0].doc['foo_c47_bar'].should.equal(2);
- }).then(function () {
- return db.find({ selector: {'foo/bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.length.should.equal(0, 'foo/bar should not be greater than 0');
- }).then(function () {
- return db.find({ selector: {'foo/bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.should.deep.equal([ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ]);
- }).then(function () {
- return db.find({ selector: {'foo_c47_bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.length.should.equal(0, 'foo_c47_bar should not be less than 0');
- }).then(function () {
- return db.find({ selector: {'foo_c47_bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
- }).then(function (res) {
- res.docs.should.deep.equal([ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ]);
- });
+ allDocsResults.rows[0].doc._id.should.equal('doc');
+ allDocsResults.rows[0].doc['foo/bar'].should.equal(-1);
+ allDocsResults.rows[0].doc['foo_c47_bar'].should.equal(2);
+ const res1 = await db.find({ selector: {'foo/bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res1.docs.length.should.equal(0, 'foo/bar should not be greater than 0');
+ const res2 = await db.find({ selector: {'foo/bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res2.docs.should.deep.equal([ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ]);
+ const res3 = await db.find({ selector: {'foo_c47_bar': {$lt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res3.docs.length.should.equal(0, 'foo_c47_bar should not be less than 0');
+ const res4 = await db.find({ selector: {'foo_c47_bar': {$gt: 0}}, fields: ['_id', 'foo/bar', 'foo_c47_bar'] });
+ res4.docs.should.deep.equal([ { _id: 'doc', 'foo/bar': -1, foo_c47_bar: 2 } ]);
});
it('#9002: query works without rewrite in nested object', async () => {
diff --git a/tests/find/test-suite-1/test.exists.js b/tests/find/test-suite-1/test.exists.js
index 1cbe034c0..ce6d1c5bc 100644
--- a/tests/find/test-suite-1/test.exists.js
+++ b/tests/find/test-suite-1/test.exists.js
@@ -1,193 +1,179 @@
'use strict';
-describe('test.exists.js', function () {
- var sortById = testUtils.sortById;
+describe('test.exists.js', () => {
+ const sortById = testUtils.sortById;
- it('does $exists queries - true', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('does $exists queries - true', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: 'a', foo: 'bar'},
{_id: 'b', foo: {yo: 'dude'}},
{_id: 'c', foo: null},
{_id: 'd'}
- ]).then(function () {
- return db.find({
- selector: {
- 'foo': {'$exists': true}
- },
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "a"},
- {"_id": "b"},
- {"_id": "c"}
- ]);
+ ]);
+ const res = await db.find({
+ selector: {
+ 'foo': {'$exists': true}
+ },
+ fields: ['_id']
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "a"},
+ {"_id": "b"},
+ {"_id": "c"}
+ ]);
});
- it('does $exists queries - false', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('does $exists queries - false', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: 'a', foo: 'bar'},
{_id: 'b', foo: {yo: 'dude'}},
{_id: 'c', foo: null},
{_id: 'd'}
- ]).then(function () {
- return db.find({
- selector: {
- 'foo': {'$exists': false}
- },
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "d"}
- ]);
+ ]);
+ const res = await db.find({
+ selector: {
+ 'foo': {'$exists': false}
+ },
+ fields: ['_id']
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "d"}
+ ]);
});
- it('does $exists queries - true/undef (multi-field)', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('does $exists queries - true/undef (multi-field)', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: 'a', foo: 'bar', bar: 'baz'},
{_id: 'b', foo: {yo: 'dude'}},
{_id: 'c', foo: null, bar: 'quux'},
{_id: 'd'}
- ]).then(function () {
- return db.find({
- selector: {
- 'foo': {'$exists': true}
- },
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "a"},
- {"_id": "b"},
- {"_id": "c"}
- ]);
+ ]);
+ const res = await db.find({
+ selector: {
+ 'foo': {'$exists': true}
+ },
+ fields: ['_id']
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "a"},
+ {"_id": "b"},
+ {"_id": "c"}
+ ]);
});
- it('does $exists queries - $eq/true (multi-field)', function () {
- var db = context.db;
- var index = {
+ it('does $exists queries - $eq/true (multi-field)', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: 'a', foo: 'bar', bar: 'baz'},
- {_id: 'b', foo: 'bar', bar: {yo: 'dude'}},
- {_id: 'c', foo: null, bar: 'quux'},
- {_id: 'd'}
- ]);
- }).then(function () {
- return db.find({
- selector: {'foo': 'bar', bar: {$exists: true}},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "a"},
- {"_id": "b"}
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: 'a', foo: 'bar', bar: 'baz'},
+ {_id: 'b', foo: 'bar', bar: {yo: 'dude'}},
+ {_id: 'c', foo: null, bar: 'quux'},
+ {_id: 'd'}
+ ]);
+ const res = await db.find({
+ selector: {'foo': 'bar', bar: {$exists: true}},
+ fields: ['_id']
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "a"},
+ {"_id": "b"}
+ ]);
});
- it('does $exists queries - $eq/false (multi-field)', function () {
- var db = context.db;
- var index = {
+ it('does $exists queries - $eq/false (multi-field)', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- {_id: 'a', foo: 'bar', bar: 'baz'},
- {_id: 'b', foo: 'bar', bar: {yo: 'dude'}},
- {_id: 'c', foo: 'bar', bar: 'yo'},
- {_id: 'd', foo: 'bar'}
- ]);
- }).then(function () {
- return db.find({
- selector: {'foo': 'bar', bar: {$exists: false}},
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "d"}
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ {_id: 'a', foo: 'bar', bar: 'baz'},
+ {_id: 'b', foo: 'bar', bar: {yo: 'dude'}},
+ {_id: 'c', foo: 'bar', bar: 'yo'},
+ {_id: 'd', foo: 'bar'}
+ ]);
+ const res = await db.find({
+ selector: {'foo': 'bar', bar: {$exists: false}},
+ fields: ['_id']
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "d"}
+ ]);
});
- it('does $exists queries - true/true (multi-field)', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('does $exists queries - true/true (multi-field)', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: 'a', foo: 'bar', bar: 'baz'},
{_id: 'b', foo: {yo: 'dude'}},
{_id: 'c', foo: null, bar: 'quux'},
{_id: 'd'}
- ]).then(function () {
- return db.find({
- selector: {
- foo: {'$exists': true},
- bar: {$exists: true}
- },
- fields: ['_id']
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "a"},
- {"_id": "c"}
- ]);
+ ]);
+ const res = await db.find({
+ selector: {
+ foo: {'$exists': true},
+ bar: {$exists: true}
+ },
+ fields: ['_id']
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "a"},
+ {"_id": "c"}
+ ]);
});
- it('does $exists queries - true/false (multi-field)', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('does $exists queries - true/false (multi-field)', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{_id: 'a', foo: 'bar', bar: 'baz'},
{_id: 'b', foo: {yo: 'dude'}},
{_id: 'c', foo: null, bar: 'quux'},
{_id: 'd'}
- ]).then(function () {
- return db.find({
+ ]);
+ const res = await db.find({
+ selector: {
+ foo: {'$exists': true},
+ bar: {$exists: false}
+ },
+ fields: ['_id']
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {"_id": "b"}
+ ]);
+ });
+
+ it('should error for non-boolean query value', async () => {
+ const db = context.db;
+ try {
+ await db.find({
selector: {
- foo: {'$exists': true},
- bar: {$exists: false}
+ foo: { '$exists': 'true' },
},
- fields: ['_id']
});
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {"_id": "b"}
- ]);
- });
- });
- it('should error for non-boolean query value', function () {
- var db = context.db;
- return db.find({
- selector: {
- foo: { '$exists': 'true' },
- },
- }).then(function () {
throw new Error('Function should throw');
- }, function (err) {
+ } catch (err) {
err.message.should.eq('Query operator $exists must be a boolean. Received string: true');
- });
+ }
});
});
diff --git a/tests/find/test-suite-1/test.explain.js b/tests/find/test-suite-1/test.explain.js
index b0f4ed9b2..3d3ea7a0c 100644
--- a/tests/find/test-suite-1/test.explain.js
+++ b/tests/find/test-suite-1/test.explain.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.explain.js', function () {
- beforeEach(function () {
- var db = context.db;
- return db.bulkDocs([
+describe('test.explain.js', () => {
+ beforeEach(async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ name: 'mario', _id: 'mario', rank: 5, series: 'mario', debut: 1981 },
{ name: 'jigglypuff', _id: 'puff', rank: 8, series: 'pokemon', debut: 1996 },
{ name: 'link', rank: 10, _id: 'link', series: 'zelda', debut: 1986 },
@@ -16,22 +16,20 @@ describe('test.explain.js', function () {
{ name: 'samus', rank: 12, _id: 'samus', series: 'metroid', debut: 1986 },
{ name: 'yoshi', _id: 'yoshi', rank: 6, series: 'mario', debut: 1990 },
{ name: 'kirby', _id: 'kirby', series: 'kirby', rank: 2, debut: 1992 }
- ])
- .then(function () {
- return db.createIndex({
- index: {
- "fields": ["name", "series"]
- },
- "type": "json",
- "name": "index-name",
- "ddoc": "design-doc-name"
- });
+ ]);
+ await db.createIndex({
+ index: {
+ "fields": ["name", "series"]
+ },
+ "type": "json",
+ "name": "index-name",
+ "ddoc": "design-doc-name"
});
});
- it.skip('explains which index it uses', function () {
- var db = context.db;
- return db.explain({
+ it.skip('explains which index it uses', async () => {
+ const db = context.db;
+ const resp = await db.explain({
selector: {
name: 'mario',
series: 'mario'
@@ -39,88 +37,87 @@ describe('test.explain.js', function () {
fields: ["_id"],
limit: 10,
skip: 1,
- }).then(function (resp) {
- var actual = { //This is an explain response from CouchDB
- "dbname": resp.dbname, //this is random based on the test
- "index": {
- "ddoc": "_design/design-doc-name",
- "name": "index-name",
- "type": "json",
- "def": {
- "fields": [
- {
- "name": "asc"
- },
- {
- "series": "asc"
- }
- ]
- }
- },
- "selector": {
- "$and": [
+ });
+ const actual = { //This is an explain response from CouchDB
+ "dbname": resp.dbname, //this is random based on the test
+ "index": {
+ "ddoc": "_design/design-doc-name",
+ "name": "index-name",
+ "type": "json",
+ "def": {
+ "fields": [
{
- "name": {
- "$eq": "mario"
- }
+ "name": "asc"
},
{
- "series": {
- "$eq": "mario"
- }
+ "series": "asc"
}
]
- },
- "opts": {
- "use_index": [],
- "bookmark": "nil",
- "limit": 25,
- "skip": 0,
- "sort": {"name": "asc"},
- "fields": [
- "_id"
- ],
- "r": [
- 49
- ],
- "conflicts": false
- },
- "limit": 10,
- "skip": 1,
+ }
+ },
+ "selector": {
+ "$and": [
+ {
+ "name": {
+ "$eq": "mario"
+ }
+ },
+ {
+ "series": {
+ "$eq": "mario"
+ }
+ }
+ ]
+ },
+ "opts": {
+ "use_index": [],
+ "bookmark": "nil",
+ "limit": 25,
+ "skip": 0,
+ "sort": {"name": "asc"},
"fields": [
"_id"
],
- "range": {
- "start_key": [
- "mario",
- "mario"
- ],
- "end_key": [
- "mario",
- "mario",
- {}
- ]
- }
- };
+ "r": [
+ 49
+ ],
+ "conflicts": false
+ },
+ "limit": 10,
+ "skip": 1,
+ "fields": [
+ "_id"
+ ],
+ "range": {
+ "start_key": [
+ "mario",
+ "mario"
+ ],
+ "end_key": [
+ "mario",
+ "mario",
+ {}
+ ]
+ }
+ };
- //This is a little tricky to test due to the fact that pouchdb-find and Mango do query slightly differently
- resp.dbname.should.deep.equal(actual.dbname);
- resp.index.should.deep.equal(actual.index);
- resp.fields.should.deep.equal(actual.fields);
- resp.skip.should.deep.equal(actual.skip);
- resp.limit.should.deep.equal(actual.limit);
- });
+ //This is a little tricky to test due to the fact that pouchdb-find and Mango do query slightly differently
+ resp.dbname.should.deep.equal(actual.dbname);
+ resp.index.should.deep.equal(actual.index);
+ resp.fields.should.deep.equal(actual.fields);
+ resp.skip.should.deep.equal(actual.skip);
+ resp.limit.should.deep.equal(actual.limit);
});
- it("should work with a callback", function () {
- var db = context.db;
- return new Promise(function (resolve, reject) {
- return db.explain({
+ it("should work with a callback", async () => {
+ const db = context.db;
+ await new Promise((resolve, reject) => {
+ db.explain({
selector: {
name: 'mario',
series: 'mario'
}
- }, function (err, res) {
+ }, (err, res) => {
if (err) {
return reject(err);
}
@@ -130,10 +127,10 @@ describe('test.explain.js', function () {
});
});
- it("should work with a throw missing selector warning", function () {
- var db = context.db;
+ it("should work with a throw missing selector warning", () => {
+ const db = context.db;
db.explain()
- .catch(function (err) {
+ .catch((err) => {
assert.ok(/provide search parameters/.test(err.message));
});
});
diff --git a/tests/find/test-suite-1/test.fields.js b/tests/find/test-suite-1/test.fields.js
index 83f9fe8cc..8d91c8082 100644
--- a/tests/find/test-suite-1/test.fields.js
+++ b/tests/find/test-suite-1/test.fields.js
@@ -1,266 +1,243 @@
'use strict';
-describe('test.fields.js', function () {
- var sortById = testUtils.sortById;
+describe('test.fields.js', () => {
+ const sortById = testUtils.sortById;
- it('does 2-field queries', function () {
- var db = context.db;
- var index = {
+ it('does 2-field queries', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a'},
- { _id: '2', foo: 'b', bar: 'b'},
- { _id: '3', foo: 'a', bar: 'a'},
- { _id: '4', foo: 'c', bar: 'a'},
- { _id: '5', foo: 'b', bar: 'a'},
- { _id: '6', foo: 'a', bar: 'b'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- "foo": {"$eq": "b"},
- "bar": {"$eq": "b"}
- },
- "fields": ["_id", "foo"]
- });
- }).then(function (resp) {
- resp.docs.should.deep.equal([{ "_id": "2", "foo": "b"}]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a'},
+ { _id: '2', foo: 'b', bar: 'b'},
+ { _id: '3', foo: 'a', bar: 'a'},
+ { _id: '4', foo: 'c', bar: 'a'},
+ { _id: '5', foo: 'b', bar: 'a'},
+ { _id: '6', foo: 'a', bar: 'b'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ "foo": {"$eq": "b"},
+ "bar": {"$eq": "b"}
+ },
+ "fields": ["_id", "foo"]
});
+ resp.docs.should.deep.equal([{ "_id": "2", "foo": "b"}]);
});
- it('does 2-field queries eq/gte', function () {
- var db = context.db;
- var index = {
+ it('does 2-field queries eq/gte', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a'},
- { _id: '2', foo: 'a', bar: 'b'},
- { _id: '3', foo: 'a', bar: 'c'},
- { _id: '4', foo: 'b', bar: 'a'},
- { _id: '5', foo: 'b', bar: 'b'},
- { _id: '6', foo: 'c', bar: 'a'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- "foo": {"$eq": "a"},
- "bar": {"$gte": "b"}
- },
- "fields": ["_id"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '2' },
- { _id: '3' }
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a'},
+ { _id: '2', foo: 'a', bar: 'b'},
+ { _id: '3', foo: 'a', bar: 'c'},
+ { _id: '4', foo: 'b', bar: 'a'},
+ { _id: '5', foo: 'b', bar: 'b'},
+ { _id: '6', foo: 'c', bar: 'a'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ "foo": {"$eq": "a"},
+ "bar": {"$gte": "b"}
+ },
+ "fields": ["_id"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '2' },
+ { _id: '3' }
+ ]);
});
- it('does 2-field queries gte/gte', function () {
- var db = context.db;
- var index = {
+ it('does 2-field queries gte/gte', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a'},
- { _id: '2', foo: 'a', bar: 'b'},
- { _id: '3', foo: 'a', bar: 'c'},
- { _id: '4', foo: 'b', bar: 'a'},
- { _id: '5', foo: 'b', bar: 'b'},
- { _id: '6', foo: 'c', bar: 'a'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- "foo": {"$gte": "b"},
- "bar": {"$gte": "a"}
- },
- "fields": ["_id"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '4' },
- { _id: '5' },
- { _id: '6' }
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a'},
+ { _id: '2', foo: 'a', bar: 'b'},
+ { _id: '3', foo: 'a', bar: 'c'},
+ { _id: '4', foo: 'b', bar: 'a'},
+ { _id: '5', foo: 'b', bar: 'b'},
+ { _id: '6', foo: 'c', bar: 'a'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ "foo": {"$gte": "b"},
+ "bar": {"$gte": "a"}
+ },
+ "fields": ["_id"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '4' },
+ { _id: '5' },
+ { _id: '6' }
+ ]);
});
- it('does 2-field queries gte/lte', function () {
- var db = context.db;
- var index = {
+ it('does 2-field queries gte/lte', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a'},
- { _id: '2', foo: 'a', bar: 'b'},
- { _id: '3', foo: 'a', bar: 'c'},
- { _id: '4', foo: 'b', bar: 'a'},
- { _id: '5', foo: 'b', bar: 'b'},
- { _id: '6', foo: 'c', bar: 'a'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- "foo": {"$gte": "b"},
- "bar": {"$lte": "b"}
- },
- "fields": ["_id"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '4' },
- { _id: '5' },
- { _id: '6' }
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a'},
+ { _id: '2', foo: 'a', bar: 'b'},
+ { _id: '3', foo: 'a', bar: 'c'},
+ { _id: '4', foo: 'b', bar: 'a'},
+ { _id: '5', foo: 'b', bar: 'b'},
+ { _id: '6', foo: 'c', bar: 'a'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ "foo": {"$gte": "b"},
+ "bar": {"$lte": "b"}
+ },
+ "fields": ["_id"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '4' },
+ { _id: '5' },
+ { _id: '6' }
+ ]);
});
- it('does 3-field queries eq/eq/eq 3-field index', function () {
- var db = context.db;
- var index = {
+ it('does 3-field queries eq/eq/eq 3-field index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar", "baz"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a', baz: 'z'},
- { _id: '2', foo: 'a', bar: 'b', baz: 'z'},
- { _id: '3', foo: 'a', bar: 'c', baz: 'z'},
- { _id: '4', foo: 'b', bar: 'a', baz: 'z'},
- { _id: '5', foo: 'b', bar: 'b', baz: 'z'},
- { _id: '6', foo: 'c', bar: 'a', baz: 'z'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- foo: 'b',
- bar: 'b',
- baz: 'z'
- },
- "fields": ["_id"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '5' }
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a', baz: 'z'},
+ { _id: '2', foo: 'a', bar: 'b', baz: 'z'},
+ { _id: '3', foo: 'a', bar: 'c', baz: 'z'},
+ { _id: '4', foo: 'b', bar: 'a', baz: 'z'},
+ { _id: '5', foo: 'b', bar: 'b', baz: 'z'},
+ { _id: '6', foo: 'c', bar: 'a', baz: 'z'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ foo: 'b',
+ bar: 'b',
+ baz: 'z'
+ },
+ "fields": ["_id"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '5' }
+ ]);
});
- it('does 1-field queries eq/eq 2-field index', function () {
- var db = context.db;
- var index = {
+ it('does 1-field queries eq/eq 2-field index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a', baz: 'z'},
- { _id: '2', foo: 'a', bar: 'b', baz: 'z'},
- { _id: '3', foo: 'a', bar: 'c', baz: 'z'},
- { _id: '4', foo: 'b', bar: 'a', baz: 'z'},
- { _id: '5', foo: 'b', bar: 'b', baz: 'z'},
- { _id: '6', foo: 'c', bar: 'a', baz: 'z'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- foo: 'b'
- },
- "fields": ["_id"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '4' },
- { _id: '5' }
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a', baz: 'z'},
+ { _id: '2', foo: 'a', bar: 'b', baz: 'z'},
+ { _id: '3', foo: 'a', bar: 'c', baz: 'z'},
+ { _id: '4', foo: 'b', bar: 'a', baz: 'z'},
+ { _id: '5', foo: 'b', bar: 'b', baz: 'z'},
+ { _id: '6', foo: 'c', bar: 'a', baz: 'z'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ foo: 'b'
+ },
+ "fields": ["_id"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '4' },
+ { _id: '5' }
+ ]);
});
- it('does 2-field queries eq/eq 3-field index', function () {
- var db = context.db;
- var index = {
+ it('does 2-field queries eq/eq 3-field index', async () => {
+ const db = context.db;
+ const index = {
"index": {
"fields": ["foo", "bar", "baz"]
},
"name": "foo-index",
"type": "json"
};
- return db.createIndex(index).then(function () {
- return db.bulkDocs([
- { _id: '1', foo: 'a', bar: 'a', baz: 'z'},
- { _id: '2', foo: 'a', bar: 'b', baz: 'z'},
- { _id: '3', foo: 'a', bar: 'c', baz: 'z'},
- { _id: '4', foo: 'b', bar: 'a', baz: 'z'},
- { _id: '5', foo: 'b', bar: 'b', baz: 'z'},
- { _id: '6', foo: 'c', bar: 'a', baz: 'z'}
- ]);
- }).then(function () {
- return db.find({
- "selector": {
- foo: 'b',
- bar: 'b'
- },
- "fields": ["_id"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '5' }
- ]);
+ await db.createIndex(index);
+ await db.bulkDocs([
+ { _id: '1', foo: 'a', bar: 'a', baz: 'z'},
+ { _id: '2', foo: 'a', bar: 'b', baz: 'z'},
+ { _id: '3', foo: 'a', bar: 'c', baz: 'z'},
+ { _id: '4', foo: 'b', bar: 'a', baz: 'z'},
+ { _id: '5', foo: 'b', bar: 'b', baz: 'z'},
+ { _id: '6', foo: 'c', bar: 'a', baz: 'z'}
+ ]);
+ const resp = await db.find({
+ "selector": {
+ foo: 'b',
+ bar: 'b'
+ },
+ "fields": ["_id"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '5' }
+ ]);
});
- it('does return all fields of overlapping paths', function () {
- var db = context.db;
- return db.bulkDocs([
+ it('does return all fields of overlapping paths', async () => {
+ const db = context.db;
+ await db.bulkDocs([
{ _id: '1', foo: { bar: 'a', baz: 'b', qux: 'q'} },
{ _id: '2', foo: { bar: 'a', baz: 'z', qux: 'q'} },
- ]).then(function () {
- return db.find({
- "selector": {
- _id: '1'
- },
- "fields": ["_id", "foo.bar", "foo.baz"]
- });
- }).then(function (resp) {
- resp.docs.sort(sortById);
- resp.docs.should.deep.equal([
- { _id: '1', foo: { bar: 'a', baz: 'b'} }
- ]);
+ ]);
+ const resp = await db.find({
+ "selector": {
+ _id: '1'
+ },
+ "fields": ["_id", "foo.bar", "foo.baz"]
});
+ resp.docs.sort(sortById);
+ resp.docs.should.deep.equal([
+ { _id: '1', foo: { bar: 'a', baz: 'b'} }
+ ]);
});
});
diff --git a/tests/find/test-suite-1/test.issue66.js b/tests/find/test-suite-1/test.issue66.js
index be679255e..3e58824ba 100644
--- a/tests/find/test-suite-1/test.issue66.js
+++ b/tests/find/test-suite-1/test.issue66.js
@@ -1,9 +1,9 @@
'use strict';
-describe('test.issue66.js', function () {
+describe('test.issue66.js', () => {
- beforeEach(function () {
- return context.db.bulkDocs([
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{
name: 'Mario',
_id: 'mario',
@@ -111,675 +111,582 @@ describe('test.issue66.js', function () {
]);
});
- it('should query all docs with $gt: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gt: null}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $lt: false', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lt: false}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lt: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lt: {}}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lte: {}}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: []', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lte: []}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lte: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lt: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lt: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $gt: false', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gt: false}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gte: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gte: 0}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gt: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gt: 0}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gte: false', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gte: false}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gt: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gt: {}}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gte: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gte: {}}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $eq: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$eq: {}}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $eq: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$eq: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $eq: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$eq: 0}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $eq: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$eq: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$lte: 0}
- }
- }).then(function (response) {
- response.docs = response.docs.map(function (doc) {
- return doc._id;
- });
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $gte: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- selector: {
- _id: {$gte: null}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gt: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gt: null}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $lt: false', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lt: false}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lt: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lt: {}}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lte: {}}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: []', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lte: []}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lte: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lt: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lt: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $gt: false', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gt: false}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gte: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gte: 0}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gt: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gt: 0}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gte: false', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gte: false}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gt: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gt: {}}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $gte: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gte: {}}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
- });
-
- it('should query all docs with $eq: {}', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$eq: {}}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $eq: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$eq: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $eq: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$eq: 0}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $eq: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$eq: null}
- }
- }).then(function (response) {
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $lte: 0', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$lte: 0}
- }
- }).then(function (response) {
- response.docs = response.docs.map(function (doc) {
- return doc._id;
- });
- response.docs.should.deep.equal([]);
- });
- });
- });
-
- it('should query all docs with $gte: null', function () {
- var db = context.db;
- return db.bulkDocs(
- [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
- ).then(function () {
- return db.find({
- sort: [{_id: 'desc'}], selector: {
- _id: {$gte: null}
- }
- }).then(function (response) {
- response.docs.map(function (doc) {
- return doc._id;
- }).sort().should.deep.equal(
- ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
- 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
- 'yoshi']
- );
- });
- });
+ it('should query all docs with $gt: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gt: null}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $lt: false', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lt: false}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lt: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lt: {}}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lte: {}}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: []', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lte: []}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lte: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lt: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lt: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $gt: false', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gt: false}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gte: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gte: 0}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gt: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gt: 0}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gte: false', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gte: false}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gt: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gt: {}}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gte: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gte: {}}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $eq: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$eq: {}}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $eq: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$eq: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $eq: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$eq: 0}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $eq: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$eq: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$lte: 0}
+ }
+ });
+ response.docs = response.docs.map((doc) => doc._id);
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $gte: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ selector: {
+ _id: {$gte: null}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gt: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gt: null}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $lt: false', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lt: false}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lt: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lt: {}}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lte: {}}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: []', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lte: []}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lte: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lt: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lt: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $gt: false', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gt: false}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gte: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gte: 0}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gt: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gt: 0}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gte: false', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gte: false}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gt: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gt: {}}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $gte: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gte: {}}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
+ });
+
+ it('should query all docs with $eq: {}', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$eq: {}}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $eq: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$eq: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $eq: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$eq: 0}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $eq: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$eq: null}
+ }
+ });
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $lte: 0', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$lte: 0}
+ }
+ });
+ response.docs = response.docs.map((doc) => doc._id);
+ response.docs.should.deep.equal([]);
+ });
+
+ it('should query all docs with $gte: null', async () => {
+ const db = context.db;
+ await db.bulkDocs(
+ [{_id: 'a'}, {_id: 'b'}, {_id: 'c'}]
+ );
+ const response = await db.find({
+ sort: [{_id: 'desc'}],
+ selector: {
+ _id: {$gte: null}
+ }
+ });
+ response.docs.map((doc) => doc._id).sort().should.deep.equal(
+ ['a', 'b', 'c', 'dk', 'falcon', 'fox', 'kirby', 'link', 'luigi',
+ 'mario', 'master_hand', 'ness', 'pikachu', 'puff', 'samus',
+ 'yoshi']
+ );
});
});
diff --git a/tests/find/test-suite-1/test.limit-skip.js b/tests/find/test-suite-1/test.limit-skip.js
index b72cf0615..8d5817dcf 100644
--- a/tests/find/test-suite-1/test.limit-skip.js
+++ b/tests/find/test-suite-1/test.limit-skip.js
@@ -1,10 +1,10 @@
'use strict';
-describe('test.limit-skip.js', function () {
- var sortById = testUtils.sortById;
+describe('test.limit-skip.js', () => {
+ const sortById = testUtils.sortById;
- beforeEach(function () {
- return context.db.bulkDocs([
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{ name: 'Mario', _id: 'mario', rank: 5, series: 'Mario', debut: 1981 },
{ name: 'Jigglypuff', _id: 'puff', rank: 8, series: 'Pokemon', debut: 1996 },
{ name: 'Link', rank: 10, _id: 'link', series: 'Zelda', debut: 1986 },
@@ -20,288 +20,262 @@ describe('test.limit-skip.js', function () {
]);
});
- it('should work with $and 1-1', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 1-1', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["debut"]
- }
- });
- }).then(function () {
+ });
+ await db.createIndex({
+ "index": {
+ "fields": ["debut"]
+ }
+ });
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 1,
- skip: 1
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([{_id: 'yoshi'}]);
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 1,
+ skip: 1
});
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([{_id: 'yoshi'}]);
});
- it('should work with $and 1 1-2', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 1 1-2', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["debut"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 1,
- skip: 2
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["debut"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 1,
+ skip: 2
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([]);
});
- it('should work with $and 1 2-0', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 1 2-0', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["debut"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 2,
- skip: 0
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([{_id: 'luigi'}, {_id: 'yoshi'}]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["debut"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 2,
+ skip: 0
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([{_id: 'luigi'}, {_id: 'yoshi'}]);
});
- it('should work with $and 2, same index 0-1', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 2, same index 0-1', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series", "debut"]
}
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 0,
- skip: 1
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([]);
});
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 0,
+ skip: 1
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([]);
});
- it('should work with $and 2, same index 4-2', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 2, same index 4-2', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series", "debut"]
}
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1970}}
- ]
- },
- sort: ['series', 'debut'],
- fields: ['_id'],
- limit: 4,
- skip: 2
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {_id: 'luigi'},
- {_id: 'yoshi'}
- ]);
});
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1970}}
+ ]
+ },
+ sort: ['series', 'debut'],
+ fields: ['_id'],
+ limit: 4,
+ skip: 2
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {_id: 'luigi'},
+ {_id: 'yoshi'}
+ ]);
});
- it('should work with $and 2, same index 2-2', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 2, same index 2-2', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series", "debut"]
}
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1980}}
- ]
- },
- fields: ['_id'],
- limit: 2,
- skip: 2
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([{_id: 'luigi'}, {_id: 'yoshi'}]);
});
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1980}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 2,
+ skip: 2
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([{_id: 'luigi'}, {_id: 'yoshi'}]);
});
- it('should work with $and 3, index/no-index 10-0', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 3, index/no-index 10-0', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["rank"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$lte: 1990}}
- ]
- },
- fields: ['_id'],
- limit: 10,
- skip: 0
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([
- {_id: 'dk'},
- {_id: 'luigi'},
- {_id: 'mario'},
- {_id: 'yoshi'}
- ]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["rank"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$lte: 1990}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 10,
+ skip: 0
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([
+ {_id: 'dk'},
+ {_id: 'luigi'},
+ {_id: 'mario'},
+ {_id: 'yoshi'}
+ ]);
});
- it('should work with $and 3, index/no-index 1-0', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 3, index/no-index 1-0', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["rank"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Star Fox'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 1,
- skip: 0
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([{_id: 'fox'}]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["rank"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Star Fox'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 1,
+ skip: 0
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([{_id: 'fox'}]);
});
- it('should work with $and 3, index/no-index 2-0', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 3, index/no-index 2-0', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["rank"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1983}}
- ]
- },
- fields: ['_id'],
- limit: 2,
- skip: 0
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([{_id: 'luigi'}, {_id: 'yoshi'}]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["rank"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1983}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 2,
+ skip: 0
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([{_id: 'luigi'}, {_id: 'yoshi'}]);
});
- it('should work with $and 4, wrong index', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 4, wrong index', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["rank"]
}
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1990}}
- ]
- },
- fields: ['_id'],
- limit: 1,
- skip: 1
- }).then(function (resp) {
- resp.docs.should.deep.equal([]);
- });
});
+ const resp = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1990}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 1,
+ skip: 1
+ });
+ resp.docs.should.deep.equal([]);
});
});
diff --git a/tests/find/test-suite-1/test.limit.js b/tests/find/test-suite-1/test.limit.js
index 4c8e313c5..13b8334a9 100644
--- a/tests/find/test-suite-1/test.limit.js
+++ b/tests/find/test-suite-1/test.limit.js
@@ -1,10 +1,10 @@
'use strict';
-describe('test.limit.js', function () {
- var sortById = testUtils.sortById;
+describe('test.limit.js', () => {
+ const sortById = testUtils.sortById;
- beforeEach(function () {
- return context.db.bulkDocs([
+ beforeEach(async () => {
+ await context.db.bulkDocs([
{ name: 'Mario', _id: 'mario', rank: 5, series: 'Mario', debut: 1981 },
{ name: 'Jigglypuff', _id: 'puff', rank: 8, series: 'Pokemon', debut: 1996 },
{ name: 'Link', rank: 10, _id: 'link', series: 'Zelda', debut: 1986 },
@@ -20,269 +20,243 @@ describe('test.limit.js', function () {
]);
});
- it('should work with $and 1 limit 0', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 1 limit 0', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["debut"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 0
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["debut"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 0
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([]);
});
- it('should work with $and 1 limit 1', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 1 limit 1', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["debut"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
- {series: 'Mario'},
- {debut: {$gte: 1982}}
- ]
- },
- fields: ['_id'],
- limit: 1
- });
- }).then(function (res) {
- res.docs.sort(sortById);
- res.docs.should.deep.equal([{_id: 'luigi'}]);
});
+ await db.createIndex({
+ "index": {
+ "fields": ["debut"]
+ }
+ });
+ const res = await db.find({
+ selector: {
+ $and: [
+ {series: 'Mario'},
+ {debut: {$gte: 1982}}
+ ]
+ },
+ fields: ['_id'],
+ limit: 1
+ });
+ res.docs.sort(sortById);
+ res.docs.should.deep.equal([{_id: 'luigi'}]);
});
- it('should work with $and 1 limit 2', function () {
- var db = context.db;
- return db.createIndex({
+ it('should work with $and 1 limit 2', async () => {
+ const db = context.db;
+ await db.createIndex({
"index": {
"fields": ["series"]
}
- }).then(function () {
- return db.createIndex({
- "index": {
- "fields": ["debut"]
- }
- });
- }).then(function () {
- return db.find({
- selector: {
- $and: [
... 4802 lines suppressed ...