Skip to content

Instantly share code, notes, and snippets.

@davidpaulhunt
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save davidpaulhunt/033b4c7d7ca9679179d4 to your computer and use it in GitHub Desktop.

Select an option

Save davidpaulhunt/033b4c7d7ca9679179d4 to your computer and use it in GitHub Desktop.
// Testing API routes
module.exports = vows.describe('Feature > SubFeature').addBatch(setupBatch).addBatch({
'GET /some/specific/url?q=something by User One > Testing SubFeature.0': {
topic: function(){
request.get({
headers: {
authorization: someHelperMethod('userone')
}
, url: urlHelper('/some/specific/url?q=something')
}, resonseParser(this.callback)
}
, '200 with meta and object':
checkResponse({code: 200, keys: ['meta','object']})
, 'object should have keys key1, key2': function(args) {
checkProperties(args, 'object').should.have.keys('key1','key2');
}
}
}).export(module);
// creating a new model using BookshelfJS
var MyCustomModel = module.exports = bookshelf.Model.extend({
tableName: 'table_name'
, hasTimestamps: ['created_at','updated_at']
, parentModel: function() {
return this.belongsTo(CustomParentModel, 'parent_id');
}
});
// add a custom find method using knex() Promise
MyCustomModel.find = function(opts) {
return new MyCustomModel({ id: opts.id }).query(function(qb) {
qb.leftJoin('other_table', 'other_table.something', 'table_name.something');
}).fetch({ require: true }).then(function(results) {
return results.map(function(r) { return r.toAPI(); });
}).catch(CustomError, function(err) {
throw new ThatOtherError(err.message);
}).catch(function(err) {
console.error(err);
throw new TheOtherError("blah blah blah");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment