UNPKG

2.41 kBJavaScriptView Raw
1const tape = require('tape')
2const { Server } = require('./util')
3
4const feedId = '@th3J6gjmDOBt77SRX1EFFWY0aH2Wagn21iUZViZFFxk=.ed25519'
5
6tape('follow', t => {
7 const sbot = Server({ tribes: true })
8
9 /* FOLLOW */
10 sbot.friends.follow(feedId, {}, (err, msg) => {
11 if (err) throw err
12
13 // NOTE get here just to confirm recps: undefined not present
14 sbot.get(msg.key, (_, value) => {
15 t.deepEqual(
16 value.content,
17 {
18 type: 'contact',
19 contact: feedId,
20 following: true
21 },
22 'publishes a follow message!'
23 )
24
25 /* UNFOLLOW */
26 sbot.friends.follow(feedId, { state: false }, (err, msg) => {
27 if (err) throw err
28
29 t.deepEqual(
30 msg.value.content,
31 {
32 type: 'contact',
33 contact: feedId,
34 following: false,
35 recps: undefined
36 },
37 'publishes a unfollow message!'
38 )
39
40 /* PRIVATE FOLLOW */
41 sbot.friends.follow(feedId, { recps: [sbot.id] }, (err, msg) => {
42 if (err) throw err
43 t.match(msg.value.content, /box\d$/, 'publishes a private follow')
44
45 sbot.close(t.end)
46 })
47 })
48 })
49 })
50})
51
52tape('block', t => {
53 const sbot = Server({ tribes: true })
54
55 /* BLOCK */
56 sbot.friends.block(feedId, {}, (err, msg) => {
57 if (err) throw err
58
59 // NOTE get here just to confirm recps: undefined not present
60 sbot.get(msg.key, (_, value) => {
61 t.deepEqual(
62 value.content,
63 {
64 type: 'contact',
65 contact: feedId,
66 blocking: true
67 },
68 'publishes a block message!'
69 )
70
71 /* UNBLOCK */
72 const opts = {
73 state: false,
74 reason: 'we talked in person'
75 }
76 sbot.friends.block(feedId, opts, (err, msg) => {
77 if (err) throw err
78
79 t.deepEqual(
80 msg.value.content,
81 {
82 type: 'contact',
83 contact: feedId,
84 blocking: false,
85 reason: 'we talked in person',
86 recps: undefined
87 },
88 'publishes an unblock message!'
89 )
90
91 /* PRIVATE BLOCK */
92 sbot.friends.block(feedId, { recps: [sbot.id] }, (err, msg) => {
93 if (err) throw err
94 t.match(msg.value.content, /box\d$/, 'publishes a private block')
95
96 sbot.close(t.end)
97 })
98 })
99 })
100 })
101})