Files: 85899d9c65af617c7746ff686142b1bf2e513f20 / tests / sync / isBlog.js
2392 bytesRaw
1 | const test = require('tape') |
2 | |
3 | const isBlog = require('../../sync/isBlog')() |
4 | // or const isBlog = require('../../isBlog') |
5 | |
6 | test('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 incompleteBlog = { |
22 | type: 'blog', |
23 | title: 'An important idea' |
24 | } |
25 | t.notOk(isBlog(incompleteBlog), 'invalidates incompleteBlog blog') |
26 | t.equal(isBlog.errors[0].message, 'is required', 'provides error messages') |
27 | |
28 | const malformedBlog = { |
29 | type: 'blog', |
30 | title: 'An important idea', |
31 | blog: '&sfoIYo0kKKGI+TJYnznVDSs3BM' |
32 | } |
33 | t.notOk(isBlog(malformedBlog), 'invalidates malformed blog') |
34 | |
35 | const actualBlog = { |
36 | 'key': '%GKGFNHKeUVAVPNUapE41skF3ND3Etm76XO7Y7sVeTLI=.sha256', |
37 | 'value': { |
38 | 'previous': '%MxC4d1BHqtBiC+mC+BaaZOAZSg41nFGOdXDpJiU+tg4=.sha256', |
39 | 'author': '@ye+QM09iPcDJD6YvQYjoQc7sLF/IFhmNbEqgdzQo3lQ=.ed25519', |
40 | 'sequence': 13369, |
41 | 'timestamp': 1518568914727, |
42 | 'hash': 'sha256', |
43 | 'content': { |
44 | 'type': 'blog', |
45 | 'channel': 'cooperative', |
46 | 'title': 'Coop-source', |
47 | 'summary': 'a day in the life of open source (and cooperatives) ', |
48 | 'mentions': [ |
49 | { |
50 | 'link': '&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256', |
51 | 'name': 'at_mention.png' |
52 | }, |
53 | { |
54 | 'link': '&3S7gQpN8ZznmLzstY9AZiWZaZXFG2UaxmeE9SuKU5jk=.sha256', |
55 | 'name': 'protoflip.png' |
56 | }, |
57 | { |
58 | 'link': '&UgzlelvbBOTj6QGaTqi/PnfkjY8wUNSzUw37/yOxMLw=.sha256', |
59 | 'name': 'protozoa_logo.png' |
60 | } |
61 | ], |
62 | 'thumbnail': '&wpKZTZIifFeH0P0LY3Iztgzbj17VlKXIfQNjPnoas1g=.sha256', |
63 | 'blog': '&+/mENZOe+RTSn9ZsTFG7Xw0dtv05YDUpIhazYQEj48w=.sha256' |
64 | }, |
65 | 'signature': '1WEhVT42LCdNhuf5ogpcnJfJWbFTUily666pj1XDKS07hjEKGuwZTy/pYRcl/XJJIHMH9MiRkR6FIiOIa7t1DQ==.sig.ed25519' |
66 | }, |
67 | 'timestamp': 1518568915077, |
68 | 'dest': '#cooperative', |
69 | 'rts': 1518568914727 |
70 | } |
71 | t.ok(isBlog(actualBlog), 'validates a blog from ticktack') |
72 | |
73 | t.end() |
74 | }) |
75 |
Built with git-ssb-web