git ssb

0+

Piet / ssb-loomio



Commit ff7663e73e7aedeb75242d658e91bb048df0253f

test common requirements for polls (e.g. title)

mix irving committed on 3/1/2018, 4:35:11 AM
Parent: 6736253e48a68510bc7290bfd2043b69e2643d0a

Files changed

README.mdchanged
poll/schema/poll.jschanged
poll/sync/chooseOne.jschanged
poll/sync/poll.jschanged
test/poll/sync/chooseOne.test.jschanged
test/poll/sync/isPoll.test.jsadded
README.mdView
@@ -58,11 +58,11 @@
5858
5959 where `opts` is an object of form:
6060 ```js
6161 {
62- title: String, // (required)
63- choices: Array, // (required)
64- text: String,
62 + title: String, // required
63 + choices: Array, // required
64 + body: String,
6565 }
6666 ```
6767 and `cb` is a callback of signature `(err, newPollMsg)`
6868
@@ -81,10 +81,11 @@
8181 ```
8282 {
8383 type: 'poll', // required
8484 pollType: oneOf:[dot, proposal, score] , // required
85- text: String, // required
86- mentions, //optional
85 + title: String, // required
86 + body: String,
87 + mentions,
8788 }
8889
8990 ```
9091
poll/schema/poll.jsView
@@ -7,9 +7,9 @@
77
88 const schema = {
99 $schema: 'http://json-schema.org/schema#',
1010 type: 'object',
11- required: ['type', 'pollDetails'],
11 + required: ['type', 'pollDetails', 'title'],
1212 properties: {
1313 version: {
1414 type: 'string',
1515 pattern: '^0.1.0$'
@@ -27,9 +27,10 @@
2727 // { $ref: '#/definitions/pollDetails/rsvp'},
2828 // { $ref: '#/definitions/pollDetails/meeting'},
2929 ]
3030 },
31- text: { type: 'string' },
31 + title: { type: 'string' },
32 + body: { type: 'string' },
3233 mentions: {
3334 oneOf: [
3435 { type: 'null' },
3536 {
poll/sync/chooseOne.jsView
@@ -1,15 +1,15 @@
11 const Poll = require('./poll')
22 const { chooseOneType } = require('../types')
33
4-function ChooseOne ({ choices, title, text, channel, recps, mentions }) {
4 +function ChooseOne ({ choices, title, body, channel, recps, mentions }) {
55 return Poll({
66 pollDetails: {
77 choices,
88 type: chooseOneType
99 },
10- text,
1110 title,
11 + body,
1212 channel,
1313 recps,
1414 mentions
1515 })
poll/sync/poll.jsView
@@ -1,8 +1,8 @@
11 // var { link } = require('ssb-msg-schemas/util')
22
3-function Poll ({ pollDetails, title, text, channel, recps, mentions }) {
4- var content = { type: 'poll', pollDetails, title, text }
3 +function Poll ({ pollDetails, title, body, channel, recps, mentions }) {
4 + var content = { type: 'poll', pollDetails, title, body }
55
66 // if (root) {
77 // root = link(root)
88 // if (!root) { throw new Error('root is not a valid link') }
test/poll/sync/chooseOne.test.jsView
@@ -3,22 +3,22 @@
33 const isPoll = require('../../../isPoll')
44
55 test('ChooseOne', function (t) {
66 var validPoll = ChooseOne({choices: [1, 2, 'three'], title: 'how many food'})
7- t.ok(isPoll(validPoll), 'simple')
7 + t.true(isPoll(validPoll), 'simple')
88
99 var fullPollMsg = {
1010 key: '%somekey',
1111 value: {
1212 content: validPoll
1313 }
1414 }
15- t.ok(isPoll(fullPollMsg), 'simple (full msg)')
15 + t.true(isPoll(fullPollMsg), 'simple (full msg)')
1616 // NOTE - we might want an isChooseOnePoll in future
17- // t.ok(isChooseOnePoll(fullPollMsg), 'simple (full msg)')
17 + // t.true(isChooseOnePoll(fullPollMsg), 'simple (full msg)')
1818
1919 var missingTitle = ChooseOne({choices: 'how'})
20- t.notOk(isPoll(missingTitle), 'only one choice => invalid')
21- t.ok(isPoll.errors, 'missing title => has errors')
20 + t.false(isPoll(missingTitle), 'only one choice => invalid')
21 + t.true(isPoll.errors, 'missing title => has errors')
2222
2323 t.end()
2424 })
test/poll/sync/isPoll.test.jsView
@@ -1,0 +1,21 @@
1 +const test = require('tape')
2 +const ChooseOne = require('../../../poll/sync/chooseOne')
3 +const isPoll = require('../../../isPoll')
4 +
5 +// this is for testing the attributes that are required for all polls
6 +
7 +test('Poll - common requirements', function (t) {
8 + var missingTitle = ChooseOne({
9 + choices: [1, 2, 'three']
10 + })
11 + t.false(isPoll(missingTitle), 'needs title')
12 +
13 + var missingDetails = {
14 + type: 'poll',
15 + pollDetails: undefined,
16 + title: 'how many food'
17 + }
18 + t.false(isPoll(missingDetails), 'missing details')
19 +
20 + t.end()
21 +})

Built with git-ssb-web