Skip to content

Commit

Permalink
passing tests
Browse files Browse the repository at this point in the history
TODO: publish await-busboy and add to deps
  • Loading branch information
aheckmann committed Nov 5, 2016
1 parent a0e03ee commit 7e7612e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
3 changes: 1 addition & 2 deletions joi-router.js
Expand Up @@ -6,9 +6,8 @@ const isGenFn = require('is-gen-fn');
const flatten = require('flatten');
const methods = require('methods');
const KoaRouter = require('koa-router');
const busboy = require('co-busboy');
const busboy = require('await-busboy');
const parse = require('co-body');
//const convert = require('koa-convert');
const Joi = require('joi');
const slice = require('sliced');
const delegate = require('delegates');
Expand Down
12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -30,7 +30,6 @@
"dependencies": {
"clone": "1.0.2",
"co-body": "4.2.0",
"co-busboy": "1.3.1",
"debug": "2.2.0",
"delegates": "1.0.0",
"flatten": "1.0.2",
Expand All @@ -41,19 +40,22 @@
"sliced": "1.0.1"
},
"devDependencies": {
"eslint": "^2.13.1",
"co-mocha": "^1.1.0",
"co-supertest": "^0.0.8",
"eslint": "^3.9.1",
"eslint-config-pebble": "^3.0.0",
"eslint-plugin-standard": "^1.1.0",
"istanbul": "^0.4.0",
"koa": "2.0.0-alpha.6",
"mocha": "^3.0.2",
"co-mocha": "^1.1.0",
"co-supertest": "^0.0.8",
"supertest": "^0.15.0"
},
"eslintConfig": {
"extends": [
"pebble"
]
],
"parserOptions": {
"ecmaVersion": 2017
}
}
}
Binary file added test/fixtures/koa.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 25 additions & 22 deletions test/index.js
Expand Up @@ -295,7 +295,7 @@ describe('koa-joi-router', () => {
r.route({
method: 'get',
path: '/product/:id/:action',
handler: async function(ctx, next) {
handler: async (ctx) => {
assert(typeof ctx.params === 'object' && ctx.params !== null,
'missing params');
assert.equal(4, ctx.params.id);
Expand Down Expand Up @@ -327,7 +327,7 @@ describe('koa-joi-router', () => {
}
});

function fn(ctx, next) {
function fn(ctx) {
ctx.body = ctx.request.body.last + ' ' + ctx.request.body.first;
}

Expand Down Expand Up @@ -647,19 +647,25 @@ describe('koa-joi-router', () => {
describe('request.parts', () => {
describe('when expected type is', () => {
'stream multipart'.split(' ').forEach((type) => {
describe.skip(type, () => {
describe(type, () => {
it('is a co-busboy object', (done) => {
const r = router();

r.route({
method: 'put',
path: '/',
handler: async function(ctx, next) {
console.log('got to the handler');
let part; // eslint-disable-line no-unused-vars
while ((part = await ctx.request.parts)) {}
console.log('finished awaiting co-body');
ctx.body = ctx.request.parts.field.color;
handler: async (ctx) => {
let filename;
let part;
while ((part = await ctx.request.parts)) {
filename = part.filename;
part.resume();
}

ctx.body = {
color: ctx.request.parts.field.color,
file: filename
};
},
validate: {
type: type
Expand All @@ -669,14 +675,11 @@ describe('koa-joi-router', () => {
const app = new Koa();
app.use(r.middleware());

const b = new Buffer(1024);
b.fill('a');

test(app)
.put('/')
.attach('file1', b)
.attach('color', new Buffer('green'))
.expect(200, done);
.attach('file1', `${__dirname}/fixtures/koa.png`)
.field('color', new Buffer('green'))
.expect('{"color":"green","file":"koa.png"}', done);
});
});
});
Expand Down Expand Up @@ -1919,7 +1922,7 @@ describe('koa-joi-router', () => {
const r = router();
let middlewareRanFirst = false;

r.use(async function(ctx, next) {
r.use(async (ctx, next) => {
middlewareRanFirst = true;
await next();
});
Expand All @@ -1945,7 +1948,7 @@ describe('koa-joi-router', () => {
ctx.body = String(middlewareRanFirst);
});

r.use(async function(ctx, next) {
r.use(async (ctx, next) => {
middlewareRanFirst = true;
await next();
});
Expand All @@ -1965,7 +1968,7 @@ describe('koa-joi-router', () => {
const r = router();
let middlewareRan = false;

r.use('/nada', async function(ctx, next) {
r.use('/nada', async (ctx, next) => {
middlewareRan = true;
await next();
});
Expand Down Expand Up @@ -2000,22 +2003,22 @@ describe('koa-joi-router', () => {

const r = router();

r.use(async function(ctx, next) {
r.use(async (ctx, next) => {
ctx.msg = 'works';
await next();
});

r.get('/', function(ctx) {
r.get('/', (ctx) => {
ctx.body = ctx.msg;
});

r.get('/itworks', function(ctx) {
r.get('/itworks', (ctx) => {
ctx.body = 'it' + ctx.msg;
});

r.get('/testparam/:id', {
validate: { params: { id: Joi.string().min(4) } }
}, function(ctx) {
}, (ctx) => {
ctx.body = `it${ctx.msg}${ctx.params.id}`;
});

Expand Down

0 comments on commit 7e7612e

Please sign in to comment.