git ssb

0+

Piet / ssb-loomio



Commit f81bab2f5e5f60995b99ed6d9b588e91f0c47d1f

Merge pull request #4 from ssbc/position_review

add poll property to positions. perhaps it should be `root` instead?
Piet Geursen authored on 3/5/2018, 9:55:18 PM
GitHub committed on 3/5/2018, 9:55:18 PM
Parent: 07a5f24f2034628892c7c9ed0782b63b30fc7911
Parent: 89f12570ac64ff180e7f40f85d7bf29a33a17e1d

Files changed

README.mdchanged
position/schema/position.jschanged
position/sync/chooseOne.jschanged
position/sync/position.jschanged
test/position/sync/chooseOne.test.jschanged
test/position/sync/isPosition.test.jschanged
types.jschanged
README.mdView
@@ -124,8 +124,9 @@
124124 ```
125125
126126 ### Position
127127
128+chooseOne position:
128129 ```
129130
130131 ```
131132
position/schema/position.jsView
@@ -4,9 +4,9 @@
44
55 const schema = {
66 $schema: 'http://json-schema.org/schema#',
77 type: 'object',
8- required: ['type', 'positionDetails'],
8+ required: ['type', 'poll', 'positionDetails'],
99 properties: {
1010 version: {
1111 type: 'string',
1212 pattern: '^0.1.0$'
@@ -14,8 +14,11 @@
1414 type: {
1515 type: 'string',
1616 pattern: '^position$'
1717 },
18+ poll: {
19+ $ref: '#/definitions/messageId'
20+ },
1821 text: { type: 'string' },
1922 reason: { type: 'string' },
2023 positionDetails: {
2124 oneOf: [
position/sync/chooseOne.jsView
@@ -1,14 +1,15 @@
11 const Postion = require('./position')
22 const { chooseOnePositionType } = require('../../types')
33
4-function ChooseOne ({ choice, body, channel, recps, mentions }) {
4+function ChooseOne ({ poll, choice, reason, channel, recps, mentions }) {
55 return Postion({
6+ poll,
67 positionDetails: {
7- choice,
8- type: chooseOnePositionType
8+ type: chooseOnePositionType,
9+ choice
910 },
10- body,
11+ reason,
1112 channel,
1213 recps,
1314 mentions
1415 })
position/sync/position.jsView
@@ -1,11 +1,9 @@
11 // var { link } = require('ssb-msg-schemas/util')
22
3-function Position ({ positionDetails, reason, body, channel, recps, mentions }) {
4- var content = { type: 'position', positionDetails, reason }
3+function Position ({ poll, positionDetails, reason, channel, recps, mentions }) {
4+ var content = { type: 'position', poll, positionDetails, reason }
55
6- if (body) content.body = body
7-
86 // if (root) {
97 // root = link(root)
108 // if (!root) { throw new Error('root is not a valid link') }
119 // content.root = root
test/position/sync/chooseOne.test.jsView
@@ -2,16 +2,30 @@
22 const ChooseOne = require('../../../position/sync/chooseOne')
33 const isPosition = require('../../../isPosition')
44
55 test('Position - ChooseOne', function (t) {
6- var invalidPosition = ChooseOne({
6+ var missingChoice = ChooseOne({
7+ poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256'
78 })
8- t.false(isPosition(invalidPosition), 'missing a choice')
9+ t.false(isPosition(missingChoice), 'missing a choice')
910
11+ var missingPoll = ChooseOne({
12+ choice: 0
13+ })
14+ t.false(isPosition(missingPoll), 'missing a poll')
15+
16+ var brokenPoll = ChooseOne({
17+ poll: 'dog?',
18+ choice: 0
19+ })
20+ t.false(isPosition(missingPoll), 'does not reference a poll')
21+
1022 var validPosition = ChooseOne({
23+ poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256',
1124 choice: 0
1225 })
1326 t.true(isPosition(validPosition), 'simple')
27+ if (isPosition.errors) console.log(isPosition.errors)
1428
1529 var fullPositionMsg = {
1630 key: '%somekey',
1731 value: {
test/position/sync/isPosition.test.jsView
@@ -4,11 +4,21 @@
44 // this is for testing the attributes that are required for all polls
55 test('position - common requirements', function (t) {
66 var missingDetails = {
77 type: 'position',
8+ poll: '%t+PhrNxxXkw/jMo6mnwUWfFjJapoPWxzsQoe0Np+nYw=.sha256',
89 positionDetails: undefined
910 }
1011 t.false(isPosition(missingDetails), 'needs details')
1112 t.true(isPosition.errors, 'failing validations have errors')
1213
14+ var missingPoll = {
15+ type: 'position',
16+ positionDetails: {
17+ type: 'chooseOnePosition',
18+ choice: 0
19+ }
20+ }
21+ t.false(isPosition(missingPoll), 'needs poll')
22+
1323 t.end()
1424 })
types.jsView
@@ -1,4 +1,24 @@
11 module.exports = {
22 chooseOnePollType: 'chooseOnePoll',
33 chooseOnePositionType: 'chooseOnePosition'
44 }
5+
6+// Question: do these need to be different, could we just have 'chooseOne',
7+// because we already have:
8+// { type: 'poll', pollDetails: { type: 'chooseOne' } }
9+// { type: 'position', positionDetails: { type: 'chooseOne' } }
10+//
11+//
12+// to that end, perhaps we could prune these down to
13+// { type: 'poll', details: { type: 'chooseOne', choices } }
14+// { type: 'position', details: { type: 'chooseOne', choice } }
15+
16+/// positions need to point at a poll right?
17+// I wonder if a position could just be ... but this would mean we would have to have the parent poll, and then based o nthe type there, run a isOneChoicePostion validator... which I wthink could be good? Maybe I don't understandthe complexity of the other types of positions.
18+// { type: 'position', poll, choice }
19+//
20+//
21+// I not that there's also a validation thing where
22+// { type: 'position', poll, choice: 9000 }
23+//
24+// is probably invalid, and that the choice should be an integer bound by the parent poll choices. Can probably think about that case later, but making out reducer we're gonna have to put some filtering logic somewhere. Could programatically generate a position schema based on a poll.... _WOAH there EASY MIX_

Built with git-ssb-web