git ssb

0+

mixmix / ssb-testing-guide



Tree: a683541f27c2757c560090b0fa816b37d947d42f

Files: a683541f27c2757c560090b0fa816b37d947d42f / intermediate / channelV3.test.js

2421 bytesRaw
1const test = require('tape')
2const Server = require('scuttle-testbot')
3const pull = require('pull-stream')
4
5// this test is the same except we're using the V3 view
6test('get a count of the number of posts to a channel', t => {
7 Server.use(require('./channelV3'))
8 const server = Server()
9
10 t.plan(1)
11
12 pull(
13 pull.values(['myco', 'ssb', 'economics', 'monkeys', 'pineapples', null, 'pineapples', undefined]),
14 pull.asyncMap(function (channel, cb) {
15 // write 5 messages to the database
16 server.publish({ type: 'post', channel, text: 'hello world' }, cb)
17 }),
18 pull.collect((err, msgs) => {
19 // use channel plugin to find out how many times each channel has been mentioned
20 server.channel.all((err, data) => {
21 t.deepEqual(data, { myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 })
22 server.close()
23 })
24 })
25 )
26})
27
28// this test is the same except we're using the V3 view
29test('get a count of how many times all channels have been mentioned', t => {
30 Server.use(require('./channelV3'))
31 const server = Server()
32
33 t.plan(1)
34
35 pull(
36 pull.values(['#myco', '#ssb', '#economics', '#monkeys', '#pineapples', null, '#pineapples', undefined]),
37 pull.asyncMap((channel, cb) => {
38 server.publish({ type: 'post', text: `hello world ${ channel }`, mentions: [{ link: channel }] }, cb)
39 }),
40 pull.collect((err, msgs) => {
41 server.channel.all((err, data) => {
42 t.deepEqual(data, { myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 })
43 server.close()
44 })
45 })
46 )
47})
48
49test('get a count of a particular channel mentions and omit duplicate mentions', t => {
50 Server.use(require('./channelV3'))
51 const server = Server()
52
53 t.plan(1)
54
55 pull(
56 pull.values([
57 { type: 'post', channel: '#myco', text: 'clathrus archerii', mentions: [{ link: '#myco' }, { link: '#mushrooms'}, { link: '#newzealand' }, { link: '#newzealand' }] },
58 { type: 'post', channel: '#newzealand', text: 'tongariro', mentions: [{ link: '#newzealand' }, { link: '#hiking' }] },
59 { type: 'post', channel: 'monkeys', text: 'always more monkeys OoooAHAHAHA', mentions: [{ link: '#apes' }] }
60 ]),
61 pull.asyncMap((post, cb) => {
62 server.publish(post, cb)
63 }),
64 pull.collect((err, msgs) => {
65 server.channel.count('newzealand', (err, count) => {
66 t.equal(count, 2)
67 server.close()
68 })
69 })
70 )
71})
72

Built with git-ssb-web