UNPKG

1.94 kBJavaScriptView Raw
1const ssbKeys = require('ssb-keys')
2const cont = require('cont')
3const tape = require('tape')
4const u = require('./util')
5const pull = require('pull-stream')
6
7// create 3 feeds
8// add some of friend edges (follow, flag)
9// make sure the friends plugin analyzes correctly
10
11function liveFriends (ssbServer) {
12 const live = {}
13 pull(
14 ssbServer.friends.createFriendStream({ live: true, meta: true }),
15 pull.drain(function (friend) {
16 if (friend.sync) return
17 live[friend.id] = friend.hops
18 })
19 )
20 return live
21}
22
23const aliceKeys = ssbKeys.generate()
24
25const ssbServer = u.Server({
26 keys: aliceKeys
27})
28
29const alice = ssbServer.createFeed(aliceKeys)
30const bob = ssbServer.createFeed()
31const carol = ssbServer.createFeed()
32
33const live = liveFriends(ssbServer)
34
35tape('add and delete', function (t) {
36 cont.para([
37 alice.add({
38 type: 'contact',
39 contact: bob.id,
40 following: true,
41 flagged: true
42 }),
43 alice.add(u.follow(carol.id)),
44 bob.add(u.follow(alice.id)),
45 bob.add({
46 type: 'contact',
47 contact: carol.id,
48 following: false,
49 flagged: { reason: 'foo' }
50 }),
51 carol.add(u.follow(alice.id)),
52 alice.add({
53 type: 'contact',
54 contact: carol.id,
55 following: false,
56 flagged: true
57 }),
58 alice.add({
59 type: 'contact',
60 contact: bob.id,
61 following: true,
62 flagged: false
63 }),
64 bob.add(u.unfollow(carol.id))
65 ])(function () {
66 ssbServer.friends.hops(function (err, hops) {
67 if (err) throw err
68 t.deepEqual(live, hops)
69 t.end()
70 })
71 })
72})
73
74tape('createFriendStream after delete', function (t) {
75 pull(
76 ssbServer.friends.createFriendStream(),
77 pull.collect(function (err, ary) {
78 t.notOk(err)
79 t.equal(ary.length, 2)
80 t.deepEqual(ary.sort(), [alice.id, bob.id].sort())
81 t.end()
82 })
83 )
84})
85
86tape('cleanup', function (t) {
87 ssbServer.close()
88
89 t.end()
90})