Skip to content

Instantly share code, notes, and snippets.

@marcusoftnet
Created May 7, 2014 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusoftnet/dd41804d0b6bb2dff256 to your computer and use it in GitHub Desktop.
Save marcusoftnet/dd41804d0b6bb2dff256 to your computer and use it in GitHub Desktop.
KoaMongoBlog test update existing post
var app = require('./app.js');
var co = require('co');
var should = require('should');
var request = require('supertest').agent(app.listen());
var posts = require('./blogRoutes.js').posts;
describe('Blog with mongo:', function(){
var removeAll = function(done){
co(function *(){
yield posts.remove({});
})(done);
};
beforeEach(function (done) {
removeAll(done);
});
afterEach(function (done) {
removeAll(done);
});
var test_post = { title: 'A nice title', body : 'Short body. Yeah!'};
it('updates an existing post', function(done){
co(function *(){
var post = yield posts.insert(test_post);
var postUrl = '/post/' + post._id;
request
.post(postUrl)
.send({title: 'Updated title', body: 'Updated body'})
.expect(302)
.expect('location', postUrl);
})(done);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment