Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
add unit tests for mockResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
winniehell committed Mar 4, 2016
1 parent fb3f246 commit 60377ba
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/unit/mock/mockResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var _ = require('lodash'),
beforeEach = require('mocha').beforeEach,
describe = require('mocha').describe,
expect = require('chai').expect,
helpers = require('./helpers'),
it = require('mocha').it,
mock = require('../../../lib/mock');

require('../../fixtures/config');

describe('Mock middleware response setup', function () {
'use strict';

var dummyRouter, mockResponse, request, response;

beforeEach(function () {
dummyRouter = helpers.dummyRouter;
dummyRouter.param = function () {
};
dummyRouter.get = function () {
};
dummyRouter.set = function () {
};
dummyRouter.enabled = function () {
};
dummyRouter.disabled = function () {
};

var dummyDataStore = new helpers.DummyDataStore();
var requestHandlerList = mock({}, dummyRouter, dummyDataStore);
mockResponse = requestHandlerList[0];

request = helpers.createRequest();
request.swagger.operation.responses = {};

response = helpers.createResponse();
response.statusCode = undefined;
});

it('should call next request handler without req.swagger', function (done) {
request.swagger = undefined;
response.on('end', helpers.expectNoResponse(response, done));
mockResponse(request, response, done);
});

it('should call next request handler when mock is disabled', function (done) {
dummyRouter.get = function (key) {
if (key === 'mock') {
return false;
}
};
response.on('end', helpers.expectNoResponse(response, done));
mockResponse(request, response, done);
});

it('should throw TypeError when req.swagger.operation.responses is undefined', function (done) {
response.statusCode = 200;
request.swagger.operation.responses = undefined;
response.on('end', helpers.expectNoResponse(response, done));
expect(function () {
mockResponse(request, response, helpers.createUnexpectedRequestHandler(done));
}).to.throw(TypeError, /Cannot read property '200' of undefined/);
done();
});

it('should foo', function (done) {
response.on('end', helpers.expectNoResponse(response, done));
mockResponse(request, response, done);
});
});

0 comments on commit 60377ba

Please sign in to comment.