Commit ff7663e73e7aedeb75242d658e91bb048df0253f
test common requirements for polls (e.g. title)
mix irving committed on 3/1/2018, 4:35:11 AMParent: 6736253e48a68510bc7290bfd2043b69e2643d0a
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 | added |
README.md | ||
---|---|---|
@@ -58,11 +58,11 @@ | ||
58 | 58 … | |
59 | 59 … | where `opts` is an object of form: |
60 | 60 … | ```js |
61 | 61 … | { |
62 | - title: String, // (required) | |
63 | - choices: Array, // (required) | |
64 | - text: String, | |
62 … | + title: String, // required | |
63 … | + choices: Array, // required | |
64 … | + body: String, | |
65 | 65 … | } |
66 | 66 … | ``` |
67 | 67 … | and `cb` is a callback of signature `(err, newPollMsg)` |
68 | 68 … | |
@@ -81,10 +81,11 @@ | ||
81 | 81 … | ``` |
82 | 82 … | { |
83 | 83 … | type: 'poll', // required |
84 | 84 … | pollType: oneOf:[dot, proposal, score] , // required |
85 | - text: String, // required | |
86 | - mentions, //optional | |
85 … | + title: String, // required | |
86 … | + body: String, | |
87 … | + mentions, | |
87 | 88 … | } |
88 | 89 … | |
89 | 90 … | ``` |
90 | 91 … |
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'], | |
11 … | + required: ['type', 'pollDetails', 'title'], | |
12 | 12 … | properties: { |
13 | 13 … | version: { |
14 | 14 … | type: 'string', |
15 | 15 … | pattern: '^0.1.0$' |
@@ -27,9 +27,10 @@ | ||
27 | 27 … | // { $ref: '#/definitions/pollDetails/rsvp'}, |
28 | 28 … | // { $ref: '#/definitions/pollDetails/meeting'}, |
29 | 29 … | ] |
30 | 30 … | }, |
31 | - text: { type: 'string' }, | |
31 … | + title: { type: 'string' }, | |
32 … | + body: { type: 'string' }, | |
32 | 33 … | mentions: { |
33 | 34 … | oneOf: [ |
34 | 35 … | { type: 'null' }, |
35 | 36 … | { |
poll/sync/chooseOne.js | ||
---|---|---|
@@ -1,15 +1,15 @@ | ||
1 | 1 … | const Poll = require('./poll') |
2 | 2 … | const { chooseOneType } = require('../types') |
3 | 3 … | |
4 | -function ChooseOne ({ choices, title, text, channel, recps, mentions }) { | |
4 … | +function ChooseOne ({ choices, title, body, channel, recps, mentions }) { | |
5 | 5 … | return Poll({ |
6 | 6 … | pollDetails: { |
7 | 7 … | choices, |
8 | 8 … | type: chooseOneType |
9 | 9 … | }, |
10 | - text, | |
11 | 10 … | title, |
11 … | + body, | |
12 | 12 … | channel, |
13 | 13 … | recps, |
14 | 14 … | mentions |
15 | 15 … | }) |
poll/sync/poll.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 … | // var { link } = require('ssb-msg-schemas/util') |
2 | 2 … | |
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 } | |
5 | 5 … | |
6 | 6 … | // if (root) { |
7 | 7 … | // root = link(root) |
8 | 8 … | // if (!root) { throw new Error('root is not a valid link') } |
test/poll/sync/chooseOne.test.js | ||
---|---|---|
@@ -3,22 +3,22 @@ | ||
3 | 3 … | const isPoll = require('../../../isPoll') |
4 | 4 … | |
5 | 5 … | test('ChooseOne', function (t) { |
6 | 6 … | var validPoll = ChooseOne({choices: [1, 2, 'three'], title: 'how many food'}) |
7 | - t.ok(isPoll(validPoll), 'simple') | |
7 … | + t.true(isPoll(validPoll), 'simple') | |
8 | 8 … | |
9 | 9 … | var fullPollMsg = { |
10 | 10 … | key: '%somekey', |
11 | 11 … | value: { |
12 | 12 … | content: validPoll |
13 | 13 … | } |
14 | 14 … | } |
15 | - t.ok(isPoll(fullPollMsg), 'simple (full msg)') | |
15 … | + t.true(isPoll(fullPollMsg), 'simple (full msg)') | |
16 | 16 … | // NOTE - we might want an isChooseOnePoll in future |
17 | - // t.ok(isChooseOnePoll(fullPollMsg), 'simple (full msg)') | |
17 … | + // t.true(isChooseOnePoll(fullPollMsg), 'simple (full msg)') | |
18 | 18 … | |
19 | 19 … | 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') | |
22 | 22 … | |
23 | 23 … | t.end() |
24 | 24 … | }) |
test/poll/sync/isPoll.test.js | |||
---|---|---|---|
@@ -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