git ssb

0+

Piet / ssb-loomio



Tree: d022ea7ba118fcb624a4afe57ec5b1be07d30313

Files: d022ea7ba118fcb624a4afe57ec5b1be07d30313 / test / poll / sync / isPoll.test.js

1828 bytesRaw
1const test = require('tape')
2const ChooseOne = require('../../../poll/sync/chooseOne')
3const isPoll = require('../../../isPoll')
4const { CHOOSE_ONE } = require('../../../types')
5
6// this is for testing the attributes that are required for all polls
7
8test('Poll - common requirements', function (t) {
9 var missingTitle = ChooseOne({
10 choices: [1, 2, 'three'],
11 closesAt: new Date().toISOString()
12 })
13 t.false(isPoll(missingTitle), 'needs title')
14
15 var missingClosesAt = ChooseOne({
16 choices: [1, 2, 'three'],
17 title: 'how many food'
18 })
19 t.false(isPoll(missingClosesAt), 'needs closes at')
20
21 var malformedClosesAt = ChooseOne({
22 choices: [1, 2, 'three'],
23 title: 'how many food',
24 closesAt: 'tomorrow'
25 })
26 t.false(isPoll(missingClosesAt), 'needs ISOString closes at')
27
28 var missingDetails = {
29 type: 'poll',
30 pollDetails: undefined,
31 title: 'how many food',
32 closesAt: new Date().toISOString()
33 }
34 t.false(isPoll(missingDetails), 'needs details')
35 t.true(isPoll.errors, 'failing validations have errors')
36
37 var fullyFeatured = {
38 type: 'poll',
39 pollDetails: {
40 type: CHOOSE_ONE,
41 title: 'how many dogs?',
42 choices: [1, 2, 3]
43 },
44 title: 'how many food',
45 body: 'this is really important, please let me know',
46 mentions: [
47 {name: 'mix', link: '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'},
48 {name: 'sweet drawing', link: '&mwILr7kd1Tug/4vX5nW6YORhyununwkO4cF6jbiSyoA=.sha256'},
49 {link: '%s8uVi560mwpE8ncjT+eMz5XBQBREdk4exvM3D6dIg9g=.sha256'}
50 ],
51 recps: [
52 '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519',
53 {name: 'mix', link: '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519'}
54 ],
55 closesAt: new Date().toISOString()
56 }
57 t.true(isPoll(fullyFeatured), 'fully featured')
58
59 t.end()
60})
61

Built with git-ssb-web