added dpd debug command

This commit is contained in:
Ritchie Martori
2012-07-04 01:16:36 -07:00
parent 666914f4fd
commit c867ce2523
11 changed files with 127 additions and 16 deletions

1
.gitignore vendored
View File

@@ -17,3 +17,4 @@ test/support/proj
test/support/keys.json
bin/mongo
bin/node
examples/test/data

3
bin/dpdebug Executable file
View File

@@ -0,0 +1,3 @@
BASEDIR=$(dirname $0)
node --debug $BASEDIR/dpd $@

View File

@@ -1 +1 @@
{"0630a817ddb9194b":{"path":"/todos","order":1,"typeLabel":"Collection","type":"Collection","$renameFrom":"/todos"},"3f7b9cc9518729e6":{"path":"/users","order":2,"typeLabel":"Users Collection","type":"UserCollection"}}
{"0630a817ddb9194b":{"properties":{"people":{"required":false,"type":"object","typeLabel":"object","id":"people"},"tags":{"required":false,"type":"array","typeLabel":"array","id":"tags"},"owner":{"required":false,"type":"string","typeLabel":"string","id":"owner"},"done":{"required":false,"type":"boolean","typeLabel":"string","id":"done"},"order":{"required":false,"type":"number","typeLabel":"string","id":"order"},"title":{"required":false,"type":"string","typeLabel":"string","id":"title"}},"onGet":"","onPost":"/* Authentication */\n// if (!me || !me.isAdmin) {\n// cancel(\"You must be an admin!\", 401);\n// }\n\n/* Automatic properties */\n// this.creator = me.id;\n// this.creatorName = me.name;\n","onPut":"/* Readonly properties */\n// protect(\"creator\");\n","onDelete":"","onValidate":"/* Validation */\n// if (this.name.length < 10) {\n// error(\"name\", \"Must be at least 10 characters\");\n// }\n","path":"/todos","order":1,"typeLabel":"Collection","type":"Collection","$renameFrom":"/todos"},"3f7b9cc9518729e6":{"path":"/users","order":2,"typeLabel":"Users Collection","type":"UserCollection","$renameFrom":"/users"},"4f78d38ea41398f8":{"path":"/empty","order":3,"typeLabel":"Collection","type":"Collection","$renameFrom":"/empty"},"372b90c73b850933":{"properties":{"array":{"required":false,"type":"array","typeLabel":"array","id":"array"},"object":{"required":false,"type":"object","typeLabel":"object","id":"object"},"date":{"required":false,"type":"date","typeLabel":"date","id":"date"},"boolean":{"required":false,"type":"boolean","typeLabel":"boolean","id":"boolean"},"number":{"required":false,"type":"number","typeLabel":"number","id":"number"},"string":{"required":false,"type":"string","typeLabel":"string","id":"string"}},"onGet":"","onPost":"/* Authentication */\n// if (!me || !me.isAdmin) {\n// cancel(\"You must be an admin!\", 401);\n// }\n\n/* Automatic properties */\n// this.creator = me.id;\n// this.creatorName = me.name;\n","onPut":"/* Readonly properties */\n// protect(\"creator\");\n","onDelete":"","onValidate":"/* Validation */\n// if (this.name.length < 10) {\n// error(\"name\", \"Must be at least 10 characters\");\n// }\n","path":"/full","order":4,"typeLabel":"Collection","type":"Collection"}}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +1 @@
86759
87266

View File

@@ -8,7 +8,9 @@
<script src="chai.js"></script>
<script src="mocha.js"></script>
<script>mocha.setup('bdd')</script>
<!-- -- tests -- -->
<script src="test/collection.js"></script>
<script src="test/user-collection.js"></script>
<script>
expect = chai.expect;
$(function(){

View File

@@ -1,20 +1,56 @@
describe('Collection', function() {
describe('dpd.todos', function() {
it('should exist', function() {
expect(dpd.todos).to.exist;
});
expect(dpd.todos).to.exist
})
describe('.post(query, fn)', function() {
describe('.post({title: \'faux\'}, fn)', function() {
it('should create a todo with an id', function(done) {
dpd.todos.post({title: 'faux'}, function (todo) {
expect(todo.id.length).to.equal(24);
done();
});
});
});
dpd.todos.post({title: 'faux'}, function (todo, err) {
expect(todo.id.length).to.equal(16)
expect(todo.title).to.equal('faux')
expect(err).to.not.exist
done()
})
})
})
describe('.get(query, fn)', function() {
});
});
});
describe('.post({title: 7}, fn)', function() {
it('should sanitize the title due to incorrect type', function(done) {
dpd.todos.post({title: 7}, function (todo, err) {
delete todo.id;
expect(todo).to.eql({done: false});
done()
})
})
})
describe('.get({title: title}, fn)', function() {
it('should return a single result', function(done) {
var title = Math.random().toString();
dpd.todos.post({title: title}, function () {
dpd.todos.get(function (todos, err) {
expect(todos.length).to.equal(1);
done(err);
})
})
})
})
})
afterEach(function (done) {
this.timeout(10000);
dpd.todos.get(function (todos) {
var total = todos.length;
if(total === 0) return done();
todos.forEach(function(todo) {
dpd.todos.del({id: todo.id}, function () {
total--;
if(!total) {
done();
}
})
})
})
})
})

View File

@@ -0,0 +1,64 @@
var credentials = {
email: 'foo@bar.com',
password: '123456'
}
describe('User Collection', function() {
describe('dpd.users', function() {
describe('.post', function() {
it('should create a user', function(done) {
dpd.users.post(credentials, function (user, err) {
expect(user).to.exist;
expect(user.id.length).to.equal(16)
delete user.id;
expect(user).to.eql({email: credentials.email});
done(err);
})
})
})
// describe('.login', function() {
// it('should login a user', function(done) {
// dpd.users.post(credentials, function (user, err) {
// expect(user.id.length).to.equal(16)
// dpd.users.login(credentials, function (session, err) {
// expect(session.id.length).to.equal(128)
// expect(session.uid.length).to.equal(16)
// done(err);
// })
// })
// })
// })
describe('.del({id: \'...\'}, fn)', function() {
it('should remove a user', function(done) {
dpd.users.post(credentials, function (user, err) {
expect(user.id.length).to.equal(16)
dpd.users.del({id: user.id}, function (session, err) {
dpd.users.get({id: user.id}, function (user) {
expect(user).to.not.exist;
done(err);
})
})
})
})
})
})
afterEach(function (done) {
this.timeout(10000);
dpd.users.get(function (users) {
var total = users.length;
if(total === 0) return done();
console.log(total);
users.forEach(function(user) {
dpd.users.del({id: user.id}, function () {
total--;
if(!total) {
done();
}
})
})
})
})
})

View File

@@ -293,6 +293,7 @@ Collection.prototype.execListener = function(method, session, query, item, clien
debug('error when executing %s listener', method, err)
err.message = "Error while executing " + method + " event: " + err.message;
};
debug('%s listener complete', method);
fn(err || errors, item);
});
}
@@ -303,6 +304,10 @@ Collection.prototype.execListener = function(method, session, query, item, clien
err.message = "Error while executing " + method + " event: " + err.message;
debug('error when executing %s listener', method, err);
}
debug('%s listener complete', method);
if(err) {
debug('errored during listener', err);
}
fn(err || errors, item);
});
}