1 | const tape = require('tape')
|
2 | const { Server } = require('./util')
|
3 |
|
4 | const feedId = '@th3J6gjmDOBt77SRX1EFFWY0aH2Wagn21iUZViZFFxk=.ed25519'
|
5 |
|
6 | tape('follow', t => {
|
7 | const sbot = Server({ tribes: true })
|
8 |
|
9 |
|
10 | sbot.friends.follow(feedId, {}, (err, msg) => {
|
11 | if (err) throw err
|
12 |
|
13 |
|
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 |
|
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 |
|
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 |
|
52 | tape('block', t => {
|
53 | const sbot = Server({ tribes: true })
|
54 |
|
55 |
|
56 | sbot.friends.block(feedId, {}, (err, msg) => {
|
57 | if (err) throw err
|
58 |
|
59 |
|
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 |
|
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 |
|
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 | })
|