Commit c4f0656414375ade1e3c819a7b61d5808010551c
add async/create
mix irving committed on 1/28/2018, 2:00:53 AMParent: 52b538d1c0b57ad5fe2d8c3e4af7b5d03fc6ebbb
Files changed
async/create.js | changed |
index.js | changed |
package.json | changed |
schemas/book.test.js | deleted |
tests/isBook.js | added |
async/create.js | |||
---|---|---|---|
@@ -1,5 +1,11 @@ | |||
1 … | +const isBook = require('../sync/isBook')() | ||
2 … | +// isBook is an odd case that doesn't need a client | ||
3 … | + | ||
1 | 4 … | module.exports = function (client) { | |
2 | 5 … | return function (book, cb) { | |
6 … | + if (!isBook(book)) return cb(isBook.errors) | ||
7 … | + | ||
8 … | + client.publish(book, cb) | ||
3 | 9 … | } | |
4 | 10 … | } | |
5 | 11 … | ||
index.js | ||
---|---|---|
@@ -1,14 +1,14 @@ | ||
1 | 1 … | const inject = require('./inject') |
2 | 2 … | |
3 | 3 … | const methods = { |
4 | 4 … | async: { |
5 | - comment: require('./async/comment'), | |
5 … | + // comment: require('./async/comment'), | |
6 | 6 … | 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'), | |
11 | 11 … | }, |
12 | 12 … | // obs: { |
13 | 13 … | // authors: require('./obs/authors'), |
14 | 14 … | // book: require('./obs/book'), |
package.json | ||
---|---|---|
@@ -3,9 +3,9 @@ | ||
3 | 3 … | "version": "0.0.1", |
4 | 4 … | "description": "a scuttlebutt helper for all book related messages", |
5 | 5 … | "main": "index.js", |
6 | 6 … | "scripts": { |
7 | - "test": "tape **/*.test.js | tap-spec" | |
7 … | + "test": "tape tests/**/*.js | tap-spec" | |
8 | 8 … | }, |
9 | 9 … | "repository": { |
10 | 10 … | "type": "git", |
11 | 11 … | "url": "git+https://github.com/mixmix/scuttle-book.git" |
schemas/book.test.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -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