git ssb

0+

mixmix / ssb-testing-guide



Tree: caa4a4b8f577c0181656d117489972a48ac3b438

Files: caa4a4b8f577c0181656d117489972a48ac3b438 / 2_singleuserpublishing.test.js

1058 bytesRaw
1const test = require('tape')
2const Server = require('scuttle-testbot')
3const pull = require('pull-stream')
4
5test('publish a message and get it back', t => {
6 var server = Server()
7
8 t.plan(2)
9
10 var content = {
11 type: "post",
12 text: "hello world"
13 }
14
15 server.publish(content, (err, msg) => {
16 t.equal(msg.value.content.type, 'post')
17 t.equal(msg.value.content.text, 'hello world')
18
19 // Make sure you close the server or tests will hang
20 server.close()
21 })
22})
23
24test('pull the message and compare with published', t => {
25 var server = Server()
26
27 t.plan(1)
28
29 pull(
30 server.createFeedStream({ live: true }),
31 pull.filter(msg => msg.sync !== true), // live streams emit { sync: true } when 'up to speed'
32 pull.take(1),
33 pull.drain(msg => {
34 t.deepEqual(msg.value.content, content)
35
36 // Make sure you close the server or tests will hang
37 server.close()
38 })
39 )
40
41 var content = {
42 type: "post",
43 text: "hello world"
44 }
45
46 server.publish(content, (err, msg) => {
47 // Must provide a callback
48 })
49})
50

Built with git-ssb-web