UNPKG

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