Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marcinrog fix passing query string #97

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/chartmogul/util/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
44 changes: 44 additions & 0 deletions test/chartmogul/util/retry.js
Original file line number Diff line number Diff line change
@@ -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: '[email protected]' };

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: '[email protected]' },
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();
});
});
});
Loading