git ssb

3+

arj / patchbook



Tree: 74ba75f717d9bffcc0ea0b128ef9e0b0f02593c3

Files: 74ba75f717d9bffcc0ea0b128ef9e0b0f02593c3 / test / write.js

1908 bytesRaw
1var tape = require('tape')
2var pull = require('pull-stream')
3var through = require('pull-through')
4var ssbKeys = require('ssb-keys')
5
6var createSbot = require('scuttlebot')
7 .use(require('scuttlebot/plugins/master'))
8
9var db = require('../db.js')
10
11const common = { title: 'The moon is a harsh mistress', authors: 'Robert A. Heinlein' }
12const subjective = { rating: 5, 'rating-type': 'stars', read: Date.now() }
13
14function getSbot()
15{
16 return createSbot({
17 temp: 'test-write' + Math.random(),
18 keys: ssbKeys.generate()
19 })
20}
21
22tape('simple create', function (t) {
23 var sbot = getSbot()
24
25 var bookDB = db.bookDB(sbot)
26 bookDB.create(common, subjective, (err, msg) => {
27 pull(
28 sbot.messagesByType({ type: "bookclub", fillCache: true, keys: false }),
29 pull.collect((err, data) => {
30 t.deepEqual(data[0].content.common, common, "message correctly stored in database")
31 t.deepEqual(data[0].content.subjective, subjective, "message correctly stored in database")
32 t.end()
33 sbot.close()
34 })
35 )
36 })
37})
38
39tape('simple amend', function (t) {
40 var sbot = getSbot()
41
42 var bookDB = db.bookDB(sbot)
43 bookDB.create(common, subjective, (err, msg) => {
44 const newRating = { rating: 4 }
45 bookDB.amend(msg.key, null, newRating, (err, msg) => {
46 const newAuthor = { authors: "El gringo" }
47 const readInfo = { shelves: "read", rating: 4.5, ratingType: "stars" }
48 bookDB.amend(msg.key, newAuthor, readInfo, (err, msg) => {
49 bookDB.getAll(books => {
50 t.deepEqual(books[0].common, Object.assign(common, newAuthor), "book common amended correctly")
51 t.deepEqual(books[0].subjective[msg.value.author],
52 Object.assign(Object.assign(subjective, newRating), readInfo),
53 "book subjective updated correctly")
54 t.end()
55 sbot.close()
56 })
57 })
58 })
59 })
60})
61

Built with git-ssb-web