Skip to content

Commit

Permalink
Updated with blog post for checking in database
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusoftnet committed May 5, 2015
1 parent febba76 commit bd862b5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "UserApiWithTests",
"version": "0.0.1",
"repository" : "https://github.com/marcusoftnet/UserApiWithTest",
"repository": "https://github.com/marcusoftnet/UserApiWithTest",
"description": "Creating a simple CRUD API starting from tests",
"main": "app.js",
"scripts": {
Expand All @@ -11,15 +11,16 @@
"author": "Marcus Hammarberg",
"license": "BSD-2-Clause",
"devDependencies": {
"mocha": "~1.18.2",
"supertest": "~0.12.1",
"co": "~3.0.6"
"co": "*",
"mocha": "*",
"should": "^6.0.1",
"supertest": "*"
},
"dependencies": {
"koa": "~0.6.1",
"koa-route": "~1.1.4",
"co-monk": "~1.0.0",
"co-body": "0.0.1",
"monk": "~0.9.0"
"co-body": "*",
"co-monk": "*",
"koa": "*",
"koa-route": "*",
"monk": "*"
}
}
3 changes: 2 additions & 1 deletion test/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports.removeAll = function(done){
co(function *(){
yield users.remove({});
// and other things we need to clean up
})(done);
done();
});
};

module.exports.test_user = { name: 'Marcus', city : 'Bandung, Indonesia'};
2 changes: 1 addition & 1 deletion test/user.del.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ describe('DEL to /user/:id', function(){
request
.del(userUrl)
.expect(200, done);
})();
});
});
});
2 changes: 1 addition & 1 deletion test/user.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ describe('GET /user/:id ', function(){
.expect(/Marcus/)
.expect(/Bandung, Indonesia/)
.expect(200, done);
})();
});
});
});
10 changes: 9 additions & 1 deletion test/user.post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var co = require("co");
var should = require("should");
var helpers = require('./testHelpers.js');
var users = helpers.users;
var request = helpers.request;
Expand All @@ -21,7 +23,13 @@ describe('POST to /user', function(){
.post('/user')
.send(test_user)
.expect('location', /^\/user\/[0-9a-fA-F]{24}$/) // Mongo Object Id /user/234234523562512512
.expect(200, done);
.expect(201)
.end(function () {
co(function *() {
var userFromDb = yield users.findOne({ name : test_user.name });
userFromDb.name.should.equal("This is not the name you are looking for");
}).then(done, done);
});
});

it('returns validation error if name is not present', function(done){
Expand Down
2 changes: 1 addition & 1 deletion test/user.update.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ describe('PUT to /user', function(){
.send({name: 'Marcus v2', City: 'Bandung Updated'})
.expect('location', userUrl)
.expect(204, done);
})();
});
});
});
2 changes: 1 addition & 1 deletion userRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports.add = function * () {
var insertedUser = yield users.insert(postedUser);

this.set("location", "/user/" + insertedUser._id);
this.status = 200;
this.status = 201;
};

module.exports.get = function *(id) {
Expand Down

0 comments on commit bd862b5

Please sign in to comment.