Commit de3a911b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

mock ServerConnector ignores undefined query params

parent acb9206b
......@@ -17,6 +17,7 @@ var ServerConnectorMock = OriginalServerConnector;
function replaceAsterisk(str) {
return str.replace(/\*/g, "all").replace(/\:/g, ".");
}
function urlToFileName(url) {
var result = url;
var token = OriginalServerConnector.getSessionData().getToken();
......@@ -32,15 +33,15 @@ function urlToFileName(url) {
function encodeParams(params) {
var result = {};
for ( var key in params) {
if (params.hasOwnProperty(key)) {
for (var key in params) {
if (params.hasOwnProperty(key) && params[key] !== undefined) {
result[key] = encodeURIComponent(params[key]);
}
}
return result;
}
ServerConnectorMock._sendRequest = function(params) {
ServerConnectorMock._sendRequest = function (params) {
var self = this;
var url = params.url;
var prefix = params.method;
......@@ -56,9 +57,9 @@ ServerConnectorMock._sendRequest = function(params) {
if (params.json !== undefined) {
suffix += self.createGetParams(params.json);
}
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
if (url.indexOf("http") === 0) {
request.get(url, function(error, response, body) {
request.get(url, function (error, response, body) {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
......@@ -69,12 +70,12 @@ ServerConnectorMock._sendRequest = function(params) {
});
} else {
var fileName = urlToFileName(url + prefix + suffix);
fs.readFile(fileName, 'utf8', function(err, content) {
fs.readFile(fileName, 'utf8', function (err, content) {
if (err) {
reject(new NetworkError(err.message, {
content : content,
url : fileName,
statusCode : 404
content: content,
url: fileName,
statusCode: 404
}));
} else {
resolve(content);
......@@ -84,13 +85,13 @@ ServerConnectorMock._sendRequest = function(params) {
});
};
ServerConnectorMock.getApiBaseUrl = function() {
ServerConnectorMock.getApiBaseUrl = function () {
return "./testFiles/apiCalls/";
};
var originalGetApiUrl = OriginalServerConnector.getApiUrl;
ServerConnectorMock.getApiUrl = function(paramObj) {
ServerConnectorMock.getApiUrl = function (paramObj) {
// replace '?' with '/'
// the call is done on ServerConnectorObject (so 'this' is set properly)
return originalGetApiUrl.call(this, paramObj).replace(/\?/g, '/');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment