Files: 7c528349577470dee18f77f63097c8b28f7825fa / gathering / async / get.test.js
2562 bytesRaw
1 | const { group } = require('tape-plus') |
2 | const Server = require('../../lib/testbot') |
3 | const { isMsg } = require('ssb-ref') |
4 | const { isGathering } = require('ssb-gathering-schema') |
5 | const Scuttle = require('../../') |
6 | |
7 | group('gathering.async.get', test => { |
8 | var now = Date.now() |
9 | var server |
10 | var scuttle |
11 | |
12 | test.beforeEach(t => { |
13 | server = Server() |
14 | scuttle = Scuttle(server) |
15 | }) |
16 | test.afterEach(t => { |
17 | server.close() |
18 | }) |
19 | |
20 | test('gets document', (t, done) => { |
21 | setupGathering((err, gathering) => { |
22 | if (err) console.error(err) |
23 | |
24 | scuttle.gathering.async.get(gathering.key, (err, doc) => { |
25 | t.false(err, 'no error') |
26 | |
27 | t.true(isMsg(doc.key), 'valid key') |
28 | t.true(isGathering(doc.value), 'valid gathering value') |
29 | |
30 | t.equal(doc.title, 'ziva\'s birthday', 'has title') |
31 | t.deepEqual(doc.startDateTime, { epoch: now + 750, tz: 'Pacific/ Auckland' }, 'has edited time startDateTime') |
32 | t.equal(doc.location, 'our place in mirimar') |
33 | t.deepEqual(doc.image, { link: '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' }, 'has single image') |
34 | |
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 | done() |
46 | }) |
47 | }) |
48 | }) |
49 | |
50 | // helper |
51 | function setupGathering (cb) { |
52 | var epoch = now + 5000 |
53 | |
54 | // publish gathering |
55 | const opts = { |
56 | title: 'ziva\'s birthday', |
57 | startDateTime: { |
58 | epoch, |
59 | tz: 'Pacific/ Auckland' |
60 | }, |
61 | image: { |
62 | link: '&l/Mr4CqSFYtCsrz3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256', |
63 | name: 'orange-grove-helpers.jpg', |
64 | size: 1049416, |
65 | type: 'image/jpeg' |
66 | } |
67 | } |
68 | scuttle.gathering.async.publish(opts, (err, gathering) => { |
69 | if (err) return cb(err) |
70 | |
71 | // make an update |
72 | epoch = now + 750 |
73 | const opts = { |
74 | startDateTime: { epoch }, |
75 | location: 'our place in mirimar', |
76 | image: { |
77 | 'link': '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' |
78 | } |
79 | } |
80 | scuttle.update.async.publish(gathering.key, opts, (err, update) => { |
81 | if (err) return cb(err) |
82 | |
83 | // attend it |
84 | scuttle.attendee.async.publish(gathering.key, (err, attendee) => { |
85 | if (err) return cb(err) |
86 | |
87 | cb(null, gathering) |
88 | }) |
89 | }) |
90 | }) |
91 | } |
92 | }) |
93 |
Built with git-ssb-web