git ssb

1+

mixmix / scuttle-book



Commit c4f0656414375ade1e3c819a7b61d5808010551c

add async/create

mix irving committed on 1/28/2018, 2:00:53 AM
Parent: 52b538d1c0b57ad5fe2d8c3e4af7b5d03fc6ebbb

Files changed

async/create.jschanged
index.jschanged
package.jsonchanged
schemas/book.test.jsdeleted
tests/isBook.jsadded
async/create.jsView
@@ -1,5 +1,11 @@
1 +const isBook = require('../sync/isBook')()
2 +// isBook is an odd case that doesn't need a client
3 +
14 module.exports = function (client) {
25 return function (book, cb) {
6 + if (!isBook(book)) return cb(isBook.errors)
7 +
8 + client.publish(book, cb)
39 }
410 }
511
index.jsView
@@ -1,14 +1,14 @@
11 const inject = require('./inject')
22
33 const methods = {
44 async: {
5- comment: require('./async/comment'),
5 + // comment: require('./async/comment'),
66 create: require('./async/create'),
7- get: require('./async/get'),
8- isBookComment: require('./async/isBookComment'),
9- isBookUpdate: require('./async/isBookUpdate'),
10- update: require('./async/update'),
7 + // get: require('./async/get'),
8 + // isBookComment: require('./async/isBookComment'),
9 + // isBookUpdate: require('./async/isBookUpdate'),
10 + // update: require('./async/update'),
1111 },
1212 // obs: {
1313 // authors: require('./obs/authors'),
1414 // book: require('./obs/book'),
package.jsonView
@@ -3,9 +3,9 @@
33 "version": "0.0.1",
44 "description": "a scuttlebutt helper for all book related messages",
55 "main": "index.js",
66 "scripts": {
7- "test": "tape **/*.test.js | tap-spec"
7 + "test": "tape tests/**/*.js | tap-spec"
88 },
99 "repository": {
1010 "type": "git",
1111 "url": "git+https://github.com/mixmix/scuttle-book.git"
schemas/book.test.jsView
@@ -1,31 +1,0 @@
1-const test = require('tape')
2-const validator = require('is-my-json-valid')
3-
4-const isBook = require('../isBook.js')
5-
6-test('book schema', t => {
7-
8- const simpleBook = {
9- type: 'bookclub',
10- authors: 'Ursula le Guin',
11- title: 'The Dispossessed'
12- }
13- t.ok(isBook(simpleBook), 'validates simple book')
14-
15- const incompleteBook = {
16- type: 'bookclub',
17- authors: 'Ursula le Guin',
18- }
19- t.notOk(isBook(incompleteBook), 'invalidates incompleteBook book')
20- t.equal(isBook.errors[0].message, 'is required', 'provides error messages')
21-
22- const multiAuthorBook = {
23- type: 'bookclub',
24- authors: ['Ursula le Guin', 'Terry Pratchett'],
25- title: 'The Dispossessed'
26- }
27- t.ok(isBook(multiAuthorBook), 'validates multi-author book')
28-
29- t.end()
30-})
31-
tests/isBook.jsView
@@ -1,0 +1,31 @@
1 +const test = require('tape')
2 +const validator = require('is-my-json-valid')
3 +
4 +const isBook = require('../isBook.js')
5 +
6 +test('isBoot / book schema', t => {
7 +
8 + const simpleBook = {
9 + type: 'bookclub',
10 + authors: 'Ursula le Guin',
11 + title: 'The Dispossessed'
12 + }
13 + t.ok(isBook(simpleBook), 'validates simple book')
14 +
15 + const incompleteBook = {
16 + type: 'bookclub',
17 + authors: 'Ursula le Guin',
18 + }
19 + t.notOk(isBook(incompleteBook), 'invalidates incompleteBook book')
20 + t.equal(isBook.errors[0].message, 'is required', 'provides error messages')
21 +
22 + const multiAuthorBook = {
23 + type: 'bookclub',
24 + authors: ['Ursula le Guin', 'Terry Pratchett'],
25 + title: 'The Dispossessed'
26 + }
27 + t.ok(isBook(multiAuthorBook), 'validates multi-author book')
28 +
29 + t.end()
30 +})
31 +

Built with git-ssb-web