git ssb

0+

Piet / ssb-loomio



Commit e602c7f5b93b901ece225fec5f2fc495eeaed73d

Standard

Piet Geursen committed on 2/28/2018, 11:22:39 PM
Parent: e5241baa17774c8f27f39e3c093cf2b43a8aaa2f

Files changed

index.jschanged
poll.jschanged
schema/poll.jschanged
schema/pollDetails/chooseOne.jschanged
schema/pollDetails/dot.jschanged
schema/pollDetails/proposal.jschanged
schema/pollDetails/score.jschanged
schema/position.jschanged
schema/positionTypes/chooseOne.jschanged
stance.jschanged
sync/isPoll.jschanged
test/schema/poll.jschanged
test/schema/pollDetails/chooseOne.jschanged
index.jsView
@@ -1,16 +1,20 @@
1-const {
1 +const {
22 create: poll,
33 schema: pollSchema,
44 validate: isPoll
55 } = require('./poll')
66
7-const {
7 +const {
88 create: stance,
99 schema: stanceSchema,
1010 validate: isStance
1111 } = require('./stance')
1212
1313 module.exports = {
14- poll, pollSchema, isPoll,
15- stance, stanceSchema, isStance,
14 + poll,
15 + pollSchema,
16 + isPoll,
17 + stance,
18 + stanceSchema,
19 + isStance
1620 }
poll.jsView
@@ -1,46 +1,38 @@
11 var Validate = require('is-my-json-valid')
22 var { schema, validate } = require('./schema/poll.js')
3-var { schema : chooseOneSchema, create: chooseOneCreate, isValidTypeString: isValidChooseOneTypeString } = require('./schema/pollDetails/chooseOne.js')
3 +var { schema: chooseOneSchema, create: chooseOneCreate, isValidTypeString: isValidChooseOneTypeString } = require('./schema/pollDetails/chooseOne.js')
44 var { link } = require('ssb-msg-schemas/util')
55
6-
7-
8-function create({text, mentions, recps, channel, pollOptions, root, branch}){
6 +function create ({text, mentions, recps, channel, pollOptions, root, branch}) {
97 var content = { type: 'poll', text, pollOptions}
108 if (root) {
119 root = link(root)
12- if (!root)
13- throw new Error('root is not a valid link')
10 + if (!root) { throw new Error('root is not a valid link') }
1411 content.root = root
1512 }
1613 if (branch) {
17- if (!root)
18- throw new Error('root is not a valid link')
14 + if (!root) { throw new Error('root is not a valid link') }
1915 branch = Array.isArray(branch) ? branch.map(link) : link(branch)
20- if (!branch)
21- throw new Error('branch is not a valid link')
16 + if (!branch) { throw new Error('branch is not a valid link') }
2217 content.branch = branch
2318 }
2419 if (mentions && (!Array.isArray(mentions) || mentions.length)) {
2520 mentions = links(mentions)
26- if (!mentions || !mentions.length)
27- throw new Error('mentions are not valid links')
21 + if (!mentions || !mentions.length) { throw new Error('mentions are not valid links') }
2822 content.mentions = mentions
2923 }
3024 if (recps && (!Array.isArray(recps) || recps.length)) {
3125 recps = links(recps)
32- if (!recps || !recps.length)
33- throw new Error('recps are not valid links')
26 + if (!recps || !recps.length) { throw new Error('recps are not valid links') }
3427 content.recps = recps
3528 }
3629 if (channel) {
37- if (typeof channel !== 'string')
38- throw new Error('channel must be a string')
30 + if (typeof channel !== 'string') { throw new Error('channel must be a string') }
3931 content.channel = channel
4032 }
4133
42- if(isValidChooseOneTypeString(pollOptions.type)){
34 + if (isValidChooseOneTypeString(pollOptions.type)) {
4335 content.pollOptions = chooseOneCreate({choices: pollOptions.choices})
4436 }
4537
4638 return content
schema/poll.jsView
@@ -23,12 +23,12 @@
2323 oneOf: [
2424 { $ref: '#/definitions/pollDetails/dot'},
2525 { $ref: '#/definitions/pollDetails/proposal'},
2626 { $ref: '#/definitions/pollDetails/score'},
27- { $ref: '#/definitions/pollDetails/chooseOne'},
28- //{ $ref: '#/definitions/pollDetails/rsvp'},
29- //{ $ref: '#/definitions/pollDetails/meeting'},
30- ]
27 + { $ref: '#/definitions/pollDetails/chooseOne'}
28 + // { $ref: '#/definitions/pollDetails/rsvp'},
29 + // { $ref: '#/definitions/pollDetails/meeting'},
30 + ]
3131 },
3232 text: { type: 'string' },
3333 mentions: {
3434 oneOf: [
@@ -52,9 +52,9 @@
5252 type: 'array',
5353 items: {
5454 oneOf: [
5555 { $ref: '#/definitions/feedId' },
56- { $ref: '#/definitions/mentions/feed' },
56 + { $ref: '#/definitions/mentions/feed' }
5757 ]
5858 }
5959 }
6060 ]
@@ -105,9 +105,9 @@
105105 name: { type: 'string' }
106106 }
107107 }
108108 }
109- },
109 + }
110110 }
111111
112112 const validate = Validate(schema, { verbose: true })
113113
schema/pollDetails/chooseOne.jsView
@@ -1,18 +1,18 @@
11 const Validate = require('is-my-json-valid')
22
33 const typeString = 'chooseOne'
4-const typeStringPattern =`^${typeString}$`
5-const typeStringRegex = new RegExp(typeStringPattern)
4 +const typeStringPattern = `^${typeString}$`
5 +const typeStringRegex = new RegExp(typeStringPattern)
66
7-function isValidTypeString(string) {
8- return typeStringRegex.test(string)
7 +function isValidTypeString (string) {
8 + return typeStringRegex.test(string)
99 }
1010
11-function create({choices}) {
11 +function create ({choices}) {
1212 return {
1313 choices,
14- type: typeString,
14 + type: typeString
1515 }
1616 }
1717
1818 var schema = {
@@ -23,9 +23,9 @@
2323 type: 'string',
2424 pattern: typeStringPattern
2525 },
2626 choices: {
27- type: 'array',
27 + type: 'array'
2828 }
2929 }
3030 }
3131
schema/pollDetails/dot.jsView
@@ -10,11 +10,10 @@
1010 type: 'integer',
1111 minimum: 1
1212 },
1313 choices: {
14- type: 'array',
14 + type: 'array'
1515 }
1616 }
1717 }
1818
19-
20-module.exports = schema;
19 +module.exports = schema
schema/pollDetails/proposal.jsView
@@ -6,10 +6,10 @@
66 type: 'string',
77 pattern: '^proposal$'
88 },
99 proposal: {
10- type: 'string',
10 + type: 'string'
1111 }
1212 }
1313 }
1414
15-module.exports = schema;
15 +module.exports = schema
schema/pollDetails/score.jsView
@@ -10,10 +10,10 @@
1010 type: 'integer',
1111 minimum: 2
1212 },
1313 choices: {
14- type: 'array',
14 + type: 'array'
1515 }
1616 }
1717 }
1818
19-module.exports = schema;
19 +module.exports = schema
schema/position.jsView
@@ -1,19 +1,19 @@
11 const Validate = require('is-my-json-valid')
22 const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref')
3-//what would a message look like?
3 +// what would a message look like?
44 //
5-//well for a chooseOne:
6-//{
5 +// well for a chooseOne:
6 +// {
77 // pollId: msgId,
88 // choice: 'apple', //what if this is a key? Or a key and index number? I wonder if this is an argument for making each choice a separate message?
99 // reason: "I don't like doctorbs",
10-//}
11-//When do the various validations happen?
12-//- when we're counting votes. We need to check it's a valid position for the type of poll
13-//- when we try and create the vote?
10 +// }
11 +// When do the various validations happen?
12 +// - when we're counting votes. We need to check it's a valid position for the type of poll
13 +// - when we try and create the vote?
1414 //
15-//Can a schema always capture the types we need. Max stance score is 1 for a chooseOne.
15 +// Can a schema always capture the types we need. Max stance score is 1 for a chooseOne.
1616
1717 const schema = {
1818 $schema: 'http://json-schema.org/schema#',
1919 type: 'object',
@@ -50,9 +50,9 @@
5050 type: 'array',
5151 items: {
5252 oneOf: [
5353 { $ref: '#/definitions/feedId' },
54- { $ref: '#/definitions/mentions/feed' },
54 + { $ref: '#/definitions/mentions/feed' }
5555 ]
5656 }
5757 }
5858 ]
@@ -115,9 +115,9 @@
115115 name: { type: 'string' }
116116 }
117117 }
118118 }
119- },
119 + }
120120 }
121121
122122 const validate = Validate(schema, { verbose: true })
123123
schema/positionTypes/chooseOne.jsView
@@ -1,20 +1,20 @@
11 const Validate = require('is-my-json-valid')
22
33 const typeString = 'chooseOne'
4-const typeStringPattern =`^${typeString}$`
5-const typeStringRegex = new RegExp(typeStringPattern)
4 +const typeStringPattern = `^${typeString}$`
5 +const typeStringRegex = new RegExp(typeStringPattern)
66
7-function isValidTypeString(string) {
8- return typeStringRegex.test(string)
7 +function isValidTypeString (string) {
8 + return typeStringRegex.test(string)
99 }
1010
11-function create({choice, reason}) {
11 +function create ({choice, reason}) {
1212 return {
1313 choice,
1414 type: typeString,
1515 reason
16- }
16 + }
1717 }
1818
1919 var schema = {
2020 type: 'object',
@@ -24,9 +24,9 @@
2424 type: 'string',
2525 pattern: typeStringPattern
2626 },
2727 choice: {
28- type: 'string',
28 + type: 'string'
2929 }
3030 }
3131 }
3232
@@ -37,5 +37,4 @@
3737 schema,
3838 validate,
3939 create
4040 }
41-
stance.jsView
@@ -1,8 +1,8 @@
11 var Validate = require('is-my-json-valid')
22 const { msgIdRegex, feedIdRegex, blobIdRegex } = require('ssb-ref')
33
4-function create(){
4 +function create () {
55
66 }
77
88 const schema = {
sync/isPoll.jsView
@@ -18,6 +18,4 @@
1818 if (obj.value && obj.value.content) return obj.value.content
1919
2020 return obj
2121 }
22-
23-
test/schema/poll.jsView
@@ -1,15 +1,14 @@
11 var test = require('tape')
2-var {poll, isPoll, response} = require('../..');
2 +var {poll, isPoll, response} = require('../..')
33
4-test('test', function(t) {
4 +test('test', function (t) {
55 t.true(true)
66 t.end()
77 })
88
9-test('create and validate an invalid chooseOne poll', function(t) {
9 +test('create and validate an invalid chooseOne poll', function (t) {
1010 var pollOptions = {type: 'chooseOne'}
11- var myPoll = poll({text:"how many food", mentions: null, recps: null, channel: null, pollOptions})
11 + var myPoll = poll({text: 'how many food', mentions: null, recps: null, channel: null, pollOptions})
1212 t.false(isPoll(myPoll))
1313 t.end()
1414 })
15-
test/schema/pollDetails/chooseOne.jsView
@@ -1,14 +1,14 @@
11 var test = require('tape')
2-var {create, validate} = require('../../../schema/pollDetails/chooseOne');
2 +var {create, validate} = require('../../../schema/pollDetails/chooseOne')
33
4-test('create and validate an invalid chooseOne poll', function(t) {
5- var myPoll = create({choices:"how"})
4 +test('create and validate an invalid chooseOne poll', function (t) {
5 + var myPoll = create({choices: 'how'})
66 t.false(validate(myPoll))
77 t.end()
88 })
99
10-test('create and validate a valid chooseOne poll', function(t) {
11- var myPoll = create({choices:["how","many", "food"]})
10 +test('create and validate a valid chooseOne poll', function (t) {
11 + var myPoll = create({choices: ['how', 'many', 'food']})
1212 t.true(validate(myPoll))
1313 t.end()
1414 })

Built with git-ssb-web