git ssb

0+

mixmix / scuttle-blog



Tree: c22975ff5c372669572525d717f2296ea5c14129

Files: c22975ff5c372669572525d717f2296ea5c14129 / tests / sync / isBlog.js

2691 bytesRaw
1const test = require('tape')
2
3const isBlog = require('../../sync/isBlog')()
4// or const isBlog = require('../../isBlog')
5
6test('isBlog / blog schema', t => {
7 const notBlog = {
8 type: 'post',
9 title: 'An important idea',
10 blog: '&sfoIYo0kKKGI+TJYnznVDSs3BM/HjMWdCPXirvj9BfE=.sha256'
11 }
12 t.notOk(isBlog(notBlog), 'invalidates messages that are not blogs')
13
14 const simpleBlog = {
15 type: 'blog',
16 title: 'An important idea',
17 blog: '&sfoIYo0kKKGI+TJYnznVDSs3BM/HjMWdCPXirvj9BfE=.sha256'
18 }
19 t.ok(isBlog(simpleBlog), 'validates simple blog')
20
21 const emptyThumbnail = {
22 type: 'blog',
23 title: 'An important idea',
24 blog: '&sfoIYo0kKKGI+TJYnznVDSs3BM/HjMWdCPXirvj9BfE=.sha256',
25 thumbnail: null
26 }
27 t.ok(isBlog(emptyThumbnail), 'validates simple blog with empty thumbnail')
28
29 const incompleteBlog = {
30 type: 'blog',
31 title: 'An important idea'
32 }
33 t.notOk(isBlog(incompleteBlog), 'invalidates incompleteBlog blog')
34 t.equal(isBlog.errors[0].message, 'is required', 'provides error messages')
35
36 const malformedBlog = {
37 type: 'blog',
38 title: 'An important idea',
39 blog: '&sfoIYo0kKKGI+TJYnznVDSs3BM'
40 }
41 t.notOk(isBlog(malformedBlog), 'invalidates malformed blog')
42
43 const actualBlog = {
44 'key': '%GKGFNHKeUVAVPNUapE41skF3ND3Etm76XO7Y7sVeTLI=.sha256',
45 'value': {
46 'previous': '%MxC4d1BHqtBiC+mC+BaaZOAZSg41nFGOdXDpJiU+tg4=.sha256',
47 'author': '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519',
48 'sequence': 13369,
49 'timestamp': 1518568914727,
50 'hash': 'sha256',
51 'content': {
52 'type': 'blog',
53 'channel': 'cooperative',
54 'title': 'Coop-source',
55 'summary': 'a day in the life of open source (and cooperatives) ',
56 'mentions': [
57 {
58 'link': '&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256',
59 'name': 'at_mention.png'
60 },
61 {
62 'link': '&3S7gQpN8ZznmLzstY9AZiWZaZXFG2UaxmeE9SuKU5jk=.sha256',
63 'name': 'protoflip.png'
64 },
65 {
66 'link': '&UgzlelvbBOTj6QGaTqi/PnfkjY8wUNSzUw37/yOxMLw=.sha256',
67 'name': 'protozoa_logo.png'
68 }
69 ],
70 'thumbnail': '&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256',
71 'blog': '&+/mENZOe+RTSn9ZsTFG7Xw0dtv05YDUpIhazYQEj48w=.sha256'
72 },
73 'signature': '1WEhVT42LCdNhuf5ogpcnJfJWbFTUily666pj1XDKS07hjEKGuwZTy/pYRcl/XJJIHMH9MiRkR6FIiOIa7t1DQ==.sig.ed25519'
74 },
75 'timestamp': 1518568915077,
76 'dest': '#cooperative',
77 'rts': 1518568914727
78 }
79 t.ok(isBlog(actualBlog), 'validates a blog from ticktack')
80 if (!isBlog(actualBlog)) console.log(isBlog.errors)
81
82 t.end()
83})
84

Built with git-ssb-web