git ssb

2+

Dominic / ssb-client



Tree: 07198b454eadad3109f5692b847cb5c3b4679a41

Files: 07198b454eadad3109f5692b847cb5c3b4679a41 / test / index.js

2120 bytesRaw
1var scuttlebot = require('scuttlebot')
2var ssbkeys = require('ssb-keys')
3var schemas = require('ssb-msg-schemas')
4var tape = require('tape')
5var ssbclient = require('../index')
6
7function setupTest () {
8 var db = require('level-sublevel/bytewise')(require('levelup')('/testdb', { db: require('memdown'), keyEncoding: 'json', valueEncoding: 'json' }))
9 var ssb = require('secure-scuttlebutt')(db, require('secure-scuttlebutt/defaults'))
10 var server = scuttlebot({ port: 45451, host: 'localhost' }, ssb, ssb.createFeed()).use(require('scuttlebot/plugins/logging'))
11
12 var keys = ssbkeys.generate()
13 var client = ssbclient({ port: 45451, host: 'localhost' })
14 client.connect(iferr)
15 client.auth(ssbkeys.createAuth(keys), iferr)
16
17 return {
18 server: server,
19 client: client,
20 keys: keys
21 }
22}
23
24function iferr (err) {
25 if (err)
26 throw err
27}
28
29tape('add messages', function (t) {
30
31 var env = setupTest()
32 var feed = env.client.createFeed(env.keys)
33
34 feed.add({type: 'post', text: 'hello'}, function (err, data) {
35 iferr(err)
36 t.equal(data.value.content.text, 'hello')
37 console.log(data)
38 env.client.close(function() {
39 env.server.close()
40 t.end()
41 })
42 })
43})
44
45
46tape('setup aliases', function (t) {
47
48 var env = setupTest()
49 var feed = env.client.createFeed(env.keys)
50
51 env.client.whoami(function (err, user) {
52 iferr(err)
53 console.log('user', user)
54
55 schemas.getContact(env.client, { by: feed.id, for: user.id }, function (err, contact) {
56 iferr(err)
57 console.log('contact', contact)
58 t.equal(Object.keys(contact).length, 0)
59
60 schemas.addContact(feed, user.id, { alias: true, role: 'user' }, function (err, msg) {
61 iferr(err)
62 console.log('added msg', msg)
63
64 schemas.getContact(env.client, { by: feed.id, for: user.id }, function (err, contact) {
65 iferr(err)
66 console.log('contact', contact)
67 t.equal(contact.alias, true)
68 t.equal(contact.role, 'user')
69
70 env.client.close(function() {
71 env.server.close()
72 t.end()
73 })
74 })
75 })
76 })
77 })
78})
79

Built with git-ssb-web