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

feature/ Replaced node-rest-client with axios #374

Merged
merged 5 commits into from
Feb 8, 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
292 changes: 150 additions & 142 deletions lib/api.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
/**
* Set the response timeout limit (in milliseconds)
*/
responseTimeout: 80000,
responseTimeout: 30000,

/**
* Mangopay REST API version - will be appended in the front of the endpoints
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
"main": "./index.js",
"dependencies": {
"@types/node": "14.14.x",
"node-rest-client": "3.1.0",
"axios": "1.6.2",
"promise": "8.1.x",
"underscore": "1.12.x"
},
"devDependencies": {
"typescript": "4.1.x",
"chai": "4.2.x",
"dtslint": "4.2.1",
"mocha": "9.2.0",
"sinon": "9.2.x",
"ts-node": "^9.1.1"
"ts-node": "^9.1.1",
"typescript": "4.1.x"
},
"scripts": {
"start": "npm install -g mocha && npm install -g jsdox && npm install",
"documentation": "jsdox -t docs/templates/ -i README -o docs lib/services",
"test": "mocha 'test/**/*.js' --recursive --timeout 60000 --ui bdd",
"test": "mocha 'test/**/*.js' --recursive --timeout 30000 --ui bdd",
"test:types": "dtslint ./typings"
}
}
51 changes: 4 additions & 47 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports = {
data: {
data: cardRegistration.PreregistrationData,
accessKeyRef: cardRegistration.AccessKey,
cardNumber: '4970105191923460',
cardNumber: '4970107111111119',
cardExpirationDate: '1224',
cardCvx: '123'
},
Expand Down Expand Up @@ -510,50 +510,7 @@ module.exports = {
data: {
data: cardRegistration.PreregistrationData,
accessKeyRef: cardRegistration.AccessKey,
cardNumber: '4970105191923460',
cardExpirationDate: '1224',
cardCvx: '123'
},
url: cardRegistration.CardRegistrationURL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};

return api.method('post', function (data, response) {
callback(Buffer.from(data).toString(), response);
}, options);
},

getPaylineCorrectRegistartionDataForDeposit: function(cardRegistration, callback) {
/*
****** DO NOT use this code in a production environment - it is just for unit tests. In production you are not allowed to have the user's card details pass via your server (which is what is required to use this code here) *******
*/
var options = {
data: {
data: cardRegistration.PreregistrationData,
accessKeyRef: cardRegistration.AccessKey,
cardNumber: '4970105181818183',
cardExpirationDate: '1224',
cardCvx: '123'
},
url: cardRegistration.CardRegistrationURL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};

return api.method('post', function (data, response) {
callback(Buffer.from(data).toString(), response);
}, options);
},

