Vows.js with Everyauth
Everyauth is a node module that provides "authentication and authorization (password, facebook, & more) for your node.js Connect and Express apps."
We wrote some code to manage logins using it, but ran into some difficulty when testing the controller. Everyauth allows to specify, as parameters, the route, view, and even controller actions that it should use1. Because of this, any calls to the controller action are coming in under the context of everyauth.Â
Normally this wouldn't be an issue, except that everyauth uses promises. The code that we had trouble testing used "this.Promise()" which in dev pointed to everyauth, but in test points to the test runner (which does not have a promise method).Â
The solution was to provide a closure around the controller call. Here's the pseudo code for vows.js tests:
var promiseLib = require("path/to/everyauth/lib/promise.js"); // ... // other test setup // ... vows.describe('Playing with a controller').addBatch({ topic: function() { var topic = this; var user= { data: "test" }; var registerClosure = function(){ this.Promise = function (values) { var prom = new promiseLib(this, values); prom.callback(function(values){ topic.callback('success',values); },this) .errback(function(err){ topic.callback('error',err); },this) .timeback(function(){ topic.callback('timeout'); },this); return prom; }; controller.actionToTest.call(this,user); }; registerClosure(); }, 'it should return true': function(type,value){ assert.strictEqual(type, "success"); assert.strictEqual(value.data, "test"); } });
Links:
1. https://github.com/bnoguchi/everyauth#password-authentication













