Skip to content

Commit

Permalink
update ava and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Nov 24, 2015
1 parent a6c9abb commit 705fe78
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 89 deletions.
3 changes: 1 addition & 2 deletions config/passport/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

const mongoose = require('mongoose');
const LocalStrategy = require('passport-local').Strategy;
const config = require('../config');
const User = mongoose.model('User');

/**
Expand All @@ -23,7 +22,7 @@ module.exports = new LocalStrategy({
select: 'name username email hashed_password salt'
};
User.load(options, function (err, user) {
if (err) return done(err)
if (err) return done(err);
if (!user) {
return done(null, false, { message: 'Unknown user' });
}
Expand Down
2 changes: 1 addition & 1 deletion config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module.exports = function (app, passport) {
return next();
}

console.error(err.stack);
// console.error(err.stack);

if (err.stack.includes('ValidationError')) {
res.status(422).render('422', { error: err.stack });
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"express": "~4.13.3",
"express-session": "~1.12.1",
"forever": "~0.15.1",
"imager": "~1.0.0-alpha1",
"method-override": "~2.3.5",
"mongoose": "~4.2.7",
"morgan": "~1.6.1",
Expand All @@ -55,7 +54,7 @@
"winston": "~2.1.1"
},
"devDependencies": {
"ava": "~0.5.0",
"ava": "~0.6.0",
"nodemon": "*",
"supertest": "*"
}
Expand Down
54 changes: 0 additions & 54 deletions test/_test-articles-get.js

This file was deleted.

44 changes: 17 additions & 27 deletions test/test-articles-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const app = require('../server');
const cleanup = require('./helper').cleanup;
const User = mongoose.model('User');
const Article = mongoose.model('Article');
const agent = request.agent(app);

const _user = {
email: '[email protected]',
Expand All @@ -21,32 +22,23 @@ const _user = {


test.before(cleanup);
test.beforeEach(cleanup);


// user login
test.beforeEach(async t => {
const ctx = global.Promise.defer();
const agent = request.agent(app);
test.before(async t => {
const user = new User(_user);
return await user.save(t.end);
});

user.save().then(() => {
agent
.post('/users/session')
.field('email', _user.email)
.field('password', _user.password)
.expect('Location', '/')
.expect('Content-Type', /text/)
.end((err, res) => {
ctx.resolve(res.headers['set-cookie']);
});
});

t.context.agent = agent;
t.context.cookie = await ctx.promise;
t.end();
test.beforeEach(t => {
agent
.post('/users/session')
.field('email', _user.email)
.field('password', _user.password)
.expect('Location', '/')
.expect('Content-Type', /text/)
.end(t.end);
});

test.after(cleanup);


test('POST /articles - when not logged in - should redirect to /login', t => {
request(app)
Expand All @@ -60,13 +52,12 @@ test('POST /articles - when not logged in - should redirect to /login', t => {


test('POST /articles - invalid form - should respond with error', t => {
t.context.agent
agent
.post('/articles')
.field('title', '')
.field('body', 'foo')
.set('cookie', t.context.cookie)
.expect('Content-Type', /text/)
.expect(302)
.expect(422)
.expect(/Article title cannot be blank/)
.end(async err => {
const count = await Article.count().exec();
Expand All @@ -78,11 +69,10 @@ test('POST /articles - invalid form - should respond with error', t => {


test('POST /articles - valid form - should redirect to the new article page', t => {
t.context.agent
agent
.post('/articles')
.field('title', 'foo')
.field('body', 'bar')
.set('cookie', t.context.cookie)
.expect('Content-Type', /plain/)
.expect('Location', /\/articles\//)
.expect(302)
Expand Down
5 changes: 2 additions & 3 deletions test/_test-users-create.js → test/test-users-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const app = require('../server');
const cleanup = require('./helper').cleanup;
const User = mongoose.model('User');

test.beforeEach(cleanup);
test.before(cleanup);
test.after(cleanup);

test('no email - should respond with errors', t => {
request(app)
Expand Down Expand Up @@ -68,5 +69,3 @@ test('valid signup - should redirect to /', t => {
t.end();
});
});

test.afterEach(cleanup);

0 comments on commit 705fe78

Please sign in to comment.