git ssb

0+

Piet / ssb-loomio



Commit 81f8f8f4fc3b67a1fc26efcfeebed05d1ed7c223

Passes basic test for position.

Piet Geursen committed on 3/5/2018, 1:44:53 AM
Parent: 44d16cc8e3faae638d0ecc2946f300056bc06322

Files changed

poll/schema/poll.jschanged
position/schema/details/chooseOne.jschanged
position/schema/position.jschanged
position/sync/chooseOne.jschanged
test/poll/sync/chooseOne.test.jschanged
test/position/sync/chooseOne.test.jschanged
test/position/sync/isPosition.test.jschanged
poll/schema/poll.jsView
@@ -85,24 +85,24 @@
8585 message: {
8686 type: 'object',
8787 required: ['link'],
8888 properties: {
89- link: { $ref: '#/definitions/messageId'}
89+ link: { $ref: '#/definitions/messageId' }
9090 }
9191 },
9292 feed: {
9393 type: 'object',
9494 required: ['link', 'name'],
9595 properties: {
96- link: { $ref: '#/definitions/feedId'},
96+ link: { $ref: '#/definitions/feedId' },
9797 name: { type: 'string' }
9898 }
9999 },
100100 blob: {
101101 type: 'object',
102102 required: ['link', 'name'],
103103 properties: {
104- link: { $ref: '#/definitions/blobId'},
104+ link: { $ref: '#/definitions/blobId' },
105105 name: { type: 'string' }
106106 }
107107 }
108108 }
position/schema/details/chooseOne.jsView
@@ -1,22 +1,7 @@
1-const Validate = require('is-my-json-valid')
2-
31 const { chooseOnePositionType } = require('../../../types')
42 const typeStringPattern = `^${chooseOnePositionType}$`
5-const typeStringRegex = new RegExp(typeStringPattern)
63
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-
194 var schema = {
205 type: 'object',
216 required: ['type', 'choice'],
227 properties: {
@@ -30,12 +15,5 @@
3015 }
3116 }
3217 }
3318
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.jsView
@@ -4,9 +4,9 @@
44
55 const schema = {
66 $schema: 'http://json-schema.org/schema#',
77 type: 'object',
8- required: ['root', 'branch', 'positionDetails'],
8+ required: ['type', 'positionDetails'],
99 properties: {
1010 version: {
1111 type: 'string',
1212 pattern: '^0.1.0$'
@@ -53,9 +53,9 @@
5353 }
5454 },
5555 definitions: {
5656
57- postionDetails: {
57+ positionDetails: {
5858 type: 'object',
5959 chooseOne: chooseOneDetails
6060 },
6161 messageId: {
@@ -116,10 +116,5 @@
116116 }
117117 }
118118 }
119119
120-const validate = Validate(schema, { verbose: true })
121-
122-module.exports = {
123- schema,
124- validate
125-}
120+module.exports = schema
position/sync/chooseOne.jsView
@@ -1,15 +1,14 @@
11 const Postion = require('./position')
2-const { chooseOneType } = require('../../types')
2+const { chooseOnePositionType } = require('../../types')
33
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)
56 return Postion({
67 positionDetails: {
7- choices,
8- type: chooseOneType
8+ choice,
9+ type: chooseOnePositionType
910 },
10- title,
11- closesAt,
1211 body,
1312 channel,
1413 recps,
1514 mentions
test/poll/sync/chooseOne.test.jsView
@@ -2,8 +2,12 @@
22 const ChooseOne = require('../../../poll/sync/chooseOne')
33 const isPoll = require('../../../isPoll')
44
55 test('Position - ChooseOne', function (t) {
6+ var invalidPoll = ChooseOne({
7+ })
8+ t.false(isPoll(invalidPoll), 'invalid')
9+
610 var validPoll = ChooseOne({
711 choices: [1, 2, 'three'],
812 title: 'how many food',
913 closesAt: Date.now()
test/position/sync/chooseOne.test.jsView
@@ -2,8 +2,12 @@
22 const ChooseOne = require('../../../position/sync/chooseOne')
33 const isPosition = require('../../../isPosition')
44
55 test('Position - ChooseOne', function (t) {
6+ var invalidPosition = ChooseOne({
7+ })
8+ t.false(isPosition(invalidPosition), 'missing a choice')
9+
610 var validPosition = ChooseOne({
711 choice: 0
812 })
913 t.true(isPosition(validPosition), 'simple')
test/position/sync/isPosition.test.jsView
@@ -1,28 +1,14 @@
11 const test = require('tape')
2-const ChooseOne = require('../../../position/sync/chooseOne')
32 const isPosition = require('../../../isPosition')
43
54 // this is for testing the attributes that are required for all polls
65 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-
196 var missingDetails = {
20- type: 'poll',
21- pollDetails: undefined,
22- title: 'how many food',
23- closesAt: Date.now()
7+ type: 'position',
8+ positionDetails: undefined
249 }
10+ console.log(isPosition({}))
2511 t.false(isPosition(missingDetails), 'needs details')
2612 t.true(isPosition.errors, 'failing validations have errors')
2713
2814 t.end()

Built with git-ssb-web