From 54e367d04a4be1d56cef2ae4fbf21a291c32c47c Mon Sep 17 00:00:00 2001 From: Baptiste Mathus Date: Tue, 17 Jul 2018 13:48:50 +0200 Subject: [PATCH 1/6] Add an options.verboseLogging option to enable/disable logging --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 9a0d509..8471517 100644 --- a/index.js +++ b/index.js @@ -5,13 +5,17 @@ const logger = require('./modules/logger')('request-promise-retry'); class rpRetry { static _rpRetry(options) { - logger.info(`calling ${options.uri} with retry ${options.retry}`); + if(options.verboseLogging) { + logger.info(`calling ${options.uri} with retry ${options.retry}`); + } const tries = options.retry || 1; delete options.retry; const fetchDataWithRetry = tryCount => { return requestPromise(options) .then(result => { - logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + if(options.verboseLogging) { + logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + } return Promise.resolve(result); }) .catch(err => { @@ -27,10 +31,14 @@ class rpRetry { } static _rp(options) { - logger.info(`calling ${options.uri} without retries`); + if(options.verboseLogging) { + logger.info(`calling ${options.uri} without retries`); + } return requestPromise(options) .then(result => { - logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + if(options.verboseLogging) { + logger.info(`Result obtained for ${options.method} request to ${options.uri}`); + } return Promise.resolve(result); }) .catch(err => { From 99d11bb51303aa1e7b8e639f9d8368f39e82dff2 Mon Sep 17 00:00:00 2001 From: Baptiste Mathus Date: Tue, 17 Jul 2018 13:59:34 +0200 Subject: [PATCH 2/6] Add test coverage --- test/index.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index 68d8cd7..c18eb35 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -15,11 +15,22 @@ const optionsWithRetry = { method: 'GET', retry: 4 }; +const optionsWithRetryAndLogging = { + uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', + method: 'GET', + verboseLogging: true, + retry: 4 +}; const optionsWithoutRetry = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', method: 'GET' }; +const optionsWithoutRetryWithLogging = { + uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', + method: 'GET', + verboseLogging: true +}; const optionsBadRetry1 = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', method: 'GET', @@ -43,6 +54,12 @@ describe('request-promise-retry', function () { expect(data.error).equal(undefined); }); }); + it('should pass, with retry options, with verbose logging', () => { + return rp(optionsWithRetryAndLogging) + .then(data => { + expect(data.error).equal(undefined); + }); + }); it('fail and retry 3 times', () => { return rp(optionsWithRetryFail) .catch(err => { @@ -55,6 +72,12 @@ describe('request-promise-retry', function () { expect(data.error).equal(undefined); }); }); + it('should pass, without retry options, with logging', () => { + return rp(optionsWithoutRetryWithLogging) + .then(data => { + expect(data.error).equal(undefined); + }); + }); it('should fail, without retry options', () => { return rp(optionsWithoutRetryFail) .catch(err => { From 5d0d04448227822c9de8620e43bb304d642da1c9 Mon Sep 17 00:00:00 2001 From: Sushim Mukul Dutta Date: Tue, 17 Jul 2018 17:50:12 +0530 Subject: [PATCH 3/6] Update index.js - changing to snake_case verbose_logging. Maintain format for global options. --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8471517..6959f2d 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ class rpRetry { const fetchDataWithRetry = tryCount => { return requestPromise(options) .then(result => { - if(options.verboseLogging) { + if(options.verbose_logging) { logger.info(`Result obtained for ${options.method} request to ${options.uri}`); } return Promise.resolve(result); @@ -36,7 +36,7 @@ class rpRetry { } return requestPromise(options) .then(result => { - if(options.verboseLogging) { + if(options.verbose_logging) { logger.info(`Result obtained for ${options.method} request to ${options.uri}`); } return Promise.resolve(result); @@ -65,4 +65,4 @@ class rpRetry { } } -module.exports = rpRetry.rp; \ No newline at end of file +module.exports = rpRetry.rp; From 91e6eb78b007699074fa10fdd3a93b810dd5733f Mon Sep 17 00:00:00 2001 From: Sushim Mukul Dutta Date: Tue, 17 Jul 2018 17:50:42 +0530 Subject: [PATCH 4/6] Update index.js - changing to snake_case --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6959f2d..0b495be 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const logger = require('./modules/logger')('request-promise-retry'); class rpRetry { static _rpRetry(options) { - if(options.verboseLogging) { + if(options.verbose_logging) { logger.info(`calling ${options.uri} with retry ${options.retry}`); } const tries = options.retry || 1; From 756147010da75701d966973db5e6e7b49228f167 Mon Sep 17 00:00:00 2001 From: Sushim Mukul Dutta Date: Tue, 17 Jul 2018 17:51:14 +0530 Subject: [PATCH 5/6] Update index.js - changing to snake_case --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 0b495be..72356bb 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,7 @@ class rpRetry { } static _rp(options) { - if(options.verboseLogging) { + if(options.verbose_logging) { logger.info(`calling ${options.uri} without retries`); } return requestPromise(options) From 607f77fc90b1e9f8df15939fee9bd516e65583c0 Mon Sep 17 00:00:00 2001 From: Sushim Mukul Dutta Date: Tue, 17 Jul 2018 17:58:34 +0530 Subject: [PATCH 6/6] Update index.test.js - updated `verbose_logging` instead of `verboseLogging` --- test/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index c18eb35..4e14a55 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -18,7 +18,7 @@ const optionsWithRetry = { const optionsWithRetryAndLogging = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', method: 'GET', - verboseLogging: true, + verbose_logging: true, retry: 4 }; @@ -29,7 +29,7 @@ const optionsWithoutRetry = { const optionsWithoutRetryWithLogging = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user', method: 'GET', - verboseLogging: true + verbose_logging: true }; const optionsBadRetry1 = { uri: 'https://developer.github.com/v3/activity/events/#list-public-events-performed-by-a-user',