diff --git a/CHANGELOG.md b/CHANGELOG.md index 104f534..f0f8c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning]. [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html -## [3.2.3] - 2023-01-19 +## [3.3.2] - 2024-02-28 +- Fix query string not passed after replacing `request` library with `superagent` + +## [3.2.3] - 2024-01-19 - Actually remove the `requests` library from `package.json` -## [3.2.2] - 2023-01-18 +## [3.2.2] - 2024-01-18 - Remove the `requests` library and use `superagent` instead ## [3.2.1] - 2023-12-20 diff --git a/lib/chartmogul/util/retry.js b/lib/chartmogul/util/retry.js index 60e0490..190ac9e 100644 --- a/lib/chartmogul/util/retry.js +++ b/lib/chartmogul/util/retry.js @@ -49,6 +49,7 @@ module.exports = function retryRequest (retries, options, cb) { const request = superagent(options.method || 'get', requestUrl) .auth(options.auth.user, options.auth.pass) .set(options.headers) + .query(options.qs) .send(options.body); request.end((err, res) => { diff --git a/package-lock.json b/package-lock.json index 2a229bb..fa83ec4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "chartmogul-node", - "version": "3.2.3", + "version": "3.2.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "chartmogul-node", - "version": "3.2.3", + "version": "3.2.4", "license": "MIT", "dependencies": { "retry": "^0.13.1", diff --git a/package.json b/package.json index 4d05970..87a7083 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chartmogul-node", - "version": "3.2.3", + "version": "3.3.2", "description": "Official Chartmogul API Node.js Client", "main": "lib/chartmogul.js", "scripts": { diff --git a/test/chartmogul/util/retry.js b/test/chartmogul/util/retry.js new file mode 100644 index 0000000..508c1de --- /dev/null +++ b/test/chartmogul/util/retry.js @@ -0,0 +1,44 @@ +'use strict'; + +const ChartMogul = require('../../../lib/chartmogul'); +const expect = require('chai').expect; +const nock = require('nock'); +const config = new ChartMogul.Config('token'); +const retryRequest = require('../../../lib/chartmogul/util/retry'); + +describe('RetryTest', () => { + config.retries = 2; + const mockSuccessResponse = { success: true }; + + it('should retry on network error and then succeed', done => { + const query = { email: 'bob@acme.com' }; + + nock(config.API_BASE) + .get('/v1/metrics/all') + .query(query) + .replyWithError({ code: 'ECONNRESET' }) + .get('/v1/metrics/all') + .query(query) + .reply(200, mockSuccessResponse); + + const options = { + uri: '/v1/metrics/all', + baseUrl: config.API_BASE, + method: 'GET', + auth: { + user: config.getApiKey(), + pass: '' + }, + qs: { email: 'bob@acme.com' }, + headers: { + 'User-Agent': 'chartmogul-node/' + config.VERSION + } + }; + + retryRequest(config.retries, options, (err, res, body) => { + expect(err).to.equal(null); + expect(body).to.deep.equal(mockSuccessResponse); + done(); + }); + }); +});