getPaylineCorrectRegistartionData3DSecure: function(cardRegistration, callback) {
var options = {
data: {
data: cardRegistration.PreregistrationData,
accessKeyRef: cardRegistration.AccessKey,
cardNumber: '4970105191923460',
cardNumber: '4970107111111119',
cardExpirationDate: '1224',
cardCvx: '123'
},
Expand Down Expand Up @@ -678,7 +635,7 @@ module.exports = {
};

api.CardRegistrations.create(cardRegistration, function () {
self.getPaylineCorrectRegistartionDataForDeposit(cardRegistration, function (data, response) {
self.getPaylineCorrectRegistartionData(cardRegistration, function (data, response) {
cardRegistration.RegistrationData = data;

api.CardRegistrations.update(cardRegistration).then(function (data) {
Expand Down Expand Up @@ -706,7 +663,7 @@ module.exports = {
};

api.CardRegistrations.create(cardRegistration, function () {
self.getPaylineCorrectRegistartionDataForDeposit(cardRegistration, function (data, response) {
self.getPaylineCorrectRegistartionData(cardRegistration, function (data, response) {
cardRegistration.RegistrationData = data;

api.CardRegistrations.update(cardRegistration).then(function (data) {
Expand Down
1 change: 1 addition & 0 deletions test/services/BankingAliases.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var expect = require('chai').expect;
var helpers = require('../helpers');
var api = require('../main');

describe('Banking Aliases', function() {
var john = helpers.data.getUserNatural();
Expand Down
11 changes: 4 additions & 7 deletions test/services/CardRegistrations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('underscore');
var expect = require('chai').expect;
var helpers = require('../helpers');
var api = require('../main');

describe('Card Registrations', function () {
var cardRegistration;
Expand Down Expand Up @@ -58,7 +59,7 @@ describe('Card Registrations', function () {
data: {
data: cardRegistration.PreregistrationData,
accessKeyRef: cardRegistration.AccessKey,
cardNumber: '4970105191923460',
cardNumber: '4970107111111119',
cardExpirationDate: '1224',
cardCvx: '123'
},
Expand Down Expand Up @@ -207,14 +208,10 @@ describe('Card Registrations', function () {
var failedResponse;

before(function(done) {
api.CardRegistrations.create(newInvalidCardRegistration)
.then(function(){
done('Creating invalid card registration did not failed the promise');
})
.catch(function(data, response){
api.CardRegistrations.create(newInvalidCardRegistration, function (data) {
failedResponse = data;
done();
});
});
});

it('should fail', function () {
Expand Down
1 change: 1 addition & 0 deletions test/services/Cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var _ = require('underscore');
var expect = require('chai').expect;
var helpers = require('../helpers');
var UserNatural = require('../../lib/models/UserNatural');
var api = require('../main');

describe('Cards', function () {
var john = new UserNatural(helpers.data.getUserNatural());
Expand Down
3 changes: 2 additions & 1 deletion test/services/Clients.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('underscore');
var path = require('path');
var expect = require('chai').expect;
var api = require('../main');

var ClientWallet = require('../../lib/models/ClientWallet');
var BankAccount = require('../../lib/models/BankAccount');
Expand Down Expand Up @@ -65,7 +66,7 @@ describe("Clients", function () {
});

it('should be uploaded', function () {
expect(requestResponse.statusCode).to.equal(204);
expect(requestResponse.status).to.equal(204);
});

});
Expand Down
1 change: 1 addition & 0 deletions test/services/Disputes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('underscore');
var path = require('path');
var expect = require('chai').expect;
var api = require('../main');

describe('Disputes', function() {
var disputes;
Expand Down
1 change: 1 addition & 0 deletions test/services/Events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var _ = require('underscore');
var expect = require('chai').expect;
var api = require('../main');

var helpers = require('../helpers');

Expand Down
1 change: 1 addition & 0 deletions test/services/Hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('underscore');
var expect = require('chai').expect;
var helpers = require('../helpers');
var api = require('../main');

describe('Hooks', function() {
var hook;
Expand Down
1 change: 1 addition & 0 deletions test/services/Idempotency.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var expect = require('chai').expect;
var api = require('../main');

var helpers = require('../helpers');
var mangopay = require('../../index');
Expand Down
98 changes: 29 additions & 69 deletions test/services/InstantConversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,22 @@ describe('InstantConversions', function () {
IpAddress: "2001:0620:0000:0000:0211:24FF:FE80:C12C"
}, function (data, response) {
api.Wallets.create(creditedWallet).then(function () {
api.Transfers.create({
instantConversion = {
AuthorId: john.Id,
Tag: 'DefaultTag',
CreditedUserId: john.Id,
DebitedFunds: {
Currency: 'GBP',
Amount: 1
CreditedWalletId: creditedWallet.Id,
DebitedWalletId: debitedWallet.Id,
CreditedFunds: {
Currency: 'GBP'
},
Fees: {
Currency: 'GBP',
Amount: 0
DebitedFunds: {
Currency: 'EUR',
Amount: 79
},
DebitedWalletId: debitedWallet.Id,
CreditedWalletId: creditedWallet.Id
}, function (data, response) {
api.Wallets.get(debitedWallet.Id).then(function (data) {
debitedWallet = data;

instantConversion = {
AuthorId: john.Id,
CreditedWalletId: creditedWallet.Id,
DebitedWalletId: debitedWallet.Id,
CreditedFunds: {
Currency: 'GBP'
},
DebitedFunds: {
Currency: 'EUR',
Amount: 79
},
Tag: 'Instant conversion test'
};
api.InstantConversions.createInstantConversion(instantConversion, function (data, response) {
instantConversion = data;
done();
});
});
Tag: 'Instant conversion test'
};
api.InstantConversions.createInstantConversion(instantConversion, function (data, response) {
instantConversion = data;
done();
});
});
});
Expand Down Expand Up @@ -203,44 +183,24 @@ describe('InstantConversions', function () {
IpAddress: "2001:0620:0000:0000:0211:24FF:FE80:C12C"
}, function (data, response) {
api.Wallets.create(creditedWallet).then(function () {
api.Transfers.create({
instantConversion = {
AuthorId: john.Id,
Tag: 'DefaultTag',
CreditedUserId: john.Id,
DebitedFunds: {
Currency: 'GBP',
Amount: 1
CreditedWalletId: creditedWallet.Id,
DebitedWalletId: debitedWallet.Id,
CreditedFunds: {
Currency: 'GBP'
},
Fees: {
Currency: 'GBP',
Amount: 0
DebitedFunds: {
Currency: 'EUR',
Amount: 79
},
DebitedWalletId: debitedWallet.Id,
CreditedWalletId: creditedWallet.Id
}, function (data, response) {
api.Wallets.get(debitedWallet.Id).then(function (data) {
debitedWallet = data;

instantConversion = {
AuthorId: john.Id,
CreditedWalletId: creditedWallet.Id,
DebitedWalletId: debitedWallet.Id,
CreditedFunds: {
Currency: 'GBP'
},
DebitedFunds: {
Currency: 'EUR',
Amount: 79
},
Tag: 'Instant conversion test'
};
api.InstantConversions.createInstantConversion(instantConversion, function (data, response) {
instantConversion = data;
api.InstantConversions.getInstantConversion(instantConversion.Id, function (data, response) {
returnedInstantConversion = data;
done();
});
});
Tag: 'Instant conversion test'
};
api.InstantConversions.createInstantConversion(instantConversion, function (data, response) {
instantConversion = data;
api.InstantConversions.getInstantConversion(instantConversion.Id, function (data, response) {
returnedInstantConversion = data;
done();
});
});
});
Expand All @@ -258,4 +218,4 @@ describe('InstantConversions', function () {
expect(returnedInstantConversion.Status).to.equal('SUCCEEDED');
});
});
});
});
1 change: 1 addition & 0 deletions test/services/KycDocuments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('underscore');
var expect = require('chai').expect;
var helpers = require('../helpers');
var api = require('../main');

describe('KycDocuments', function() {
var john = helpers.data.getUserNatural();
Expand Down
1 change: 1 addition & 0 deletions test/services/Mandates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Promise = require('promise');
var expect = require('chai').expect;
var assert = require('chai').assert;
var os = require('os');
var api = require('../main');

var helpers = require('../helpers');

Expand Down
Loading
Loading