git ssb

3+

arj / patchbook



Tree: 93aed91e8e392b4b011fbacc5cccc010522e986d

Files: 93aed91e8e392b4b011fbacc5cccc010522e986d / test / write.js

1855 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, 'ratingType': '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 db.create(sbot, common, subjective, (err, msg) => {
26 pull(
27 sbot.messagesByType({ type: "bookclub", fillCache: true, keys: false }),
28 pull.collect((err, data) => {
29 t.deepEqual(data[0].content.common, common, "message correctly stored in database")
30 t.deepEqual(data[0].content.subjective, subjective, "message correctly stored in database")
31 t.end()
32 sbot.close()
33 })
34 )
35 })
36})
37
38tape('simple amend', function (t) {
39 var sbot = getSbot()
40
41 db.create(sbot, common, subjective, (err, msg) => {
42 const newRating = { rating: 4 }
43 db.amend(sbot, msg.key, null, newRating, (err, msg) => {
44 const newAuthor = { authors: "El gringo" }
45 const readInfo = { shelves: "read", rating: 4.5, ratingType: "stars" }
46 db.amend(sbot, msg.key, newAuthor, readInfo, (err, msg) => {
47 db.getAll(sbot, books => {
48 t.deepEqual(books[0].common, Object.assign(common, newAuthor), "book common amended correctly")
49 t.deepEqual(books[0].subjective[msg.value.author],
50 Object.assign(Object.assign(subjective, newRating), readInfo),
51 "book subjective updated correctly")
52 t.end()
53 sbot.close()
54 })
55 })
56 })
57 })
58})
59

Built with git-ssb-web