Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add test harness to dispatch #6

Open
pacovell opened this Issue · 0 comments

1 participant

Paul Covell
Paul Covell
Owner

I've added a test harness to my production code that needs to be re-integrated into dispatch:

https://gist.github.com/1311173

It relies on the controllers.js lib file, which may also be reasonable to integrate into dispatch:

https://gist.github.com/1311177

It gets used together with sinon.js in a controller vows test like this:

var Asks = new ControlChain('asks');

function mockFindUser(user) {
    return function () {
        models.User.findById = function (id, callback) {
            callback(null, user);
        };
        sinon.spy(models.User, 'findById');
    };
}

vows.describe('Ask Controller').addBatch({
    'my, user logged in' : {
        topic : Asks.get('my', { session : { currentUserId : '123456789abc' } },
            { before : [ mockFindUser(mockObjects.user), mockFindAsks() ] }),
        'finds user' : function (err, req, res) {
            assert.ok(models.User.findById.calledOnce);
            assert.equal(mockObjects.user.id, models.User.findById.getCall(0).args[0]);
        },
        'finds asks' : function (err, req, res) {
            assert.ok(models.Ask.find.calledOnce);
        },
        'should have status OK' : function (err, req, res) {
            assert.equal(res.statusCode, 200);
        },
        'should have correct return value' : function (err, req, res) {
            assert.deepEqual(mockObjects.asks, JSON.parse(res.body));
        }
    }
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.