git ssb

0+

mixmix / ssb-testing-guide



Commit 87f62996e714588859e2a26acb9a43e07d2db238

rearrange folder structure

Kieran committed on 5/24/2018, 12:34:11 AM
Parent: a683541f27c2757c560090b0fa816b37d947d42f

Files changed

intermediate/channelV1.jsdeleted
intermediate/flumeview-reduce/channelV1.jsadded
intermediate/flumeview-reduce/channelV1.test.jsadded
intermediate/flumeview-reduce/channelV2.jsadded
intermediate/flumeview-reduce/channelV2.test.jsadded
intermediate/flumeview-reduce/channelV3.jsadded
intermediate/flumeview-reduce/channelV3.test.jsadded
intermediate/channelV1.test.jsdeleted
intermediate/channelV2.jsdeleted
intermediate/channelV2.test.jsdeleted
intermediate/channelV3.jsdeleted
intermediate/channelV3.test.jsdeleted
intermediate/channelV1.jsView
@@ -1,37 +1,0 @@
1-const flumeView = require('flumeview-reduce')
2-
3-const NAME = 'channel'
4-const VERSION = 1
5-
6-module.exports = {
7- name: NAME,
8- version: VERSION,
9- manifest: {
10- all: 'async'
11- },
12- init: function (server, config) {
13- const view = server._flumeUse(
14- NAME,
15- flumeView(VERSION, reduce, map, null, initialState())
16- )
17-
18- return {
19- all: view.get
20- }
21- }
22-}
23-
24-function map (msg) {
25- var content = msg.value.content
26- return content.channel
27-}
28-
29-// if map returns null or undefined, reduce is skipped
30-function reduce (accumulator, channel) {
31- accumulator[channel] = (accumulator[channel] || 0) + 1
32- return accumulator
33-}
34-
35-function initialState () {
36- return {}
37-}
intermediate/flumeview-reduce/channelV1.jsView
@@ -1,0 +1,37 @@
1 +const flumeView = require('flumeview-reduce')
2 +
3 +const NAME = 'channel'
4 +const VERSION = 1
5 +
6 +module.exports = {
7 + name: NAME,
8 + version: VERSION,
9 + manifest: {
10 + all: 'async'
11 + },
12 + init: function (server, config) {
13 + const view = server._flumeUse(
14 + NAME,
15 + flumeView(VERSION, reduce, map, null, initialState())
16 + )
17 +
18 + return {
19 + all: view.get
20 + }
21 + }
22 +}
23 +
24 +function map (msg) {
25 + var content = msg.value.content
26 + return content.channel
27 +}
28 +
29 +// if map returns null or undefined, reduce is skipped
30 +function reduce (accumulator, channel) {
31 + accumulator[channel] = (accumulator[channel] || 0) + 1
32 + return accumulator
33 +}
34 +
35 +function initialState () {
36 + return {}
37 +}
intermediate/flumeview-reduce/channelV1.test.jsView
@@ -1,0 +1,25 @@
1 +const test = require('tape')
2 +const Server = require('scuttle-testbot')
3 +const pull = require('pull-stream')
4 +
5 +test('get a count of the number of posts to a channel', t => {
6 + Server.use(require('./channelV1'))
7 + const server = Server()
8 +
9 + t.plan(1)
10 +
11 + pull(
12 + pull.values(['myco', 'ssb', 'economics', 'monkeys', 'pineapples', null, 'pineapples', undefined]),
13 + pull.asyncMap(function (channel, cb) {
14 + // write 5 messages to the database
15 + server.publish({ type: 'post', channel, text: 'hello world' }, cb)
16 + }),
17 + pull.collect((err, msgs) => {
18 + // use channel plugin to find out how many times each channel has been mentioned
19 + server.channel.all((err, data) => {
20 + t.deepEqual({ myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 }, data)
21 + server.close()
22 + })
23 + })
24 + )
25 +})
intermediate/flumeview-reduce/channelV2.jsView
@@ -1,0 +1,46 @@
1 +const flumeView = require('flumeview-reduce')
2 +
3 +const NAME = 'channel'
4 +const VERSION = 2
5 +
6 +module.exports = {
7 + name: NAME,
8 + version: VERSION,
9 + manifest: {
10 + all: 'async'
11 + },
12 + init: function (server, config) {
13 + const view = server._flumeUse(
14 + NAME,
15 + flumeView(VERSION, reduce, map, null, initialState())
16 + )
17 +
18 + return {
19 + all: view.get
20 + }
21 + }
22 +}
23 +
24 +function map (msg) {
25 + var content = msg.value.content
26 + var channelAttribute = content.channel
27 +
28 + var mentions = content.mentions || []
29 + var mentionedChannel = mentions
30 + .filter(mention => Boolean(mention.link))
31 + .filter(mention => mention.link.match(/^#/))
32 + .map(mention => mention.link.replace('#',''))
33 + .shift()
34 +
35 + return channelAttribute || mentionedChannel
36 +}
37 +
38 +// if map returns null or undefined, reduce is skipped
39 +function reduce (accumulator, channel) {
40 + accumulator[channel] = (accumulator[channel] || 0) + 1
41 + return accumulator
42 +}
43 +
44 +function initialState () {
45 + return {}
46 +}
intermediate/flumeview-reduce/channelV2.test.jsView
@@ -1,0 +1,47 @@
1 +const test = require('tape')
2 +const Server = require('scuttle-testbot')
3 +const pull = require('pull-stream')
4 +
5 +// This test is the same except we're using the V2 view
6 +test('get a count of the number of posts to a channel', t => {
7 + Server.use(require('./channelV2'))
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({ myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 }, data)
22 + server.close()
23 + })
24 + })
25 + )
26 +})
27 +
28 +test('get a count of how many times all channels have been mentioned', t => {
29 + Server.use(require('./channelV2'))
30 + const server = Server()
31 +
32 + t.plan(1)
33 +
34 + pull(
35 + pull.values(['#myco', '#ssb', '#economics', '#monkeys', '#pineapples', null, '#pineapples', undefined]),
36 + pull.asyncMap(function (channel, cb) {
37 + server.publish({ type: 'post', text: `hello world ${ channel }`, mentions: [{ link: channel }] }, cb)
38 + }),
39 + pull.collect((err, msgs) => {
40 + // use channel plugin to find out how many times each channel has been mentioned
41 + server.channel.all((err, data) => {
42 + t.deepEqual({ myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 }, data)
43 + server.close()
44 + })
45 + })
46 + )
47 +})
intermediate/flumeview-reduce/channelV3.jsView
@@ -1,0 +1,63 @@
1 +const flumeView = require('flumeview-reduce')
2 +
3 +const NAME = 'channel'
4 +const VERSION = 3
5 +
6 +module.exports = {
7 + name: NAME,
8 + version: VERSION,
9 + manifest: {
10 + all: 'async',
11 + count: 'async'
12 + },
13 + init: function (server, config) {
14 + // Our original view
15 + const view = server._flumeUse(
16 + NAME,
17 + flumeView(
18 + VERSION,
19 + (soFar, channels) => {
20 + // reduce
21 + channels.forEach(channel => {
22 + soFar[channel] = (soFar[channel] || 0) + 1
23 + })
24 + return soFar
25 + },
26 + (msg) => {
27 + // map
28 + var { content } = msg.value
29 + var mentions = [
30 + ...content.mentions || [],
31 + { link: content.channel }
32 + ]
33 + // Put content.channel in list, even if null / undefined
34 + channels = mentions
35 + // map to string
36 + .map(men => men.link)
37 + // remove falsey
38 + .filter(Boolean)
39 + // remove #
40 + .map(parseChannel)
41 +
42 + // remove duplicates and return array
43 + return Array.from(new Set(channels))
44 +
45 + function parseChannel (channel) {
46 + return channel.replace('#', '')
47 + }
48 + },
49 + null,
50 + {}
51 + )
52 + )
53 +
54 + return {
55 + all: view.get,
56 + count: (name, cb) => {
57 + view.get((err, data) => {
58 + cb(null, data[name])
59 + })
60 + }
61 + }
62 + }
63 +}
intermediate/flumeview-reduce/channelV3.test.jsView
@@ -1,0 +1,71 @@
1 +const test = require('tape')
2 +const Server = require('scuttle-testbot')
3 +const pull = require('pull-stream')
4 +
5 +// this test is the same except we're using the V3 view
6 +test('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
29 +test('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 +
49 +test('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 +})
intermediate/channelV1.test.jsView
@@ -1,25 +1,0 @@
1-const test = require('tape')
2-const Server = require('scuttle-testbot')
3-const pull = require('pull-stream')
4-
5-test('get a count of the number of posts to a channel', t => {
6- Server.use(require('./channelV1'))
7- const server = Server()
8-
9- t.plan(1)
10-
11- pull(
12- pull.values(['myco', 'ssb', 'economics', 'monkeys', 'pineapples', null, 'pineapples', undefined]),
13- pull.asyncMap(function (channel, cb) {
14- // write 5 messages to the database
15- server.publish({ type: 'post', channel, text: 'hello world' }, cb)
16- }),
17- pull.collect((err, msgs) => {
18- // use channel plugin to find out how many times each channel has been mentioned
19- server.channel.all((err, data) => {
20- t.deepEqual({ myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 }, data)
21- server.close()
22- })
23- })
24- )
25-})
intermediate/channelV2.jsView
@@ -1,46 +1,0 @@
1-const flumeView = require('flumeview-reduce')
2-
3-const NAME = 'channel'
4-const VERSION = 2
5-
6-module.exports = {
7- name: NAME,
8- version: VERSION,
9- manifest: {
10- all: 'async'
11- },
12- init: function (server, config) {
13- const view = server._flumeUse(
14- NAME,
15- flumeView(VERSION, reduce, map, null, initialState())
16- )
17-
18- return {
19- all: view.get
20- }
21- }
22-}
23-
24-function map (msg) {
25- var content = msg.value.content
26- var channelAttribute = content.channel
27-
28- var mentions = content.mentions || []
29- var mentionedChannel = mentions
30- .filter(mention => Boolean(mention.link))
31- .filter(mention => mention.link.match(/^#/))
32- .map(mention => mention.link.replace('#',''))
33- .shift()
34-
35- return channelAttribute || mentionedChannel
36-}
37-
38-// if map returns null or undefined, reduce is skipped
39-function reduce (accumulator, channel) {
40- accumulator[channel] = (accumulator[channel] || 0) + 1
41- return accumulator
42-}
43-
44-function initialState () {
45- return {}
46-}
intermediate/channelV2.test.jsView
@@ -1,47 +1,0 @@
1-const test = require('tape')
2-const Server = require('scuttle-testbot')
3-const pull = require('pull-stream')
4-
5-// This test is the same except we're using the V2 view
6-test('get a count of the number of posts to a channel', t => {
7- Server.use(require('./channelV2'))
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({ myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 }, data)
22- server.close()
23- })
24- })
25- )
26-})
27-
28-test('get a count of how many times all channels have been mentioned', t => {
29- Server.use(require('./channelV2'))
30- const server = Server()
31-
32- t.plan(1)
33-
34- pull(
35- pull.values(['#myco', '#ssb', '#economics', '#monkeys', '#pineapples', null, '#pineapples', undefined]),
36- pull.asyncMap(function (channel, cb) {
37- server.publish({ type: 'post', text: `hello world ${ channel }`, mentions: [{ link: channel }] }, cb)
38- }),
39- pull.collect((err, msgs) => {
40- // use channel plugin to find out how many times each channel has been mentioned
41- server.channel.all((err, data) => {
42- t.deepEqual({ myco: 1, ssb: 1, economics: 1, monkeys: 1, pineapples: 2 }, data)
43- server.close()
44- })
45- })
46- )
47-})
intermediate/channelV3.jsView
@@ -1,61 +1,0 @@
1-const flumeView = require('flumeview-reduce')
2-
3-const NAME = 'channel'
4-const VERSION = 3
5-
6-module.exports = {
7- name: NAME,
8- version: VERSION,
9- manifest: {
10- all: 'async',
11- count: 'async'
12- },
13- init: function (server, config) {
14- // Our original view
15- const view = server._flumeUse(
16- NAME,
17- flumeView(
18- VERSION,
19- (soFar, channels) => {
20- // reduce
21- channels.forEach(channel => {
22- soFar[channel] = (soFar[channel] || 0) + 1
23- })
24- return soFar
25- },
26- (msg) => {
27- // map
28- var content = msg.value.content
29- var mentions = content.mentions || []
30- // Put content.channel in list, even if null / undefined
31- mentions.push({ link: content.channel })
32- channels = mentions
33- // map to string
34- .map(men => men.link)
35- // remove falsey
36- .filter(Boolean)
37- // remove #
38- .map(parseChannel)
39-
40- // remove duplicates and return array
41- return Array.from(new Set(channels))
42-
43- function parseChannel (channel) {
44- return channel.replace('#', '')
45- }
46- },
47- null,
48- {}
49- )
50- )
51-
52- return {
53- all: view.get,
54- count: (name, cb) => {
55- view.get((err, data) => {
56- cb(null, data[name])
57- })
58- }
59- }
60- }
61-}
intermediate/channelV3.test.jsView
@@ -1,71 +1,0 @@
1-const test = require('tape')
2-const Server = require('scuttle-testbot')
3-const pull = require('pull-stream')
4-
5-// this test is the same except we're using the V3 view
6-test('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
29-test('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-
49-test('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-})

Built with git-ssb-web