Commit 0e0922a38a178fc20c0532642828075f0de37a72
add closesAt requirement on polls
mix irving committed on 3/1/2018, 5:23:35 AMParent: ff7663e73e7aedeb75242d658e91bb048df0253f
Files changed
README.md | changed |
poll/schema/poll.js | changed |
poll/sync/chooseOne.js | changed |
poll/sync/poll.js | changed |
test/poll/sync/chooseOne.test.js | changed |
test/poll/sync/isPoll.test.js | changed |
README.md | |||
---|---|---|---|
@@ -76,48 +76,56 @@ | |||
76 | 76 … | ``` | |
77 | 77 … | ||
78 | 78 … | ## Schemas | |
79 | 79 … | ||
80 … | +### Poll | ||
81 … | + | ||
80 | 82 … | Poll message content | |
81 | -``` | ||
83 … | +```js | ||
82 | 84 … | { | |
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, | ||
87 | 91 … | mentions, | |
92 … | + recps | ||
88 | 93 … | } | |
89 | 94 … | ||
90 | 95 … | ``` | |
91 | 96 … | ||
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 | ||
94 | 101 … | { | |
95 | 102 … | type: 'dot', // required | |
96 | 103 … | maxStanceScore: 'Integer >= 0', // required | |
97 | 104 … | maxChoiceScore: 'Integer >= 0', //optional | |
98 | 105 … | choices: Array, // required | |
99 | 106 … | } | |
100 | 107 … | ``` | |
101 | 108 … | ||
102 | -Proposal pollType | ||
103 | -``` | ||
109 … | +Proposal PollDetails | ||
110 … | +```js | ||
104 | 111 … | { | |
105 | 112 … | type: 'proposal', // required | |
106 | 113 … | proposal: String, // required | |
107 | 114 … | } | |
108 | 115 … | ``` | |
109 | 116 … | ||
110 | -Score pollType | ||
111 | -``` | ||
117 … | +Score PollDetails | ||
118 … | +```js | ||
112 | 119 … | { | |
113 | 120 … | type: 'score', // required | |
114 | 121 … | maxChoiceScore: 'Integer >= 0', //required | |
115 | 122 … | choices: Array, // required | |
116 | 123 … | } | |
117 | 124 … | ``` | |
118 | 125 … | ||
119 | -Position | ||
126 … | +### Position | ||
127 … | + | ||
120 | 128 … | ``` | |
121 | 129 … | ||
122 | 130 … | ``` | |
123 | 131 … |
poll/schema/poll.js | ||
---|---|---|
@@ -7,9 +7,9 @@ | ||
7 | 7 … | |
8 | 8 … | const schema = { |
9 | 9 … | $schema: 'http://json-schema.org/schema#', |
10 | 10 … | type: 'object', |
11 | - required: ['type', 'pollDetails', 'title'], | |
11 … | + required: ['type', 'pollDetails', 'title', 'closesAt'], | |
12 | 12 … | properties: { |
13 | 13 … | version: { |
14 | 14 … | type: 'string', |
15 | 15 … | pattern: '^0.1.0$' |
@@ -28,8 +28,9 @@ | ||
28 | 28 … | // { $ref: '#/definitions/pollDetails/meeting'}, |
29 | 29 … | ] |
30 | 30 … | }, |
31 | 31 … | title: { type: 'string' }, |
32 … | + closesAt: { type: 'integer' }, | |
32 | 33 … | body: { type: 'string' }, |
33 | 34 … | mentions: { |
34 | 35 … | oneOf: [ |
35 | 36 … | { type: 'null' }, |
poll/sync/chooseOne.js | ||
---|---|---|
@@ -1,14 +1,15 @@ | ||
1 | 1 … | const Poll = require('./poll') |
2 | 2 … | const { chooseOneType } = require('../types') |
3 | 3 … | |
4 | -function ChooseOne ({ choices, title, body, channel, recps, mentions }) { | |
4 … | +function ChooseOne ({ choices, title, closesAt, body, channel, recps, mentions }) { | |
5 | 5 … | return Poll({ |
6 | 6 … | pollDetails: { |
7 | 7 … | choices, |
8 | 8 … | type: chooseOneType |
9 | 9 … | }, |
10 | 10 … | title, |
11 … | + closesAt, | |
11 | 12 … | body, |
12 | 13 … | channel, |
13 | 14 … | recps, |
14 | 15 … | mentions |
poll/sync/poll.js | ||
---|---|---|
@@ -1,9 +1,11 @@ | ||
1 | 1 … | // var { link } = require('ssb-msg-schemas/util') |
2 | 2 … | |
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 } | |
5 | 5 … | |
6 … | + if (body) content.body = body | |
7 … | + | |
6 | 8 … | // if (root) { |
7 | 9 … | // root = link(root) |
8 | 10 … | // if (!root) { throw new Error('root is not a valid link') } |
9 | 11 … | // content.root = root |
test/poll/sync/chooseOne.test.js | ||
---|---|---|
@@ -2,9 +2,13 @@ | ||
2 | 2 … | const ChooseOne = require('../../../poll/sync/chooseOne') |
3 | 3 … | const isPoll = require('../../../isPoll') |
4 | 4 … | |
5 | 5 … | 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 … | + }) | |
7 | 11 … | t.true(isPoll(validPoll), 'simple') |
8 | 12 … | |
9 | 13 … | var fullPollMsg = { |
10 | 14 … | key: '%somekey', |
@@ -15,10 +19,6 @@ | ||
15 | 19 … | t.true(isPoll(fullPollMsg), 'simple (full msg)') |
16 | 20 … | // NOTE - we might want an isChooseOnePoll in future |
17 | 21 … | // t.true(isChooseOnePoll(fullPollMsg), 'simple (full msg)') |
18 | 22 … | |
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 | - | |
23 | 23 … | t.end() |
24 | 24 … | }) |
test/poll/sync/isPoll.test.js | ||
---|---|---|
@@ -5,17 +5,26 @@ | ||
5 | 5 … | // this is for testing the attributes that are required for all polls |
6 | 6 … | |
7 | 7 … | test('Poll - common requirements', function (t) { |
8 | 8 … | var missingTitle = ChooseOne({ |
9 | - choices: [1, 2, 'three'] | |
9 … | + choices: [1, 2, 'three'], | |
10 … | + closesAt: Date.now() | |
10 | 11 … | }) |
11 | 12 … | t.false(isPoll(missingTitle), 'needs title') |
12 | 13 … | |
14 … | + var missingClosesAt = ChooseOne({ | |
15 … | + choices: [1, 2, 'three'], | |
16 … | + title: 'how many food' | |
17 … | + }) | |
18 … | + t.false(isPoll(missingClosesAt), 'needs closes at') | |
19 … | + | |
13 | 20 … | var missingDetails = { |
14 | 21 … | type: 'poll', |
15 | 22 … | pollDetails: undefined, |
16 | - title: 'how many food' | |
23 … | + title: 'how many food', | |
24 … | + closesAt: Date.now() | |
17 | 25 … | } |
18 | - t.false(isPoll(missingDetails), 'missing details') | |
26 … | + t.false(isPoll(missingDetails), 'needs details') | |
27 … | + t.true(isPoll.errors, 'failing validations have errors') | |
19 | 28 … | |
20 | 29 … | t.end() |
21 | 30 … | }) |
Built with git-ssb-web