Permalink
Browse files

mocha tests working

  • Loading branch information...
1 parent e82b827 commit f61f067b1792f6ce4184e1bb9a0f2b6a0bc91f25 @yesobo committed Dec 12, 2012
Showing with 22 additions and 10 deletions.
  1. +4 −0 daos/mongoHQDao.coffee
  2. +6 −1 daos/mongoHQDao.js
  3. +3 −2 routes.coffee
  4. +6 −4 routes.js
  5. +3 −3 test/mocha_api_test.js
View
@@ -1,5 +1,6 @@
#npm install mongodb
mongodb = require 'mongodb'
+util = require 'util'
###
Use:
@@ -72,6 +73,7 @@ module.exports = class MongoDBConnector
console.log "ERROR!"
callback err, null
else
+ console.log "inserting pattern: #{util.inspect(pattern)}"
collection.insert pattern, (err, doc) ->
callback err, doc
@@ -95,9 +97,11 @@ module.exports = class MongoDBConnector
#call: callback parameters are (err)
delete: (pId, callback) ->
+ console.log "INIT: daoObj delete"
initTransaction.call this, (err, collection) ->
if err?
console.log "ERROR!"
else
+ console.log "removing element with id = #{pId}"
collection.remove id:pId, (err) ->
callback err
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,4 +1,5 @@
DBConnector = require "./daos/mongoHQDao.js"
+util = require 'util'
daoObj = new DBConnector 'design_patterns', 'alex.mongohq.com', 10001
# GET all patterns
@@ -15,7 +16,6 @@ app.get '/api/patterns/count', (req, res) ->
app.get '/api/patterns/:id', (req, res) ->
intId = parseInt req.params.id
daoObj.findById intId, (err, item) ->
- console.log "result: #{item}"
if err?
res.send 500
else
@@ -26,8 +26,9 @@ app.get '/api/patterns/:id', (req, res) ->
# POST a new pattern
app.post '/api/patterns', (req, res) ->
+ intId = parseInt req.body.id
new_pattern =
- id: req.body.id
+ id: intId
name: req.body.name
category: req.body.category
intent: req.body.intent
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -202,17 +202,17 @@ describe('Tests for patterns API, ', function() {
});
describe('Delete pattern with id = 3 test', function() {
- it('should be succesful', function(error, res, body) {
+ it('should be succesful', function(done) {
var post_options = {
- method: 'DEL',
+ method: 'DELETE',
uri: url + '/api/patterns/3',
port: 8010
};
var del_callback = function(error, res, body) {
res.statusCode.should.be.equal(200);
done();
};
- request(post_options, del_callback);
+ request.del(post_options, del_callback);
});
});
});

0 comments on commit f61f067

Please sign in to comment.