Commit 4250819350e538b6f5b1c63433e0b4b3f27ff6be
update block tests to use new obv based api
Dominic Tarr committed on 5/28/2017, 10:32:53 AMParent: e1e0ab885aaa57a0630e5ff36031bec1c3f845f4
Files changed
test/block.js | changed |
test/block2.js | changed |
test/block3.js | changed |
test/block.js | ||
---|---|---|
@@ -10,8 +10,16 @@ | ||
10 | 10 | .use(require('../plugins/replicate')) |
11 | 11 | |
12 | 12 | var toAddress = require('../lib/util').toAddress |
13 | 13 | |
14 | +function once (fn) { | |
15 | + var called = 0 | |
16 | + return function () { | |
17 | + if(called++) throw new Error('called :'+called+' times!') | |
18 | + return fn.apply(this, arguments) | |
19 | + } | |
20 | +} | |
21 | + | |
14 | 22 | // alice, bob, and carol all follow each other, |
15 | 23 | // but then bob offends alice, and she blocks him. |
16 | 24 | // this means that: |
17 | 25 | // |
@@ -35,16 +43,21 @@ | ||
35 | 43 | }) |
36 | 44 | |
37 | 45 | tape('alice blocks bob, and bob cannot connect to alice', function (t) { |
38 | 46 | |
47 | + console.log({ | |
48 | + alice: alice.id, | |
49 | + bob: bob.id, | |
50 | + carol: carol.id | |
51 | + }) | |
52 | + | |
39 | 53 | //in the beginning alice and bob follow each other |
40 | 54 | cont.para([ |
41 | 55 | cont(alice.publish)(u.follow(bob.id)), |
42 | 56 | cont(bob .publish)(u.follow(alice.id)), |
43 | 57 | cont(carol.publish)(u.follow(alice.id)) |
44 | 58 | ]) (function (err) { |
45 | 59 | if(err) throw err |
46 | - | |
47 | 60 | var n = 3, rpc |
48 | 61 | |
49 | 62 | bob.connect(alice.getAddress(), function (err, _rpc) { |
50 | 63 | if(err) throw err |
@@ -54,24 +67,23 @@ | ||
54 | 67 | }) |
55 | 68 | |
56 | 69 | //get the next messages that are replicated to alice and bob, |
57 | 70 | //and check that these are the correct follow messages. |
58 | - var bobCancel = bob.post(function (op) { | |
71 | + var bobCancel = bob.post(once(function (op) { | |
59 | 72 | console.log('BOB_POST', op) |
60 | 73 | //should be the alice's follow(bob) message. |
61 | - t.equal(op.value.author, alice.id) | |
62 | - t.equal(op.value.content.contact, bob.id) | |
74 | + t.equal(op.value.author, alice.id, 'bob expected message from alice') | |
75 | + t.equal(op.value.content.contact, bob.id, 'bob expected message to be about bob') | |
63 | 76 | next() |
64 | - }) | |
77 | + }), false) | |
65 | 78 | |
66 | - var aliceCancel = alice.post(function (op) { | |
79 | + var aliceCancel = alice.post(once(function (op) { | |
67 | 80 | console.log('ALICE_POST', op) |
68 | 81 | //should be the bob's follow(alice) message. |
69 | - t.equal(op.value.author, bob.id) | |
70 | - t.equal(op.value.content.contact, alice.id) | |
82 | + t.equal(op.value.author, bob.id, 'alice expected to receive a message from bob') | |
83 | + t.equal(op.value.content.contact, alice.id, 'alice expected received message to be about alice') | |
71 | 84 | next() |
72 | - }) | |
73 | - | |
85 | + }), false) | |
74 | 86 | function next () { |
75 | 87 | if(--n) return |
76 | 88 | |
77 | 89 | rpc.close(true, function () { |
@@ -82,68 +94,61 @@ | ||
82 | 94 | alice.publish(u.block(bob.id)) |
83 | 95 | (function (err) { |
84 | 96 | if(err) throw err |
85 | 97 | |
86 | - t.ok(alice.friends.get({source: alice.id, dest: bob.id, graph: 'flag'})) | |
98 | + alice.friends.get(null, function (err, g) { | |
99 | + if(err) throw err | |
100 | + t.equal(g[alice.id][bob.id], false) | |
87 | 101 | |
88 | - pull( | |
89 | - alice.links({ | |
90 | - source: alice.id, | |
91 | - dest: bob.id, | |
92 | - rel: 'contact', | |
93 | - values: true | |
94 | - }), | |
95 | - pull.filter(function (op) { | |
96 | - return op.value.content.flagged != null | |
97 | - }), | |
98 | - pull.collect(function (err, ary) { | |
99 | - if(err) throw err | |
100 | - console.log(ary) | |
101 | - t.ok(flagged = ary.pop().value.content.flagged, 'alice did block bob') | |
102 | + pull( | |
103 | + alice.links({ | |
104 | + source: alice.id, | |
105 | + dest: bob.id, | |
106 | + rel: 'contact', | |
107 | + values: true | |
108 | + }), | |
109 | + pull.filter(function (op) { | |
110 | + return op.value.content.flagged != null | |
111 | + }), | |
112 | + pull.collect(function (err, ary) { | |
113 | + if(err) throw err | |
114 | + console.log(ary) | |
115 | + t.ok(flagged = ary.pop().value.content.flagged, 'alice did block bob') | |
102 | 116 | |
103 | - //since bob is blocked, he should not be able to connect | |
104 | - bob.connect(alice.getAddress(), function (err, rpc) { | |
105 | - t.ok(err, 'bob is blocked, should fail to connect to alice') | |
117 | + //since bob is blocked, he should not be able to connect | |
118 | + bob.connect(alice.getAddress(), function (err, rpc) { | |
119 | + t.ok(err, 'bob is blocked, should fail to connect to alice') | |
106 | 120 | |
107 | 121 | |
108 | - carol.post(function (msg) { | |
109 | - console.log('CAROL RECV', msg, alice.id) | |
110 | - if(msg.author === alice.id) { | |
111 | - if(msg.sequence == 2) | |
112 | - t.end() | |
113 | - } | |
114 | - }) | |
122 | + carol.post(function (msg) { | |
123 | + console.log('CAROL RECV', msg, alice.id) | |
124 | + if(msg.author === alice.id) { | |
125 | + if(msg.sequence == 2) | |
126 | + t.end() | |
127 | + } | |
128 | + }) | |
115 | 129 | |
116 | - //but carol, should, because she is not blocked. | |
117 | - carol.connect(alice.getAddress(), function (err, rpc) { | |
118 | - if(err) throw err | |
119 | - console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id) | |
120 | -// pull( | |
121 | -// alice.createHistoryStream({id: alice.id, seq: 0}), | |
122 | -// pull.collect(console.log) | |
123 | -// ) | |
130 | + //but carol, should, because she is not blocked. | |
131 | + carol.connect(alice.getAddress(), function (err, rpc) { | |
132 | + if(err) throw err | |
133 | + console.log('CAROL CONNECTED TO ALICE', carol.id, alice.id) | |
134 | + rpc.on('closed', function () { | |
135 | + pull( | |
136 | + carol.createHistoryStream({id: alice.id, seq: 0, live: false}), | |
137 | + pull.collect(function (err, ary) { | |
138 | + if(err) throw err | |
124 | 139 | |
125 | - rpc.on('closed', function () { | |
126 | - pull( | |
127 | - carol.createHistoryStream({id: alice.id, seq: 0, live: false}), | |
128 | - pull.collect(function (err, ary) { | |
129 | - if(err) throw err | |
130 | - | |
131 | - t.ok(ary.length, 'carol replicated data from alice') | |
132 | - console.log(alice.id, carol.id, err, ary) | |
133 | - t.end() | |
134 | - }) | |
135 | - ) | |
140 | + t.ok(ary.length, 'carol replicated data from alice') | |
141 | + console.log(alice.id, carol.id, err, ary) | |
142 | + t.end() | |
143 | + }) | |
144 | + ) | |
145 | + }) | |
136 | 146 | }) |
137 | 147 | }) |
138 | -// carol.once('replicate:finish', function (vclock) { | |
139 | -// t.equal(vclock[alice.id], 2) | |
140 | -// //in next test, bob connects to carol... | |
141 | -// t.end() | |
142 | -// }) | |
143 | 148 | }) |
144 | - }) | |
145 | - ) | |
149 | + ) | |
150 | + }) | |
146 | 151 | }) |
147 | 152 | }) |
148 | 153 | } |
149 | 154 | }) |
@@ -177,7 +182,4 @@ | ||
177 | 182 | |
178 | 183 | |
179 | 184 | |
180 | 185 | |
181 | - | |
182 | - | |
183 | - |
Built with git-ssb-web