Commit 81f8f8f4fc3b67a1fc26efcfeebed05d1ed7c223
Passes basic test for position.
Piet Geursen committed on 3/5/2018, 1:44:53 AMParent: 44d16cc8e3faae638d0ecc2946f300056bc06322
Files changed
poll/schema/poll.js | ||
---|---|---|
@@ -85,24 +85,24 @@ | ||
85 | 85 | message: { |
86 | 86 | type: 'object', |
87 | 87 | required: ['link'], |
88 | 88 | properties: { |
89 | - link: { $ref: '#/definitions/messageId'} | |
89 | + link: { $ref: '#/definitions/messageId' } | |
90 | 90 | } |
91 | 91 | }, |
92 | 92 | feed: { |
93 | 93 | type: 'object', |
94 | 94 | required: ['link', 'name'], |
95 | 95 | properties: { |
96 | - link: { $ref: '#/definitions/feedId'}, | |
96 | + link: { $ref: '#/definitions/feedId' }, | |
97 | 97 | name: { type: 'string' } |
98 | 98 | } |
99 | 99 | }, |
100 | 100 | blob: { |
101 | 101 | type: 'object', |
102 | 102 | required: ['link', 'name'], |
103 | 103 | properties: { |
104 | - link: { $ref: '#/definitions/blobId'}, | |
104 | + link: { $ref: '#/definitions/blobId' }, | |
105 | 105 | name: { type: 'string' } |
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
position/schema/details/chooseOne.js | ||
---|---|---|
@@ -1,22 +1,7 @@ | ||
1 | -const Validate = require('is-my-json-valid') | |
2 | - | |
3 | 1 | const { chooseOnePositionType } = require('../../../types') |
4 | 2 | const typeStringPattern = `^${chooseOnePositionType}$` |
5 | -const typeStringRegex = new RegExp(typeStringPattern) | |
6 | 3 | |
7 | -function isValidTypeString (string) { | |
8 | - return typeStringRegex.test(string) | |
9 | -} | |
10 | - | |
11 | -function create ({choice, reason}) { | |
12 | - return { | |
13 | - choice, | |
14 | - type: chooseOnePositionType, | |
15 | - reason | |
16 | - } | |
17 | -} | |
18 | - | |
19 | 4 | var schema = { |
20 | 5 | type: 'object', |
21 | 6 | required: ['type', 'choice'], |
22 | 7 | properties: { |
@@ -30,12 +15,5 @@ | ||
30 | 15 | } |
31 | 16 | } |
32 | 17 | } |
33 | 18 | |
34 | -const validate = Validate(schema, { verbose: true }) | |
35 | - | |
36 | -module.exports = { | |
37 | - isValidTypeString, | |
38 | - schema, | |
39 | - validate, | |
40 | - create | |
41 | -} | |
19 | +module.exports = schema |
position/schema/position.js | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 | |
5 | 5 | const schema = { |
6 | 6 | $schema: 'http://json-schema.org/schema#', |
7 | 7 | type: 'object', |
8 | - required: ['root', 'branch', 'positionDetails'], | |
8 | + required: ['type', 'positionDetails'], | |
9 | 9 | properties: { |
10 | 10 | version: { |
11 | 11 | type: 'string', |
12 | 12 | pattern: '^0.1.0$' |
@@ -53,9 +53,9 @@ | ||
53 | 53 | } |
54 | 54 | }, |
55 | 55 | definitions: { |
56 | 56 | |
57 | - postionDetails: { | |
57 | + positionDetails: { | |
58 | 58 | type: 'object', |
59 | 59 | chooseOne: chooseOneDetails |
60 | 60 | }, |
61 | 61 | messageId: { |
@@ -116,10 +116,5 @@ | ||
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | -const validate = Validate(schema, { verbose: true }) | |
121 | - | |
122 | -module.exports = { | |
123 | - schema, | |
124 | - validate | |
125 | -} | |
120 | +module.exports = schema |
position/sync/chooseOne.js | ||
---|---|---|
@@ -1,15 +1,14 @@ | ||
1 | 1 | const Postion = require('./position') |
2 | -const { chooseOneType } = require('../../types') | |
2 | +const { chooseOnePositionType } = require('../../types') | |
3 | 3 | |
4 | -function ChooseOne ({ choices, title, closesAt, body, channel, recps, mentions }) { | |
4 | +function ChooseOne ({ choice, body, channel, recps, mentions }) { | |
5 | + console.log('choose one choice:', choice) | |
5 | 6 | return Postion({ |
6 | 7 | positionDetails: { |
7 | - choices, | |
8 | - type: chooseOneType | |
8 | + choice, | |
9 | + type: chooseOnePositionType | |
9 | 10 | }, |
10 | - title, | |
11 | - closesAt, | |
12 | 11 | body, |
13 | 12 | channel, |
14 | 13 | recps, |
15 | 14 | mentions |
test/poll/sync/chooseOne.test.js | ||
---|---|---|
@@ -2,8 +2,12 @@ | ||
2 | 2 | const ChooseOne = require('../../../poll/sync/chooseOne') |
3 | 3 | const isPoll = require('../../../isPoll') |
4 | 4 | |
5 | 5 | test('Position - ChooseOne', function (t) { |
6 | + var invalidPoll = ChooseOne({ | |
7 | + }) | |
8 | + t.false(isPoll(invalidPoll), 'invalid') | |
9 | + | |
6 | 10 | var validPoll = ChooseOne({ |
7 | 11 | choices: [1, 2, 'three'], |
8 | 12 | title: 'how many food', |
9 | 13 | closesAt: Date.now() |
test/position/sync/chooseOne.test.js | ||
---|---|---|
@@ -2,8 +2,12 @@ | ||
2 | 2 | const ChooseOne = require('../../../position/sync/chooseOne') |
3 | 3 | const isPosition = require('../../../isPosition') |
4 | 4 | |
5 | 5 | test('Position - ChooseOne', function (t) { |
6 | + var invalidPosition = ChooseOne({ | |
7 | + }) | |
8 | + t.false(isPosition(invalidPosition), 'missing a choice') | |
9 | + | |
6 | 10 | var validPosition = ChooseOne({ |
7 | 11 | choice: 0 |
8 | 12 | }) |
9 | 13 | t.true(isPosition(validPosition), 'simple') |
test/position/sync/isPosition.test.js | ||
---|---|---|
@@ -1,28 +1,14 @@ | ||
1 | 1 | const test = require('tape') |
2 | -const ChooseOne = require('../../../position/sync/chooseOne') | |
3 | 2 | const isPosition = require('../../../isPosition') |
4 | 3 | |
5 | 4 | // this is for testing the attributes that are required for all polls |
6 | 5 | test('position - common requirements', function (t) { |
7 | - var missingTitle = ChooseOne({ | |
8 | - choices: [1, 2, 'three'], | |
9 | - closesAt: Date.now() | |
10 | - }) | |
11 | - t.false(isPosition(missingTitle), 'needs title') | |
12 | - | |
13 | - var missingClosesAt = ChooseOne({ | |
14 | - choices: [1, 2, 'three'], | |
15 | - title: 'how many food' | |
16 | - }) | |
17 | - t.false(isPosition(missingClosesAt), 'needs closes at') | |
18 | - | |
19 | 6 | var missingDetails = { |
20 | - type: 'poll', | |
21 | - pollDetails: undefined, | |
22 | - title: 'how many food', | |
23 | - closesAt: Date.now() | |
7 | + type: 'position', | |
8 | + positionDetails: undefined | |
24 | 9 | } |
10 | + console.log(isPosition({})) | |
25 | 11 | t.false(isPosition(missingDetails), 'needs details') |
26 | 12 | t.true(isPosition.errors, 'failing validations have errors') |
27 | 13 | |
28 | 14 | t.end() |
Built with git-ssb-web