-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlist.spec.js
58 lines (39 loc) · 1.38 KB
/
list.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
/*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-list-test'
const couchdb = initCouchDb(CONFIG)
const test = initTest(couchdb, DB_NAME)
test('::list should list all of the documents in the ' +
'in the database by default', t =>
couchdb.then((connection) => {
Bluebird.all([
connection.create(DB_NAME, 'my-foo1', { test: 'Test', moo: 'Elsie' })
, connection.create(DB_NAME, 'my-foo2', { test: 'Test', moo: 'Clara' })
])
.then(() => connection.list(DB_NAME, {}))
.then((res) => res.body)
.then((list) => {
const expected_count = 2
const expected_rows = [
{ id: 'my-foo1', test: 'Test', moo: 'Elsie' }
, { id: 'my-foo2', test: 'Test', moo: 'Clara' }
]
const actual_rows = list
.rows
.map((x) => ({ id: x.doc._id, test: x.doc.test, moo: x.doc.moo }))
.filter((x) => 'Test' === x.test )
t.is(actual_rows.length, expected_count, 'list count is not 2')
t.deepEqual(actual_rows, expected_rows, 'list not what I expected')
})
.catch((err) => {
t.fail(err)
})
}).catch((err) => {
debug("LIST: %o", err)
t.fail(err)
throw err
})
)