From 2622eb1d817c5921301ead8fcdfe13cf6a42b39d Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Tue, 25 Feb 2025 13:40:46 +0200 Subject: [PATCH] fixed instantiating multiple instances of the SDK --- lib/api.js | 2 +- test/services/MultipleSdkInstances.js | 41 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/services/MultipleSdkInstances.js diff --git a/lib/api.js b/lib/api.js index b80ae8b..1d01be7 100644 --- a/lib/api.js +++ b/lib/api.js @@ -32,7 +32,7 @@ var Api = function (config) { this.rateLimits = []; // Add default request configuration options - _.extend(this.requestOptions, { + this.requestOptions = _.extend({}, this.requestOptions, { // Path options are replacing the ${placeholders} from apiMethods path: { clientId: config.clientId, diff --git a/test/services/MultipleSdkInstances.js b/test/services/MultipleSdkInstances.js new file mode 100644 index 0000000..4ba174c --- /dev/null +++ b/test/services/MultipleSdkInstances.js @@ -0,0 +1,41 @@ +const {expect} = require("chai"); +const mangopay = require("../../index"); + +var api_1 = new mangopay({ + clientId: 'sdk-unit-tests', + clientApiKey: 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju' +}); + +var api_2 = new mangopay({ + clientId: 'bad-client', + clientApiKey: 'bad-key' +}); + +describe('sdk instances', function () { + var data1, data2; + var error; + + before(function (done) { + api_1.Users.getAll(function (data) { + data1 = data; + api_2.Users.getAll(function (data) { + data2 = data; + done(); + }) + .catch(function (data) { + error = data; + done(); + }); + }); + }); + + it('should work', function () { + expect(api_1.config.clientId).not.to.be.eq(api_2.config.clientId); + expect(api_1.config.clientApiKey).not.to.be.eq(api_2.config.clientApiKey); + expect(api_1.requestOptions.path.clientId).not.to.be.eq(api_2.requestOptions.path.clientId); + + expect(data1).to.be.an('array'); + expect(data2).to.be.undefined; + expect(error.error).to.eq("invalid_client"); + }); +}); \ No newline at end of file