Files: 5f4e5cc3e56c96ddb795f9c1966bc83775100b01 / test / add.js
1975 bytesRaw
1 | |
2 | var tape = require('tape') |
3 | var pull = require('pull-stream') |
4 | var crypto = require('crypto') |
5 | |
6 | var createSSB = require('./util') |
7 | |
8 | module.exports = function (opts) { |
9 | var ssb = createSSB('test-ssb-feed', {}) |
10 | var ssb2 = createSSB('test-ssb-feed2', {}) |
11 | |
12 | tape('add invalid message', function (t) { |
13 | ssb.add({}, function (err) { |
14 | t.ok(err) |
15 | t.end() |
16 | }) |
17 | }) |
18 | |
19 | tape('add null message', function (t) { |
20 | ssb.add(null, function (err) { |
21 | t.ok(err) |
22 | t.end() |
23 | }) |
24 | }) |
25 | tape('add okay message', function (t) { |
26 | var f = ssb.createFeed() |
27 | |
28 | f.add({ type: 'okay' }, function (err, msg, key) { |
29 | if (err) throw err |
30 | console.log(msg, key) |
31 | ssb.get(msg.key, function (err, _msg) { |
32 | if (err) throw err |
33 | |
34 | t.deepEqual(_msg, msg.value) |
35 | f.add({ type: 'wtf' }, function (err, msg) { |
36 | if (err) throw err |
37 | console.log(msg) |
38 | ssb.get(msg.key, function (err, _msg) { |
39 | if (err) throw err |
40 | t.deepEqual(_msg, msg.value) |
41 | t.end() |
42 | }) |
43 | }) |
44 | }) |
45 | }) |
46 | }) |
47 | |
48 | tape('log', function (t) { |
49 | pull(ssb.createLogStream({ keys: true, values: true }), pull.collect(function (err, ary) { |
50 | console.log(err, ary) |
51 | if (err) throw err |
52 | console.log(ary) |
53 | t.equal(ary.length, 2) |
54 | t.end() |
55 | })) |
56 | }) |
57 | |
58 | tape('log', function (t) { |
59 | pull( |
60 | ssb.createLogStream({ keys: false, values: true }), |
61 | ssb2.createWriteStream(function (err, ary) { |
62 | if (err) throw err |
63 | t.end() |
64 | }) |
65 | ) |
66 | }) |
67 | |
68 | tape('sign-cap', function (t) { |
69 | var opts = { caps: { sign: crypto.randomBytes(32).toString('base64') } } |
70 | var ssb = createSSB('test-ssb-sign-cap', opts) |
71 | ssb.createFeed().add({ type: 'test', options: opts }, function (err, msg) { |
72 | if (err) throw err |
73 | console.log(msg) |
74 | t.deepEqual(msg.value.content.options, opts) |
75 | t.end() |
76 | }) |
77 | }) |
78 | } |
79 | |
80 | if (!module.parent) { module.exports({}) } |
81 |
Built with git-ssb-web