-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfind.spec.js
59 lines (42 loc) · 1.47 KB
/
find.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*eslint-env es6*/
const Bluebird = require('bluebird')
const debug = require('debug')('got-couch')
const CONFIG = require('./config/_index.js')
const { initCouchDb, initTest } = require('./_test-base.js')
const DB_NAME = 'couch-find-test'
const couchdb = initCouchDb(CONFIG)
const test = initTest(couchdb, DB_NAME)
test('::find should query the database using the /{db}/_find endpoint',
t =>
couchdb.then((connection) => {
Bluebird.all([
connection.create(DB_NAME, 'find-foo1', { test: 'FIND', moo: 'Elsie' })
, connection.create(DB_NAME, 'find-foo2', { test: 'FIND', moo: 'Clara' })
, connection.create(DB_NAME, 'find-foo3', { test: 'FIND', moo: 'Bessie' })
, connection.create(DB_NAME, 'find-foo4', { test: 'FIND', moo: 'Babe' })
])
.then(() => connection.find(DB_NAME, {
selector: { test: "FIND", moo: "Clara" }
}, {}))
.then((result) => {
const expected_count = 1
const expected_rows = [
{ id: 'find-foo2', test: 'FIND', moo: 'Clara' }
]
const actual_rows = result
.body
.docs
.map((x) => ({ id: x._id, test: x.test, moo: x.moo }))
t.is(actual_rows.length, expected_count, 'list count is not 1')
t.deepEqual(actual_rows, expected_rows, 'list not what I expected')
})
.catch((err) => {
t.fail(err)
})
})
.catch((err) => {
debug("FIND: %o", err)
t.fail(err)
throw err
})
)