Skip to content

Commit

Permalink
Merge pull request #80 from warmachine64/master
Browse files Browse the repository at this point in the history
Added a mock method to deal with POST requests and created a wrapper for MSL
  • Loading branch information
warmachine64 authored May 17, 2017
2 parents 9f70c3c + 4d27117 commit 89e5551
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 460 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.idea
3 changes: 3 additions & 0 deletions msl-client-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
},
{
"name": "Jake Sheppard"
},
{
"name": "Liusongsen Yang"
}
],
"repository": [{
Expand Down
23 changes: 23 additions & 0 deletions msl-client-node/mockapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ exports.setMockRespond = function(server, port, configurations)
}


/**
* Method to register mock POST response. Once you register, whenever server receives a request matching
* the registered requestPath, it will respond with a fake response
*
* @param server => url of web-server.js running on node
* @param port => port number of web-server.js running on node
* @param configurations => Json object that contains the requestPath, requestJSONBody, contentType, responseText, delayTime, headers, function.
**/
exports.setMockPOSTRespond = function(server, port, configurations)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
if(configurations['eval'] !== undefined && typeof configurations['eval'] === 'function')
{
configurations['eval'] = configurations['eval'].toString();
}

xmlHttp.open( 'POST', 'http://' + server + ':' + port + '/mock/fakePOSTrespond', true );
xmlHttp.setRequestHeader('Content-Type', 'application/json');
xmlHttp.send(JSON.stringify(configurations));
};


/**
* Method to register a template to be used when mocking responses. Once registered, pass the same id
* used to register the template along with a map containing the key-value pairs that are to be replaced.
Expand Down
7 changes: 4 additions & 3 deletions msl-client-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
"xhr2":"0.0.7"
},
"devDependencies": {
"msl-server": "~1.0.11"
"msl-server": "~1.1"
},
"author": [
"Daniel Koo <[email protected]>",
"Bryan Robbins <[email protected]>",
"Chien-Hung Kuo <[email protected]>",
"Jake Sheppard <[email protected]>"
"Jake Sheppard <[email protected]>",
"Liusongsen Yang <[email protected]>"
],
"main": "mockapi.js",
"bin": {},
"engines": {
"node": "~0.10"
},
"version": "1.0.5",
"version": "1.1",
"readmeFilename": "README.md",
"license": "Apache 2.0"
}
2 changes: 1 addition & 1 deletion msl-server-node/bin/msl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('../web-server');
require('../web-server')();
Loading

0 comments on commit 89e5551

Please sign in to comment.