-
Notifications
You must be signed in to change notification settings - Fork 75
/
latest.js
58 lines (52 loc) · 1.33 KB
/
latest.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
'use strict'
var tape = require('tape')
var pull = require('pull-stream')
var cont = require('cont')
var createSSB = require('./util/create-ssb')
var db = createSSB('test-ssb-latest')
var alice = db.createFeed()
var bob = db.createFeed()
var carol = db.createFeed()
var start = Date.now()
// LEGACY: uses feed.add as a continuable
tape('latest (empty)', function (t) {
cont.para([
])(function (err) {
if (err) throw err
pull(
db.latest(),
pull.collect(function (err, ary) {
if (err) throw err
t.equal(ary.length, 0)
t.end()
}))
})
})
tape('latest', function (t) {
cont.para([
cont.to(alice.add)({ type: 'post', text: 'hello' }),
cont.to(bob.add)({ type: 'post', text: 'hello' }),
cont.to(carol.add)({ type: 'post', text: 'hello' })
])(function (err) {
if (err) throw err
var end = Date.now()
pull(
db.latest(),
pull.collect(function (err, ary) {
if (err) throw err
t.equal(ary.length, 3)
var n = ary.map(function (v) {
t.equal(v.sequence, 1)
t.ok(v.ts >= start)
t.ok(v.ts <= end)
return v.id
})
t.deepEqual(n.sort(), [alice.id, bob.id, carol.id].sort())
db.close(err => {
t.error(err, 'ssb.close - latest')
t.end()
})
})
)
})
})