-
Notifications
You must be signed in to change notification settings - Fork 75
/
create-sequence-stream.js
50 lines (38 loc) · 1.12 KB
/
create-sequence-stream.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
const obv = require('obv')
const pull = require('pull-stream')
const test = require('tape')
const ssb = require('../').init({}, { temp: true })
test('createSequenceStream (initial sequence numbers)', (t) => {
const since = obv()
pull(
ssb.createSequenceStream(),
pull.drain(since.set)
)
since.once((val) => {
t.equal(val, -1, 'since has correct init value')
})
ssb.publish({ type: 'test' }, (err, publishedMessage) => {
t.error(err, 'publish() success')
t.equal(since.value, 0, 'since is incremented')
t.end()
})
})
test('createSequenceStream (resume sequence stream later)', (t) => {
const since = obv()
pull(
ssb.createSequenceStream(),
pull.drain(since.set)
)
since.once((val) => {
t.equal(val, 0, 'since has correct init value')
})
ssb.publish({ type: 'test' }, (err, publishedMessage) => {
t.error(err, 'publish() success')
ssb.get(since.value, (err, foundMessage) => {
t.error(err, 'get() success')
t.ok(since.value > 1, 'since is incremented')
t.deepEqual(foundMessage, publishedMessage, 'sequence number works')
t.end()
})
})
})