mockserver-client
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "mockserver-client", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"homepage": "https://github.com/jamesdbloom/mockserver-client-node", | ||
@@ -5,0 +5,0 @@ "authors": [ |
61
index.js
@@ -29,3 +29,6 @@ /* | ||
path: path, | ||
port: port | ||
port: port, | ||
headers: { | ||
'Content-Type': "application/json; charset=utf-8" | ||
} | ||
}; | ||
@@ -248,6 +251,14 @@ | ||
* | ||
* @param path the path to decide which expectations to cleared | ||
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to | ||
* decide which expectations to cleared, however if an object is passed | ||
* in the value will be treated as a full request matcher object | ||
*/ | ||
var clear = function (path) { | ||
return sendRequest(host, port, "/clear", createResponseMatcher(path || ".*")); | ||
var clear = function (pathOrRequestMatcher) { | ||
if (typeof pathOrRequestMatcher === "string") { | ||
return sendRequest(host, port, "/clear", createResponseMatcher(pathOrRequestMatcher)); | ||
} else if (pathOrRequestMatcher) { | ||
return sendRequest(host, port, "/clear", pathOrRequestMatcher); | ||
} else { | ||
return sendRequest(host, port, "/clear", createResponseMatcher(".*")); | ||
} | ||
}; | ||
@@ -259,6 +270,14 @@ /** | ||
* | ||
* @param path the path to decide which expectations to dump to the log | ||
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to | ||
* decide which expectations to cleared, however if an object is passed | ||
* in the value will be treated as a full request matcher object | ||
*/ | ||
var dumpToLogs = function (path) { | ||
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(path || ".*")); | ||
var dumpToLogs = function (pathOrRequestMatcher) { | ||
if (typeof pathOrRequestMatcher === "string") { | ||
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(pathOrRequestMatcher)); | ||
} else if (pathOrRequestMatcher) { | ||
return sendRequest(host, port, "/dumpToLog", pathOrRequestMatcher); | ||
} else { | ||
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(".*")); | ||
} | ||
}; | ||
@@ -375,6 +394,14 @@ | ||
* | ||
* @param path the path to decide which expectations to cleared | ||
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to | ||
* decide which recorded requests to cleared, however if an object is | ||
* passed in the value will be treated as a full request matcher object | ||
*/ | ||
var clear = function (path) { | ||
return sendRequest(host, port, "/clear", createResponseMatcher(path || ".*")); | ||
var clear = function (pathOrRequestMatcher) { | ||
if (typeof pathOrRequestMatcher === "string") { | ||
return sendRequest(host, port, "/clear", createResponseMatcher(pathOrRequestMatcher)); | ||
} else if (pathOrRequestMatcher) { | ||
return sendRequest(host, port, "/clear", pathOrRequestMatcher); | ||
} else { | ||
return sendRequest(host, port, "/clear", createResponseMatcher(".*")); | ||
} | ||
}; | ||
@@ -385,6 +412,14 @@ /** | ||
* | ||
* @param path the path to decide which expectations to dump to the log | ||
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path to | ||
* decide which recorded requests to cleared, however if an object is | ||
* passed in the value will be treated as a full request matcher object | ||
*/ | ||
var dumpToLogs = function (path) { | ||
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(path || ".*", "")); | ||
var dumpToLogs = function (pathOrRequestMatcher) { | ||
if (typeof pathOrRequestMatcher === "string") { | ||
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(pathOrRequestMatcher)); | ||
} else if (pathOrRequestMatcher) { | ||
return sendRequest(host, port, "/dumpToLog", pathOrRequestMatcher); | ||
} else { | ||
return sendRequest(host, port, "/dumpToLog", createResponseMatcher(".*")); | ||
} | ||
}; | ||
@@ -391,0 +426,0 @@ |
{ | ||
"name": "mockserver-client", | ||
"description": "A node client for the MockServer", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"homepage": "https://github.com/jamesdbloom/mockserver", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -101,2 +101,3 @@ # mockserver-client-node | ||
* 2015-04-06 v1.0.5 Upgrading dependencies | ||
* 2015-06-02 v1.0.6 Improved clear and dumpToLog options | ||
@@ -103,0 +104,0 @@ --- |
@@ -369,3 +369,2 @@ (function () { | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -377,3 +376,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -417,3 +417,2 @@ test.done(); | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -425,3 +424,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -465,3 +465,2 @@ test.done(); | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -473,3 +472,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -482,3 +482,3 @@ test.done(); | ||
'should clear expectations': function (test) { | ||
'should clear expectations by path': function (test) { | ||
// given - a client | ||
@@ -530,2 +530,102 @@ var client = mockServerClient("localhost", 1080); | ||
'should clear expectations by request matcher': function (test) { | ||
// given - a client | ||
var client = mockServerClient("localhost", 1080); | ||
// and - an expectation | ||
client.mockSimpleResponse('/somePathOne', { name: 'value' }, 200).then(function () { | ||
// and - another expectation | ||
client.mockSimpleResponse('/somePathOne', { name: 'value' }, 200).then(function () { | ||
// and - another expectation | ||
client.mockSimpleResponse('/somePathTwo', { name: 'value' }, 200).then(function () { | ||
// and - a matching request (that returns 200) | ||
sendRequest("GET", "localhost", 1080, "/somePathOne") | ||
.then(function (response) { | ||
test.equal(response.statusCode, 200); | ||
test.equal(response.body, '{"name":"value"}'); | ||
}, function (error) { | ||
test.ok(false, error); | ||
}).then(function () { | ||
// when - some expectations cleared | ||
client.clear({ | ||
"path": "/somePathOne" | ||
}).then(function () { | ||
// then - request matching cleared expectation should return 404 | ||
sendRequest("GET", "localhost", 1080, "/somePathOne") | ||
.then(function (response) { | ||
test.ok(false, "should clear matching expectations"); | ||
}, function (error) { | ||
test.equals(404, error); | ||
}).then(function () { | ||
// and - request matching non-cleared expectation should return 200 | ||
sendRequest("GET", "localhost", 1080, "/somePathTwo") | ||
.then(function (response) { | ||
test.equal(response.statusCode, 200); | ||
test.equal(response.body, '{"name":"value"}'); | ||
test.done(); | ||
}, function (error) { | ||
test.ok(false, "should not clear non-matching expectations"); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
'should clear expectations by expectation matcher': function (test) { | ||
// given - a client | ||
var client = mockServerClient("localhost", 1080); | ||
// and - an expectation | ||
client.mockSimpleResponse('/somePathOne', { name: 'value' }, 200).then(function () { | ||
// and - another expectation | ||
client.mockSimpleResponse('/somePathOne', { name: 'value' }, 200).then(function () { | ||
// and - another expectation | ||
client.mockSimpleResponse('/somePathTwo', { name: 'value' }, 200).then(function () { | ||
// and - a matching request (that returns 200) | ||
sendRequest("GET", "localhost", 1080, "/somePathOne") | ||
.then(function (response) { | ||
test.equal(response.statusCode, 200); | ||
test.equal(response.body, '{"name":"value"}'); | ||
}, function (error) { | ||
test.ok(false, error); | ||
}).then(function () { | ||
// when - some expectations cleared | ||
client.clear({ | ||
"httpRequest": { | ||
"path": "/somePathOne" | ||
} | ||
}).then(function () { | ||
// then - request matching cleared expectation should return 404 | ||
sendRequest("GET", "localhost", 1080, "/somePathOne") | ||
.then(function (response) { | ||
test.ok(false, "should clear matching expectations"); | ||
}, function (error) { | ||
test.equals(404, error); | ||
}).then(function () { | ||
// and - request matching non-cleared expectation should return 200 | ||
sendRequest("GET", "localhost", 1080, "/somePathTwo") | ||
.then(function (response) { | ||
test.equal(response.statusCode, 200); | ||
test.equal(response.body, '{"name":"value"}'); | ||
test.done(); | ||
}, function (error) { | ||
test.ok(false, "should not clear non-matching expectations"); | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
'should reset expectations': function (test) { | ||
@@ -532,0 +632,0 @@ // given - a client |
@@ -158,3 +158,2 @@ (function () { | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -166,3 +165,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -202,3 +202,2 @@ }).then(function () { | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -210,3 +209,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -246,3 +246,2 @@ }).then(function () { | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -254,3 +253,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -263,3 +263,3 @@ }).then(function () { | ||
'should clear proxy': function (test) { | ||
'should clear proxy by path': function (test) { | ||
// given - a client | ||
@@ -309,3 +309,2 @@ var client = proxyClient("localhost", 1090); | ||
" \"path\" : \"/someOtherPath\",\n" + | ||
" \"body\" : \"someBody\",\n" + | ||
" \"headers\" : [ {\n" + | ||
@@ -317,3 +316,4 @@ " \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
@@ -345,2 +345,166 @@ }).then(function () { | ||
'should clear proxy by request matcher': function (test) { | ||
// given - a client | ||
var client = proxyClient("localhost", 1090); | ||
// and - a request | ||
sendRequestViaProxy("http://localhost:1080/somePath", "someBody") | ||
.then(function (response) { | ||
test.ok(false, "expecting 404 response"); | ||
}, function (error) { | ||
test.equal(error, 404); | ||
}).then(function () { | ||
// and - another request | ||
sendRequestViaProxy("http://localhost:1080/someOtherPath", "someBody") | ||
.then(function (response) { | ||
test.ok(false, "expecting 404 response"); | ||
}, function (error) { | ||
test.equal(error, 404); | ||
}).then(function () { | ||
// and - a verification that passes | ||
client.verify( | ||
{ | ||
'method': 'POST', | ||
'path': '/somePath', | ||
'body': 'someBody' | ||
}, 1).then(function () { | ||
// when - matching requests cleared | ||
client.clear({ | ||
"path": "/somePath" | ||
}).then(function () { | ||
// then - the verification should fail requests that were cleared | ||
client.verify( | ||
{ | ||
'method': 'POST', | ||
'path': '/somePath', | ||
'body': 'someBody' | ||
}, 1).then(function () { | ||
test.ok(false, "verification should have failed"); | ||
}, function (message) { | ||
test.equals(message, "Request not found at least once, expected:<{\n" + | ||
" \"method\" : \"POST\",\n" + | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}> but was:<{\n" + | ||
" \"method\" : \"POST\",\n" + | ||
" \"path\" : \"/someOtherPath\",\n" + | ||
" \"headers\" : [ {\n" + | ||
" \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"localhost:1080\" ]\n" + | ||
" }, {\n" + | ||
" \"name\" : \"Content-Length\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
}).then(function () { | ||
// then - the verification should pass for other requests | ||
client.verify( | ||
{ | ||
'method': 'POST', | ||
'path': '/someOtherPath', | ||
'body': 'someBody' | ||
}, 1).then(function () { | ||
test.done(); | ||
}, function () { | ||
test.ok(false, "verification should have passed"); | ||
test.done(); | ||
}); | ||
}); | ||
}, function () { | ||
test.ok(false, "client should not fail when resetting"); | ||
}); | ||
}, function () { | ||
test.ok(false, "verification should pass"); | ||
}); | ||
}); | ||
}); | ||
}, | ||
'should clear proxy by expectation matcher': function (test) { | ||
// given - a client | ||
var client = proxyClient("localhost", 1090); | ||
// and - a request | ||
sendRequestViaProxy("http://localhost:1080/somePath", "someBody") | ||
.then(function (response) { | ||
test.ok(false, "expecting 404 response"); | ||
}, function (error) { | ||
test.equal(error, 404); | ||
}).then(function () { | ||
// and - another request | ||
sendRequestViaProxy("http://localhost:1080/someOtherPath", "someBody") | ||
.then(function (response) { | ||
test.ok(false, "expecting 404 response"); | ||
}, function (error) { | ||
test.equal(error, 404); | ||
}).then(function () { | ||
// and - a verification that passes | ||
client.verify( | ||
{ | ||
'method': 'POST', | ||
'path': '/somePath', | ||
'body': 'someBody' | ||
}, 1).then(function () { | ||
// when - matching requests cleared | ||
client.clear({ | ||
"httpRequest": { | ||
"path": "/somePath" | ||
} | ||
}).then(function () { | ||
// then - the verification should fail requests that were cleared | ||
client.verify( | ||
{ | ||
'method': 'POST', | ||
'path': '/somePath', | ||
'body': 'someBody' | ||
}, 1).then(function () { | ||
test.ok(false, "verification should have failed"); | ||
}, function (message) { | ||
test.equals(message, "Request not found at least once, expected:<{\n" + | ||
" \"method\" : \"POST\",\n" + | ||
" \"path\" : \"/somePath\",\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}> but was:<{\n" + | ||
" \"method\" : \"POST\",\n" + | ||
" \"path\" : \"/someOtherPath\",\n" + | ||
" \"headers\" : [ {\n" + | ||
" \"name\" : \"Host\",\n" + | ||
" \"values\" : [ \"localhost:1080\" ]\n" + | ||
" }, {\n" + | ||
" \"name\" : \"Content-Length\",\n" + | ||
" \"values\" : [ \"8\" ]\n" + | ||
" } ],\n" + | ||
" \"body\" : \"someBody\"\n" + | ||
"}>"); | ||
}).then(function () { | ||
// then - the verification should pass for other requests | ||
client.verify( | ||
{ | ||
'method': 'POST', | ||
'path': '/someOtherPath', | ||
'body': 'someBody' | ||
}, 1).then(function () { | ||
test.done(); | ||
}, function () { | ||
test.ok(false, "verification should have passed"); | ||
test.done(); | ||
}); | ||
}); | ||
}, function () { | ||
test.ok(false, "client should not fail when resetting"); | ||
}); | ||
}, function () { | ||
test.ok(false, "verification should pass"); | ||
}); | ||
}); | ||
}); | ||
}, | ||
'should reset proxy': function (test) { | ||
@@ -347,0 +511,0 @@ // given - a client |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
201855
4771
106