Skip to content

Commit

Permalink
Merge pull request koajs#88 from bananaappletw/master
Browse files Browse the repository at this point in the history
Update co-views to fix swig cache problem and add test for blog
  • Loading branch information
hemanth authored Oct 8, 2016
2 parents dac6730 + 88b4ac2 commit 1cbbfa7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
6 changes: 3 additions & 3 deletions blog/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var logger = require('koa-logger');
var route = require('koa-route');
var parse = require('co-body');
var koa = require('koa');
var app = koa();
var app = module.exports = koa();

// "database"

Expand Down Expand Up @@ -67,5 +67,5 @@ function *create() {

// listen

app.listen(3000);
console.log('listening on port 3000');
if (!module.parent) app.listen(3000);

56 changes: 56 additions & 0 deletions blog/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());

describe('Blog', function(){
describe('GET /',function(){
it('should see title "Posts"', function(done){
request
.get('/')
.expect(200, function(err, res){
if (err) return done(err);

res.should.be.html;
res.text.should.include('<title>Posts</title>');
done();
});
});
it('should see 0 post', function(done){
request
.get('/')
.expect(200, function(err, res){
if (err) return done(err);

res.should.be.html;
res.text.should.include('<p>You have <strong>0</strong> posts!</p>');
done();
});
});
});
describe('POST /post/new',function(){
it('should create post and redirect to /', function(done){
request
.post('/post')
.send({title: 'Title', body: 'Contents'})
.end(function(err, res){
if (err) return done(err);

res.header.location.should.be.equal('/')
done();
});
});
});
describe('GET /post/0',function(){
it('should see post', function(done){
request
.get('/post/0')
.expect(200, function(err, res){
if (err) return done(err);

res.should.be.html;
res.text.should.include('<h1>Title</h1>')
res.text.should.include('<p>Contents</p>')
done();
});
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"co-body": "^1.0.0",
"co-busboy": "^1.0.2",
"co-fs": "^1.2.0",
"co-views": "^0.2.0",
"co-views": "^2.1.0",
"ejs": "^1.0.0",
"koa": "^1.0.0",
"koa-basic-auth": "^1.1.1",
Expand Down

0 comments on commit 1cbbfa7

Please sign in to comment.