Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mockserver-client

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockserver-client - npm Package Compare versions

Comparing version 5.2.2 to 5.2.3

examples/callback_action_examples/package.json

2

examples/add_array_of_expectations/package.json

@@ -9,4 +9,4 @@ {

"dependencies": {
"mockserver-client": "5.2.2"
"mockserver-client": "5.2.3"
}
}

@@ -9,5 +9,5 @@ {

"dependencies": {
"mockserver-client": "5.2.2",
"mockserver-node": "5.2.2"
"mockserver-client": "5.2.3",
"mockserver-node": "5.2.3"
}
}

@@ -9,5 +9,5 @@ {

"dependencies": {
"mockserver-client": "5.2.2",
"mockserver-node": "5.2.2"
"mockserver-client": "5.2.3",
"mockserver-node": "5.2.3"
}
}

@@ -570,2 +570,23 @@ /*

};
/**
* Retrieve logs messages for expectation matching, verification, clearing, etc,
* log messages are filtered by request matcher as follows:
* - use a string value to match on path,
* - use a request matcher object to match on a full request,
* - or use null to retrieve all requests
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path, however
* if an object is passed in the value will be treated as a full request
* matcher object, if null is passed in it will be treated as match all
*/
var retrieveLogMessages = function (pathOrRequestMatcher) {
return {
then: function (sucess, error) {
return makeRequest(host, port, "/retrieve?type=LOGS", addDefaultRequestMatcherHeaders(pathOrRequestMatcher))
.then(function (result) {
sucess(result.body && result.body.split("------------------------------------"));
});
}
};
};

@@ -583,3 +604,4 @@ var _this = {

retrieveActiveExpectations: retrieveActiveExpectations,
retrieveRecordedExpectations: retrieveRecordedExpectations
retrieveRecordedExpectations: retrieveRecordedExpectations,
retrieveLogMessages: retrieveLogMessages
};

@@ -586,0 +608,0 @@ return _this;

