1 | Chance = require('chance')
|
2 |
|
3 | chance = new Chance()
|
4 |
|
5 | clone = (o) -> JSON.parse JSON.stringify o
|
6 |
|
7 | doc = ->
|
8 | uid: chance.guid()
|
9 | name: chance.name
|
10 | middle_initial: true,
|
11 | prefix: true
|
12 | description: chance.sentence()
|
13 | address: chance.address()
|
14 |
|
15 | N = 42
|
16 |
|
17 | docs = (new Array(N)).fill(0).map -> doc()
|
18 | hits = docs.map (d) ->
|
19 | _id: d.uid
|
20 | _type: 'mytype'
|
21 | _index: 'myindex'
|
22 | _source: d
|
23 |
|
24 | c = 0
|
25 |
|
26 | reset = -> c = 0
|
27 |
|
28 | iter = ->
|
29 | c += 10
|
30 | clone hits.slice(c - 10, c)
|
31 |
|
32 | search = spy (opts, cb) -> reset(); setImmediate ->
|
33 | cb null, {_scroll_id:'123', hits:{total:N, hits:iter()}}
|
34 | scroll = spy (opts, cb) -> setImmediate ->
|
35 | cb null, {_scroll_id:'123', hits:{total:N, hits:iter()}}
|
36 | bulk = spy (opts, cb) -> Promise.resolve {}
|
37 |
|
38 | fn = -> {search, scroll, bulk}
|
39 | fn.docs = -> clone docs
|
40 |
|
41 | module.exports = fn
|