Files: fa119a00e0a13307d66a09f8c482ae107ba31bdb / gathering / async / get.test.js
2921 bytesRaw
1 | const { group } = require('tape-plus') |
2 | const Server = require('../../lib/testbot') |
3 | const { isMsg } = require('ssb-ref') |
4 | const Scuttle = require('../../') |
5 | |
6 | group('gathering.async.get', test => { |
7 | var now = Date.now() |
8 | var server |
9 | var scuttle |
10 | |
11 | test.beforeEach(t => { |
12 | server = Server() |
13 | scuttle = Scuttle(server) |
14 | }) |
15 | test.afterEach(t => { |
16 | server.close() |
17 | }) |
18 | |
19 | test('gets document', (t, done) => { |
20 | setupGathering((err, gathering) => { |
21 | if (err) console.error(err) |
22 | |
23 | scuttle.gathering.async.get(gathering.key, (err, doc) => { |
24 | t.false(err, 'no error') |
25 | |
26 | t.true(isMsg(doc.key), 'valid key') |
27 | |
28 | t.equal(doc.title, 'ziva\'s birthday', 'has title') |
29 | t.deepEqual(doc.startDateTime, { epoch: now + 750, tz: 'Pacific/ Auckland' }, 'has edited time startDateTime') |
30 | t.equal(doc.location, 'our place in mirimar') |
31 | |
32 | t.equal(doc.description, '', 'unset String field returns empty string') |
33 | |
34 | t.deepEqual(doc.image, { link: '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' }, 'has single image') |
35 | t.deepEqual(doc.images, [ |
36 | { |
37 | link: '&l/Mr4CqSFYtCsrz3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256', |
38 | name: 'orange-grove-helpers.jpg', |
39 | size: 1049416, |
40 | type: 'image/jpeg' |
41 | }, |
42 | { link: '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' } |
43 | ], 'has all images added') |
44 | |
45 | t.deepEqual(doc.attendees, [ server.id ], 'shows me attending') |
46 | scuttle.attendee.async.publish(gathering.key, false, (err, attendee) => { |
47 | if (err) throw (err) |
48 | scuttle.gathering.async.get(gathering.key, (err, doc) => { |
49 | if (err) throw (err) |
50 | t.deepEqual(doc.attendees, [], 'shows me no longer attending') |
51 | |
52 | done() |
53 | }) |
54 | }) |
55 | }) |
56 | }) |
57 | }) |
58 | |
59 | // helper |
60 | function setupGathering (cb) { |
61 | var epoch = now + 5000 |
62 | |
63 | const initialGathering = { |
64 | title: 'ziva\'s birthday', |
65 | startDateTime: { |
66 | epoch, |
67 | tz: 'Pacific/ Auckland' |
68 | }, |
69 | image: { |
70 | link: '&l/Mr4CqSFYtCsrz3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256', |
71 | name: 'orange-grove-helpers.jpg', |
72 | size: 1049416, |
73 | type: 'image/jpeg' |
74 | } |
75 | } |
76 | |
77 | const anUpdate = { |
78 | startDateTime: { epoch: now + 750 }, |
79 | location: 'our place in mirimar', |
80 | image: { |
81 | 'link': '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' |
82 | } |
83 | } |
84 | |
85 | // publish gathering |
86 | scuttle.gathering.async.publish(initialGathering, (err, gathering) => { |
87 | if (err) return cb(err) |
88 | |
89 | // make an update |
90 | scuttle.update.async.publish(gathering.key, anUpdate, (err, update) => { |
91 | if (err) return cb(err) |
92 | |
93 | // attend it |
94 | scuttle.attendee.async.publish(gathering.key, (err, attendee) => { |
95 | if (err) return cb(err) |
96 | |
97 | cb(null, gathering) |
98 | }) |
99 | }) |
100 | }) |
101 | } |
102 | }) |
103 |
Built with git-ssb-web