Commit 44789fb8 authored by nanahira's avatar nanahira
parents 13aa9e94 f14e8715
### 2.2.0
- Add timeout support (#39)
### 2.1.2 ### 2.1.2
- Force escaping of all url params (#34) - Force escaping of all url params (#34)
......
...@@ -294,6 +294,39 @@ const client = challonge.createClient({ ...@@ -294,6 +294,39 @@ const client = challonge.createClient({
<tr>
<td class="name"><code>timeout</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">Duration in ms to wait for a timeout, passed to https request as timeout option</td>
</tr>
<tr> <tr>
<td class="name"><code>massageProperties</code></td> <td class="name"><code>massageProperties</code></td>
...@@ -383,7 +416,7 @@ const client = challonge.createClient({ ...@@ -383,7 +416,7 @@ const client = challonge.createClient({
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -945,7 +945,7 @@ ...@@ -945,7 +945,7 @@
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -1645,7 +1645,7 @@ ...@@ -1645,7 +1645,7 @@
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -2356,7 +2356,7 @@ ...@@ -2356,7 +2356,7 @@
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -48,6 +48,7 @@ const util = require('../util'); ...@@ -48,6 +48,7 @@ const util = require('../util');
* @param {string} options.apiKey Your challonge API Key * @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls. * @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string. * @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true. * @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @description * @description
* Constructor function for the Client base responsible for communicating with Challonge API * Constructor function for the Client base responsible for communicating with Challonge API
...@@ -141,6 +142,11 @@ Client.prototype.makeRequest = function(obj) { ...@@ -141,6 +142,11 @@ Client.prototype.makeRequest = function(obj) {
} }
}; };
const timeout = this.options.get('timeout');
if (timeout) {
options.timeout = timeout;
}
const req = https.request(options, (res) => { const req = https.request(options, (res) => {
// store the chunked data as it comes back // store the chunked data as it comes back
let resData = ''; let resData = '';
...@@ -165,6 +171,13 @@ Client.prototype.makeRequest = function(obj) { ...@@ -165,6 +171,13 @@ Client.prototype.makeRequest = function(obj) {
}); });
}); });
req.on('timeout', () => {
errorHandler.handle({
timeout: true
}, '', callback, self.options.get('format'));
req.destroy();
});
req.end(); req.end();
}; };
</code></pre> </code></pre>
...@@ -179,7 +192,7 @@ Client.prototype.makeRequest = function(obj) { ...@@ -179,7 +192,7 @@ Client.prototype.makeRequest = function(obj) {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -96,6 +96,17 @@ exports.handle = function(res, resData, callback, format) { ...@@ -96,6 +96,17 @@ exports.handle = function(res, resData, callback, format) {
return; return;
} }
if (res.timeout) {
err = {
error: true,
errors: [],
statusCode: 'timeout',
text: ''
};
callback(err, res);
return;
}
// not an api-documented error // not an api-documented error
err = { err = {
error: true, error: true,
...@@ -120,7 +131,7 @@ exports.handle = function(res, resData, callback, format) { ...@@ -120,7 +131,7 @@ exports.handle = function(res, resData, callback, format) {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -160,7 +160,7 @@ Matches.prototype.update = function(obj) { ...@@ -160,7 +160,7 @@ Matches.prototype.update = function(obj) {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -249,7 +249,7 @@ Participants.prototype.randomize = function(obj) { ...@@ -249,7 +249,7 @@ Participants.prototype.randomize = function(obj) {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -361,7 +361,7 @@ Tournaments.prototype.abortCheckIn = function(obj) { ...@@ -361,7 +361,7 @@ Tournaments.prototype.abortCheckIn = function(obj) {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -49,6 +49,7 @@ endpoints.forEach(endpointName => { ...@@ -49,6 +49,7 @@ endpoints.forEach(endpointName => {
* @param {string} options.apiKey Your challonge API Key * @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls. * @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string. * @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true. * @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @returns {object} new api client instance * @returns {object} new api client instance
* @description * @description
...@@ -89,7 +90,7 @@ exports.createClient = function createClient(options) { ...@@ -89,7 +90,7 @@ exports.createClient = function createClient(options) {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -353,6 +353,39 @@ const client = challonge.createClient({ ...@@ -353,6 +353,39 @@ const client = challonge.createClient({
<tr>
<td class="name"><code>timeout</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">Duration in ms to wait for a timeout, passed to https request as timeout option</td>
</tr>
<tr> <tr>
<td class="name"><code>massageProperties</code></td> <td class="name"><code>massageProperties</code></td>
...@@ -450,7 +483,7 @@ const client = challonge.createClient({ ...@@ -450,7 +483,7 @@ const client = challonge.createClient({
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -103,7 +103,7 @@ client.tournaments.create({ ...@@ -103,7 +103,7 @@ client.tournaments.create({
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -366,7 +366,7 @@ ...@@ -366,7 +366,7 @@
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -857,7 +857,7 @@ ...@@ -857,7 +857,7 @@
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -107,7 +107,7 @@ module.exports = serialize; ...@@ -107,7 +107,7 @@ module.exports = serialize;
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -121,7 +121,7 @@ module.exports = { ...@@ -121,7 +121,7 @@ module.exports = {
<br class="clear"> <br class="clear">
<footer> <footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer> </footer>
<script>prettyPrint();</script> <script>prettyPrint();</script>
......
...@@ -9,6 +9,7 @@ const util = require('../util'); ...@@ -9,6 +9,7 @@ const util = require('../util');
* @param {string} options.apiKey Your challonge API Key * @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls. * @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string. * @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true. * @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @description * @description
* Constructor function for the Client base responsible for communicating with Challonge API * Constructor function for the Client base responsible for communicating with Challonge API
...@@ -102,6 +103,11 @@ Client.prototype.makeRequest = function(obj) { ...@@ -102,6 +103,11 @@ Client.prototype.makeRequest = function(obj) {
} }
}; };
const timeout = this.options.get('timeout');
if (timeout) {
options.timeout = timeout;
}
const req = https.request(options, (res) => { const req = https.request(options, (res) => {
// store the chunked data as it comes back // store the chunked data as it comes back
let resData = ''; let resData = '';
...@@ -131,5 +137,12 @@ Client.prototype.makeRequest = function(obj) { ...@@ -131,5 +137,12 @@ Client.prototype.makeRequest = function(obj) {
callback(e, null); callback(e, null);
}); });
req.on('timeout', () => {
errorHandler.handle({
timeout: true
}, '', callback, self.options.get('format'));
req.destroy();
});
req.end(); req.end();
}; };
...@@ -171,6 +171,13 @@ describe('Client Class', () => { ...@@ -171,6 +171,13 @@ describe('Client Class', () => {
expect(opts.cache_bust).toBeDefined(); expect(opts.cache_bust).toBeDefined();
}); });
it('should add a timeout if one is passed', () => {
client.options.timeout = 20000;
client.makeRequest({});
expect(httpsMock.opts.timeout).toEqual(20000);
});
it('should delete the callback, path, and method from the object', () => { it('should delete the callback, path, and method from the object', () => {
client.makeRequest({ client.makeRequest({
callback: '', callback: '',
...@@ -242,6 +249,17 @@ describe('Client Class', () => { ...@@ -242,6 +249,17 @@ describe('Client Class', () => {
}); });
}); });
it('should call the error handler on a timeout', () => {
spyOn(errorHandler, 'handle');
client.makeRequest({});
httpsMock.reqListeners.timeout[0]();
expect(errorHandler.handle).toHaveBeenCalledWith({
timeout: true
}, '', undefined, 'json');
});
it('should call the error handler on anything but a 200 response', () => { it('should call the error handler on anything but a 200 response', () => {
spyOn(errorHandler, 'handle'); spyOn(errorHandler, 'handle');
......
...@@ -57,6 +57,17 @@ exports.handle = function(res, resData, callback, format) { ...@@ -57,6 +57,17 @@ exports.handle = function(res, resData, callback, format) {
return; return;
} }
if (res.timeout) {
err = {
error: true,
errors: [],
statusCode: 'timeout',
text: ''
};
callback(err, res);
return;
}
// not an api-documented error // not an api-documented error
err = { err = {
error: true, error: true,
......
...@@ -46,6 +46,23 @@ describe('error handler', () => { ...@@ -46,6 +46,23 @@ describe('error handler', () => {
}); });
it('should throw the correct error on a timeout', () => {
function cb(err, res) {
expect(err).toEqual({
error: true,
errors: [],
statusCode: 'timeout',
text: ''
});
}
HandleFn({
timeout: true
}, '', cb, 'json');
});
it('should not parse resData if not json type and passed as a 422', () => { it('should not parse resData if not json type and passed as a 422', () => {
function cb(err, res) { function cb(err, res) {
......
...@@ -10,6 +10,7 @@ endpoints.forEach(endpointName => { ...@@ -10,6 +10,7 @@ endpoints.forEach(endpointName => {
* @param {string} options.apiKey Your challonge API Key * @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls. * @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string. * @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true. * @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @returns {object} new api client instance * @returns {object} new api client instance
* @description * @description
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"description": "Wrapper for the challong api", "description": "Wrapper for the challong api",
"author": "Aaron Tiwell <aaron.tidwell@gmail.com>", "author": "Aaron Tiwell <aaron.tidwell@gmail.com>",
"main": "./lib/challonge.js", "main": "./lib/challonge.js",
"version": "2.1.2", "version": "2.2.0",
"contributors": [ "contributors": [
{ {
"name": "Ricardo Reis", "name": "Ricardo Reis",
......
...@@ -6,6 +6,7 @@ mockery.enable({ ...@@ -6,6 +6,7 @@ mockery.enable({
const httpsMock = { const httpsMock = {
reset: function() { reset: function() {
this.reqListeners = {};
this.listeners = {}; this.listeners = {};
this.opts = {}; this.opts = {};
this.res.statusCode = ''; this.res.statusCode = '';
...@@ -13,6 +14,7 @@ const httpsMock = { ...@@ -13,6 +14,7 @@ const httpsMock = {
opts: {}, opts: {},
listeners: { listeners: {
}, },
reqListeners: {},
res: { res: {
on: (method, cb) => { on: (method, cb) => {
if (!httpsMock.listeners[method]) { if (!httpsMock.listeners[method]) {
...@@ -27,6 +29,14 @@ const httpsMock = { ...@@ -27,6 +29,14 @@ const httpsMock = {
return { return {
end: () => { end: () => {
},
destroy: () => {
},
on: (method, cb) => {
if (!httpsMock.reqListeners[method]) {
httpsMock.reqListeners[method] = [];
}
httpsMock.reqListeners[method].push(cb);
} }
}; };
} }
......
Markdown is supported
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