git ssb

0+

Piet / ssb-loomio



Commit 0e0922a38a178fc20c0532642828075f0de37a72

add closesAt requirement on polls

mix irving committed on 3/1/2018, 5:23:35 AM
Parent: ff7663e73e7aedeb75242d658e91bb048df0253f

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.jschanged
README.mdView
@@ -76,48 +76,56 @@
7676 ```
7777
7878 ## Schemas
7979
80 +### Poll
81 +
8082 Poll message content
81-```
83 +```js
8284 {
83- type: 'poll', // required
84- pollType: oneOf:[dot, proposal, score] , // required
85- title: String, // required
86- body: String,
85 + type: 'poll', // required
86 + pollDetails: PollDetails // required
87 + title: String, // required
88 + closesAt: Integer // required
89 + body: String,
90 + channel,
8791 mentions,
92 + recps
8893 }
8994
9095 ```
9196
92-Dot vote pollType
93-```
97 +Where `PollDetails` is an object which has the details needed for each type of poll: Dot, Proposal, Score
98 +
99 +Dot vote PollDetails
100 +```js
94101 {
95102 type: 'dot', // required
96103 maxStanceScore: 'Integer >= 0', // required
97104 maxChoiceScore: 'Integer >= 0', //optional
98105 choices: Array, // required
99106 }
100107 ```
101108
102-Proposal pollType
103-```
109 +Proposal PollDetails
110 +```js
104111 {
105112 type: 'proposal', // required
106113 proposal: String, // required
107114 }
108115 ```
109116
110-Score pollType
111-```
117 +Score PollDetails
118 +```js
112119 {
113120 type: 'score', // required
114121 maxChoiceScore: 'Integer >= 0', //required
115122 choices: Array, // required
116123 }
117124 ```
118125
119-Position
126 +### Position
127 +
120128 ```
121129
122130 ```
123131
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', 'title'],
11 + required: ['type', 'pollDetails', 'title', 'closesAt'],
1212 properties: {
1313 version: {
1414 type: 'string',
1515 pattern: '^0.1.0$'
@@ -28,8 +28,9 @@
2828 // { $ref: '#/definitions/pollDetails/meeting'},
2929 ]
3030 },
3131 title: { type: 'string' },
32 + closesAt: { type: 'integer' },
3233 body: { type: 'string' },
3334 mentions: {
3435 oneOf: [
3536 { type: 'null' },
poll/sync/chooseOne.jsView
@@ -1,14 +1,15 @@
11 const Poll = require('./poll')
22 const { chooseOneType } = require('../types')
33
4-function ChooseOne ({ choices, title, body, channel, recps, mentions }) {
4 +function ChooseOne ({ choices, title, closesAt, body, channel, recps, mentions }) {
55 return Poll({
66 pollDetails: {
77 choices,
88 type: chooseOneType
99 },
1010 title,
11 + closesAt,
1112 body,
1213 channel,
1314 recps,
1415 mentions
poll/sync/poll.jsView
@@ -1,9 +1,11 @@
11 // var { link } = require('ssb-msg-schemas/util')
22
3-function Poll ({ pollDetails, title, body, channel, recps, mentions }) {
4- var content = { type: 'poll', pollDetails, title, body }
3 +function Poll ({ pollDetails, title, closesAt, body, channel, recps, mentions }) {
4 + var content = { type: 'poll', pollDetails, title, closesAt }
55
6 + if (body) content.body = body
7 +
68 // if (root) {
79 // root = link(root)
810 // if (!root) { throw new Error('root is not a valid link') }
911 // content.root = root
test/poll/sync/chooseOne.test.jsView
@@ -2,9 +2,13 @@
22 const ChooseOne = require('../../../poll/sync/chooseOne')
33 const isPoll = require('../../../isPoll')
44
55 test('ChooseOne', function (t) {
6- var validPoll = ChooseOne({choices: [1, 2, 'three'], title: 'how many food'})
6 + var validPoll = ChooseOne({
7 + choices: [1, 2, 'three'],
8 + title: 'how many food',
9 + closesAt: Date.now()
10 + })
711 t.true(isPoll(validPoll), 'simple')
812
913 var fullPollMsg = {
1014 key: '%somekey',
@@ -15,10 +19,6 @@
1519 t.true(isPoll(fullPollMsg), 'simple (full msg)')
1620 // NOTE - we might want an isChooseOnePoll in future
1721 // t.true(isChooseOnePoll(fullPollMsg), 'simple (full msg)')
1822
19- var missingTitle = ChooseOne({choices: 'how'})
20- t.false(isPoll(missingTitle), 'only one choice => invalid')
21- t.true(isPoll.errors, 'missing title => has errors')
22-
2323 t.end()
2424 })
test/poll/sync/isPoll.test.jsView
@@ -5,17 +5,26 @@
55 // this is for testing the attributes that are required for all polls
66
77 test('Poll - common requirements', function (t) {
88 var missingTitle = ChooseOne({
9- choices: [1, 2, 'three']
9 + choices: [1, 2, 'three'],
10 + closesAt: Date.now()
1011 })
1112 t.false(isPoll(missingTitle), 'needs title')
1213
14 + var missingClosesAt = ChooseOne({
15 + choices: [1, 2, 'three'],
16 + title: 'how many food'
17 + })
18 + t.false(isPoll(missingClosesAt), 'needs closes at')
19 +
1320 var missingDetails = {
1421 type: 'poll',
1522 pollDetails: undefined,
16- title: 'how many food'
23 + title: 'how many food',
24 + closesAt: Date.now()
1725 }
18- t.false(isPoll(missingDetails), 'missing details')
26 + t.false(isPoll(missingDetails), 'needs details')
27 + t.true(isPoll.errors, 'failing validations have errors')
1928
2029 t.end()
2130 })

Built with git-ssb-web