{
"name": "mockserver-client",
"description": "A node client for the MockServer",
"version": "5.2.2",
"version": "5.2.3",
"homepage": "https://github.com/jamesdbloom/mockserver",

@@ -40,3 +40,3 @@ "author": {

"karma-xvfb-chrome-launcher": "0.0.1",
"mockserver-node": "5.2.2",
"mockserver-node": "5.2.3",
"nodeunit": "~0.11"

@@ -43,0 +43,0 @@ },

@@ -224,2 +224,23 @@ /*

};
/**
* Retrieve logs messages for expectation matching, verification, clearing, etc,
* log messages are filtered by request matcher as follows:
* - use a string value to match on path,
* - use a request matcher object to match on a full request,
* - or use null to retrieve all requests
*
* @param pathOrRequestMatcher if a string is passed in the value will be treated as the path, however
* if an object is passed in the value will be treated as a full request
* matcher object, if null is passed in it will be treated as match all
*/
var retrieveLogMessages = function (pathOrRequestMatcher) {
return {
then: function (sucess, error) {
return makeRequest(host, port, "/retrieve?type=LOGS", addDefaultRequestMatcherHeaders(pathOrRequestMatcher))
.then(function (result) {
sucess(result.body && result.body.split("------------------------------------"));
});
}
};
};

@@ -232,3 +253,4 @@ var _this = {

retrieveRecordedRequests: retrieveRecordedRequests,
retrieveRecordedExpectations: retrieveRecordedExpectations
retrieveRecordedExpectations: retrieveRecordedExpectations,
retrieveLogMessages: retrieveLogMessages
};

@@ -235,0 +257,0 @@ return _this;

@@ -177,2 +177,3 @@ # mockserver-client-node

2017-12-12 | v5.2.2 | Fixed incorrect error format 5.2.2
2017-12-18 | v5.2.3  | Added retrieveLogs + upgrade to 5.2.3

@@ -179,0 +180,0 @@ ---

@@ -465,3 +465,3 @@ if ((typeof __karma__ !== 'undefined' ? __karma__.config.mode === 'with_proxy' : window.location.href.indexOf('proxy=true') !== -1)) {

it("should retrieve some requests using object matcher", function (done) {
it("should retrieve some recorded recorded requests using object matcher", function (done) {
// given

@@ -532,3 +532,3 @@ var client = mockServerClient("localhost", mockServerPort);

it("should retrieve some requests using path", function (done) {
it("should retrieve some recorded requests using path", function (done) {
// given

@@ -535,0 +535,0 @@ var client = mockServerClient("localhost", mockServerPort);

(function () {
'use strict';
'use strict';
var mockServer = require('../../');
var mockServerClient = mockServer.mockServerClient;
var proxyClient = mockServer.proxyClient;
var Q = require('q');
var http = require('http');
var mockServerPort = 1080;
var proxyPort = 1090;
var mockServer = require('../../');
var mockServerClient = mockServer.mockServerClient;
var proxyClient = mockServer.proxyClient;
var Q = require('q');
var http = require('http');
var mockServerPort = 1080;
var proxyPort = 1090;
function sendRequestViaProxy(destinationUrl, jsonBody, method) {
var deferred = Q.defer();
function sendRequestViaProxy(destinationUrl, jsonBody, method) {
var deferred = Q.defer();
var body = (typeof jsonBody === "string" ? jsonBody : JSON.stringify(jsonBody || ""));
var options = {
method: method || "POST",
host: "localhost",
port: proxyPort,
headers: {
Host: "localhost:" + mockServerPort,
Connection: "keep-alive"
},
path: destinationUrl
};
var body = (typeof jsonBody === "string" ? jsonBody : JSON.stringify(jsonBody || ""));
var options = {
method: method || "POST",
host: "localhost",
port: proxyPort,
headers: {
Host: "localhost:" + mockServerPort,
Connection: "keep-alive"
},
path: destinationUrl
};
var callback = function (response) {
var data = '';
var callback = function (response) {
var data = '';
response.on('data', function (chunk) {
data += chunk;
});
response.on('data', function (chunk) {
data += chunk;
});
response.on('end', function () {
if (response.statusCode >= 400 && response.statusCode < 600) {
if (response.statusCode === 404) {
deferred.reject("404 Not Found");
} else {
deferred.reject(data);
}
} else {
deferred.resolve({
statusCode: response.statusCode,
headers: response.headers,
body: data
});
}
});
};
var req = http.request(options, callback);
if (options.method === "POST") {
req.write(body);
response.on('end', function () {
if (response.statusCode >= 400 && response.statusCode < 600) {
if (response.statusCode === 404) {
deferred.reject("404 Not Found");
} else {
deferred.reject(data);
}
} else {
deferred.resolve({
statusCode: response.statusCode,
headers: response.headers,
body: data
});
}
req.end();
});
};
return deferred.promise;
var req = http.request(options, callback);
if (options.method === "POST") {
req.write(body);
}
req.end();
var fail = function (test) {
return function (error) {
test.ok(false, "failed with the following error \n" + error);
test.done();
};
return deferred.promise;
}
var fail = function (test) {
return function (error) {
test.ok(false, "failed with the following error \n" + error);
test.done();
};
};
exports.proxy_client_node_test = {
setUp: function (callback) {
mockServerClient("localhost", mockServerPort).reset().then(function () {
proxyClient("localhost", proxyPort).reset().then(function () {
callback();
}, function (error) {
throw 'Failed with error ' + JSON.stringify(error);
});
}, function (error) {
throw 'Failed with error ' + JSON.stringify(error);
exports.proxy_client_node_test = {
setUp: function (callback) {
mockServerClient("localhost", mockServerPort).reset().then(function () {
proxyClient("localhost", proxyPort).reset().then(function () {
callback();
}, function (error) {
throw 'Failed with error ' + JSON.stringify(error);
});
}, function (error) {
throw 'Failed with error ' + JSON.stringify(error);
});
},
'should verify exact number of requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - a verification that passes
client.verify(
{
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 2, true).then(function () {
test.done();
}, fail(test));
});
},
});
},
'should verify exact number of requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should verify at least a number of requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - a verification that passes
client.verify(
{
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 2, true).then(function () {
test.done();
}, fail(test));
});
});
},
// and - a verification that passes
client.verify(
{
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1).then(function () {
test.done();
}, fail(test));
});
});
},
'should verify at least a number of requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
'should fail when no requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when - a verification that should fail
client.verify(
{
'path': '/someOtherPath'
}, 1)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"path\" : \"/someOtherPath\"\n" +
"}> but was:<{\n"));
test.done();
});
});
},
'should fail when not enough exact requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when - a verification that should fail
client.verify(
{
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 2, true)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found exactly 2 times, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
test.done();
});
});
},
'should fail when not enough at least requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when - a verification that should fail
client.verify(
{
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 2)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least 2 times, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
test.done();
});
});
},
'should pass when correct sequence of requests have been sent': function (test) {
// given
var client = proxyClient("localhost", mockServerPort);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/one", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/two", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/three", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
test.equal(error, "404 Not Found");
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - a verification that passes
client.verify(
{
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1).then(function () {
test.done();
}, fail(test));
});
// when
client.verifySequence(
{
'method': 'POST',
'path': '/one',
'body': 'someBody'
},
{
'method': 'GET',
'path': '/two'
},
{
'method': 'GET',
'path': '/three'
}
).then(function () {
test.done();
}, fail(test));
});
},
});
});
'should fail when no requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
},
'should fail when incorrect sequence of requests have been sent': function (test) {
// given
var client = proxyClient("localhost", mockServerPort);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/one", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/two", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/three", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
test.equal(error, "404 Not Found");
// when - a verification that should fail
client.verify(
// when - wrong order
client.verifySequence({
'method': 'POST',
'path': '/one',
'body': 'someBody'
},
{
'method': 'GET',
'path': '/three'
},
{
'method': 'GET',
'path': '/two'
})
.then(fail(test), function () {
// when - first request incorrect body
client.verifySequence({
'method': 'POST',
'path': '/one',
'body': 'some_incorrect_body'
},
{
'path': '/someOtherPath'
}, 1)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"path\" : \"/someOtherPath\"\n" +
"}> but was:<{\n"));
test.done();
'method': 'GET',
'path': '/two'
},
{
'method': 'GET',
'path': '/three'
})
.then(fail(test), function () {
test.done();
});
});
});
},
});
});
'should fail when not enough exact requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
},
// when - a verification that should fail
client.verify(
{
'should clear proxy by path': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - a verification that passes
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(function () {
// when - matching requests cleared
client.clear('/somePath')
.then(function () {
// then - the verification should fail requests that were cleared
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
// then - the verification should pass for other requests
client.verify({
'method': 'POST',
'path': '/somePath',
'path': '/someOtherPath',
'body': 'someBody'
}, 2, true)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found exactly 2 times, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
test.done();
}, 1)
.then(function () {
test.ok(true, "verification has passed");
test.done();
}, fail(test));
});
});
},
}, fail(test));
}, fail(test));
});
});
},
'should fail when not enough at least requests have been sent': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should clear proxy by request matcher': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when - a verification that should fail
client.verify(
{
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// 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(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
// then - the verification should pass for other requests
client.verify({
'method': 'POST',
'path': '/somePath',
'path': '/someOtherPath',
'body': 'someBody'
}, 2)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least 2 times, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
test.done();
}, 1)
.then(function () {
test.done();
}, fail(test));
});
});
},
}, fail(test));
}, fail(test));
});
});
},
'should pass when correct sequence of requests have been sent': function (test) {
// given
var client = proxyClient("localhost", mockServerPort);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/one", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/two", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/three", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should clear proxy by expectation matcher': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when
client.verifySequence(
{
'method': 'POST',
'path': '/one',
'body': 'someBody'
},
{
'method': 'GET',
'path': '/two'
},
{
'method': 'GET',
'path': '/three'
}
).then(function () {
test.done();
}, fail(test));
});
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// 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(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
// then - the verification should pass for other requests
client.verify({
'method': 'POST',
'path': '/someOtherPath',
'body': 'someBody'
}, 1)
.then(function () {
test.done();
}, fail(test));
});
});
}, fail(test));
}, fail(test));
});
});
},
},
'should reset proxy': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should fail when incorrect sequence of requests have been sent': function (test) {
// given
var client = proxyClient("localhost", mockServerPort);
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/one", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - a verification that passes
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(function () {
// when - all recorded requests reset
client.reset()
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/two", undefined, "GET")
// then - the verification should fail
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
test.equals(error, "Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<>");
test.done();
});
}, fail(test));
}, fail(test));
});
});
},
sendRequestViaProxy("http://localhost:" + mockServerPort + "/three", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should retrieve some recorded requests using object matcher': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathTwo', {name: 'two'}, 202)
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
// when - wrong order
client.verifySequence({
'method': 'POST',
'path': '/one',
'body': 'someBody'
},
{
'method': 'GET',
'path': '/three'
},
{
'method': 'GET',
'path': '/two'
})
.then(fail(test), function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 201);
// when - first request incorrect body
client.verifySequence({
'method': 'POST',
'path': '/one',
'body': 'some_incorrect_body'
},
{
'method': 'GET',
'path': '/two'
},
{
'method': 'GET',
'path': '/three'
})
.then(fail(test), function () {
test.done();
});
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
});
});
});
});
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathTwo", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 202);
},
// when
proxyClient("localhost", proxyPort)
.retrieveRecordedRequests({
"httpRequest": {
"path": "/somePathOne"
}
})
.then(function (requests) {
'should clear proxy by path': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// then
test.equal(requests.length, 2);
// first request
test.equal(requests[0].path, '/somePathOne');
test.equal(requests[0].method, 'POST');
test.equal(requests[0].body, 'someBody');
// second request
test.equal(requests[1].path, '/somePathOne');
test.equal(requests[1].method, 'GET');
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
test.done();
}, fail(test));
}, fail(test));
});
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
},
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should retrieve some recorded requests using path': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathTwo', {name: 'two'}, 202)
.then(function () {
// and - a verification that passes
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(function () {
// when - matching requests cleared
client.clear('/somePath')
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
// then - the verification should fail requests that were cleared
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
// then - the verification should pass for other requests
client.verify({
'method': 'POST',
'path': '/someOtherPath',
'body': 'someBody'
}, 1)
.then(function () {
test.ok(true, "verification has passed");
test.done();
}, fail(test));
});
}, fail(test));
}, fail(test));
});
});
},
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 201);
'should clear proxy by request matcher': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathTwo", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 202);
// 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 () {
// when
proxyClient("localhost", proxyPort)
.retrieveRecordedRequests("/somePathOne")
.then(function (requests) {
// then - the verification should fail requests that were cleared
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
// then - the verification should pass for other requests
client.verify({
'method': 'POST',
'path': '/someOtherPath',
'body': 'someBody'
}, 1)
.then(function () {
test.done();
}, fail(test));
});
}, fail(test));
// then
test.equal(requests.length, 2);
// first request
test.equal(requests[0].path, '/somePathOne');
test.equal(requests[0].method, 'POST');
test.equal(requests[0].body, 'someBody');
// second request
test.equal(requests[1].path, '/somePathOne');
test.equal(requests[1].method, 'GET');
test.done();
}, fail(test));
}, fail(test));
});
});
},
}, fail(test));
}, fail(test));
}, fail(test));
'should clear proxy by expectation matcher': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
}, fail(test));
}, fail(test));
}, fail(test));
},
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/someOtherPath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should retrieve some recorded expectations using object matcher': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathTwo', {name: 'two'}, 202)
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
// 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 () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 201);
// then - the verification should fail requests that were cleared
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(fail(test), function (message) {
test.ok(message.startsWith("Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<{\n"));
// then - the verification should pass for other requests
client.verify({
'method': 'POST',
'path': '/someOtherPath',
'body': 'someBody'
}, 1)
.then(function () {
test.done();
}, fail(test));
});
}, fail(test));
}, fail(test));
});
});
},
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
'should reset proxy': function (test) {
// given - a client
var client = proxyClient("localhost", proxyPort);
// and - a request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathTwo", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 202);
// and - another request
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePath", "someBody")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when
proxyClient("localhost", proxyPort)
.retrieveRecordedExpectations({
"httpRequest": {
"path": "/somePathOne"
}
})
.then(function (expectations) {
// and - a verification that passes
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(function () {
// when - all recorded requests reset
client.reset()
.then(function () {
// then
test.equal(expectations.length, 2);
// first expectation
test.equal(expectations[0].httpRequest.path, '/somePathOne');
test.equal(expectations[0].httpRequest.method, 'POST');
test.equal(expectations[0].httpRequest.body, 'someBody');
test.equal(expectations[0].httpResponse.body, '{"name":"one"}');
test.equal(expectations[0].httpResponse.statusCode, 201);
// second expectation
test.equal(expectations[1].httpRequest.path, '/somePathOne');
test.equal(expectations[1].httpRequest.method, 'GET');
test.equal(expectations[0].httpResponse.body, '{"name":"one"}');
test.equal(expectations[0].httpResponse.statusCode, 201);
// then - the verification should fail
client.verify({
'method': 'POST',
'path': '/somePath',
'body': 'someBody'
}, 1)
.then(fail(test), function (error) {
test.equals(error, "Request not found at least once, expected:<{\n" +
" \"method\" : \"POST\",\n" +
" \"path\" : \"/somePath\",\n" +
" \"body\" : \"someBody\"\n" +
"}> but was:<>");
test.done();
});
}, fail(test));
test.done();
}, fail(test));
}, fail(test));
});
});
},
});
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
},
'should retrieve some requests using object matcher': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
'should retrieve some recorded expectations using path': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathTwo', {name: 'two'}, 202)
.then(function () {
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathTwo', {name: 'two'}, 202)
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathTwo", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 202);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when
client.retrieveRecordedRequests({
"httpRequest": {
"path": "/somePathOne"
}
}).then(function (requests) {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathTwo", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 202);
// then
test.equal(requests.length, 2);
// first request
test.equal(requests[0].path, '/somePathOne');
test.equal(requests[0].method, 'POST');
test.equal(requests[0].body, 'someBody');
// second request
test.equal(requests[1].path, '/somePathOne');
test.equal(requests[1].method, 'GET');
// when
proxyClient("localhost", proxyPort)
.retrieveRecordedExpectations("/somePathOne")
.then(function (expectations) {
test.done();
}, fail(test));
}, fail(test));
});
}, fail(test));
}, fail(test));
// then
test.equal(expectations.length, 2);
// first expectation
test.equal(expectations[0].httpRequest.path, '/somePathOne');
test.equal(expectations[0].httpRequest.method, 'POST');
test.equal(expectations[0].httpRequest.body, 'someBody');
test.equal(expectations[0].httpResponse.body, '{"name":"one"}');
test.equal(expectations[0].httpResponse.statusCode, 201);
// second expectation
test.equal(expectations[1].httpRequest.path, '/somePathOne');
test.equal(expectations[1].httpRequest.method, 'GET');
test.equal(expectations[0].httpResponse.body, '{"name":"one"}');
test.equal(expectations[0].httpResponse.statusCode, 201);
test.done();
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
},
}, fail(test));
}, fail(test));
},
'should retrieve some requests using path': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
client.mockSimpleResponse('/somePathTwo', {name: 'two'}, 202)
.then(function () {
'should retrieve some logs using object matcher': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathTwo", undefined, "GET")
.then(function (response) {
test.equal(response.statusCode, 202);
// when
proxyClient("localhost", proxyPort)
.retrieveLogMessages({
"httpRequest": {
"path": "/somePathOne"
}
})
.then(function (expectations) {
// when
proxyClient("localhost", proxyPort).retrieveRecordedRequests("/somePathOne")
.then(function (requests) {
// then
test.equal(expectations.length, 3);
// then
test.equal(requests.length, 2);
// first request
test.equal(requests[0].path, '/somePathOne');
test.equal(requests[0].method, 'POST');
test.equal(requests[0].body, 'someBody');
// second request
test.equal(requests[1].path, '/somePathOne');
test.equal(requests[1].method, 'GET');
test.equal(expectations[0], 'resetting all expectations and request logs');
test.ok(expectations[1].startsWith('\n' +
'returning response:\n' +
'\n' +
'\t{\n' +
'\t "statusCode" : 201,\n' +
'\t "headers"'));
test.equal(expectations[2], '\n' +
'retrieving logs that match:\n' +
'\n' +
'\t{\n' +
'\t "path" : "/somePathOne"\n' +
'\t}\n' +
'\n');
test.done();
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
test.done();
}, fail(test));
}, fail(test));
}, fail(test));
}, fail(test));
},
}, fail(test));
}, fail(test));
'should retrieve some logs using using path': function (test) {
// given
var client = mockServerClient("localhost", mockServerPort);
client.mockSimpleResponse('/somePathOne', {name: 'one'}, 201)
.then(function () {
sendRequestViaProxy("http://localhost:" + mockServerPort + "/somePathOne", "someBody")
.then(function (response) {
test.equal(response.statusCode, 201);
sendRequestViaProxy("http://localhost:" + mockServerPort + "/notFound", undefined, "GET")
.then(fail(test), function (error) {
test.equal(error, "404 Not Found");
// when
proxyClient("localhost", proxyPort)
.retrieveLogMessages("/somePathOne")
.then(function (expectations) {
// then
test.equal(expectations.length, 3);
test.equal(expectations[0], 'resetting all expectations and request logs');
test.ok(expectations[1].startsWith('\n' +
'returning response:\n' +
'\n' +
'\t{\n' +
'\t "statusCode" : 201,\n' +
'\t "headers"'));
test.equal(expectations[2], '\n' +
'retrieving logs that match:\n' +
'\n' +
'\t{\n' +
'\t "path" : "/somePathOne"\n' +
'\t}\n' +
'\n');
test.done();
}, fail(test));
}, fail(test));
}
};
}, fail(test));
}, fail(test));
}
};
})();

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc