Skip to content

Commit

Permalink
Merge pull request #105 from smollweide/develop
Browse files Browse the repository at this point in the history
v0.23.3
  • Loading branch information
smollweide authored Jun 20, 2018
2 parents 49816b6 + 5bd72f5 commit b4707a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
15 changes: 8 additions & 7 deletions lib/controller/MockController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

'use strict';

var nodePath = require('path');
var Utils = require('../Utils');
var extend = require('util')._extend;
var ejs = require('ejs');
Expand Down Expand Up @@ -248,7 +249,7 @@ MockController.prototype = extend(MockController.prototype, {
try {
if (this._setMimeType(options.res, options.expectedResponse.type)) {
// add statusCode defined by filename
var status = this._getHttpStatusFromFileName(options.responseFilePath);
var status = this._getHttpStatusFromFilePath(options.responseFilePath);
if (status && options.res.statusCode === 200) {
options.res.statusCode = status;
}
Expand Down Expand Up @@ -297,7 +298,7 @@ MockController.prototype = extend(MockController.prototype, {

if (outStr) {
// add statusCode defined by filename
var status = this._getHttpStatusFromFileName(options.responseFilePath);
var status = this._getHttpStatusFromFilePath(options.responseFilePath);
if (status && options.res.statusCode === 200) {
options.res.statusCode = status;
}
Expand Down Expand Up @@ -414,7 +415,7 @@ MockController.prototype = extend(MockController.prototype, {
* @private
*/
_sendError: function (options) {
var status = this._getHttpStatusFromFileName(options.expectedResponse.name) || 500;
var status = this._getHttpStatusFromFilePath(options.expectedResponse.name) || 500;

// add statusCode defined by filename
if (options.res.statusCode === 200) {
Expand Down Expand Up @@ -814,13 +815,13 @@ MockController.prototype = extend(MockController.prototype, {
},

/**
* @method _getHttpStatusFromFileName
* @param {string} fileName
* @method _getHttpStatusFromFilePath
* @param {string} filePath - absolute path to file
* @returns {number|void} HTTP status code
* @private
*/
_getHttpStatusFromFileName: function (fileName) {
var reg = (/([\w]+)(-)([0-9]{3})/).exec(fileName);
_getHttpStatusFromFilePath: function (filePath) {
var reg = (/([\w]+)(-)([0-9]{3})/).exec(nodePath.basename(filePath));

if (reg === null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-mock-server",
"version": "0.23.2",
"version": "0.23.3",
"description": "File based Node REST API mock server",
"email": "[email protected]",
"author": "Simon Mollweide <[email protected]>",
Expand Down
16 changes: 16 additions & 0 deletions test/tests-mock-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ module.exports = function(serverOptions, _getFile) {
var pathExpected = './test/expected/mock-server',
baseUrl = serverOptions.urlBase + serverOptions.urlPath;

describe('method _getHttpStatusFromFilePath', function () {
var getStatus = MockController.prototype._getHttpStatusFromFilePath;

it('undefined', function () {
assert.deepEqual(getStatus('/Users/test/projects/node-mock-server/test/../demo/rest/_fallbacks/#/OPTIONS/mock/success.json'), undefined);
});

it('300', function () {
assert.deepEqual(getStatus('/Users/test/projects/node-mock-server/test/../demo/rest/_fallbacks/#/OPTIONS/mock/success-300.json'), 300);
});

it('PR-326', function () {
assert.deepEqual(getStatus('/Users/test/projects/node-mock-server/test/../demo/rest/_fallbacks/#/OPTIONS/mock/PR-326/success.json'), undefined);
});
});

describe('method _getExpectedResponse', function () {

var func = MockController.prototype._getExpectedResponse;
Expand Down

0 comments on commit b4707a9

Please sign in to comment.