Files: 93aed91e8e392b4b011fbacc5cccc010522e986d / test / write.js
1855 bytesRaw
1 | var tape = require('tape') |
2 | var pull = require('pull-stream') |
3 | var through = require('pull-through') |
4 | var ssbKeys = require('ssb-keys') |
5 | |
6 | var createSbot = require('scuttlebot') |
7 | .use(require('scuttlebot/plugins/master')) |
8 | |
9 | var db = require('../db.js') |
10 | |
11 | const common = { title: 'The moon is a harsh mistress', authors: 'Robert A. Heinlein' } |
12 | const subjective = { rating: 5, 'ratingType': 'stars', read: Date.now() } |
13 | |
14 | function getSbot() |
15 | { |
16 | return createSbot({ |
17 | temp: 'test-write' + Math.random(), |
18 | keys: ssbKeys.generate() |
19 | }) |
20 | } |
21 | |
22 | tape('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 | |
38 | tape('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