From b12d4b552535622e69ea94e1abea32e661e5374e Mon Sep 17 00:00:00 2001 From: stefanGhivi Date: Mon, 26 Sep 2016 13:25:03 +0300 Subject: [PATCH] implemented client wallet api --- lib/apiMethods.js | 7 +++- lib/models/ClientWallet.js | 28 ++++++++++++++ lib/services/Clients.js | 75 ++++++++++++++++++++++++++++++++++++++ test/services/Clients.js | 62 +++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 lib/models/ClientWallet.js diff --git a/lib/apiMethods.js b/lib/apiMethods.js index e21a5dd..1130315 100644 --- a/lib/apiMethods.js +++ b/lib/apiMethods.js @@ -112,5 +112,10 @@ module.exports = { "clients_get" : ["/${apiVersion}/${clientId}/clients", "GET"], "clients_update" : ["/${apiVersion}/${clientId}/clients", "PUT"], - "clients_upload_logo" : ["/${apiVersion}/${clientId}/clients/logo", "PUT"] + "clients_upload_logo" : ["/${apiVersion}/${clientId}/clients/logo", "PUT"], + "client_wallets_all" : ["/${apiVersion}/${clientId}/clients/wallets/", "GET"], + "client_wallets_get" : ["/${apiVersion}/${clientId}/clients/wallets/${fundsType}/${currency}", "GET"], + "client_wallets_by_fundsType" : ["/${apiVersion}/${clientId}/clients/wallets/${fundsType}", "GET"], + "client_wallets_transactions" : ["/${apiVersion}/${clientId}/clients/wallets/${fundsType}/${currency}/transactions/", "GET"] + }; \ No newline at end of file diff --git a/lib/models/ClientWallet.js b/lib/models/ClientWallet.js new file mode 100644 index 0000000..a4ee5a7 --- /dev/null +++ b/lib/models/ClientWallet.js @@ -0,0 +1,28 @@ +var EntityBase = require('./EntityBase'); +var Money = require('./Money'); + +var ClientWallet = EntityBase.extend({ + defaults : { + Balance : null, + Currency : null, + FundsType : null + }, + + getSubObjects: function() { + return { + 'Balance': Money + } + }, + + /** + * Get array with read-only properties + * @return {Array} List of string properties + */ + getReadOnlyProperties: function() { + var properties = EntityBase.prototype.getReadOnlyProperties(); + properties.push('Balance'); + return properties; + } +}); + +module.exports = ClientWallet; \ No newline at end of file diff --git a/lib/services/Clients.js b/lib/services/Clients.js index 3de73b9..4ad7cd6 100644 --- a/lib/services/Clients.js +++ b/lib/services/Clients.js @@ -7,6 +7,8 @@ var fs = require('fs'); var Service = require('../service'); var Client = require('../models/Client'); +var Transaction = require('../models/Transaction'); +var ClientWallet = require('../models/ClientWallet'); var Clients = Service.extend({ /** @@ -80,7 +82,80 @@ var Clients = Service.extend({ if (!logo) this._api.errorHandler('Content of the file cannot be empty'); return this.uploadLogo(logo, callback, options); + }, + + /** + * Get all client wallets + * @param {Function} callback Callback function + * @param {Object} options Request options + * @return {Object} Promise of the request + */ + getClientWallets: function(callback, options) { + options = this._api._getOptions(callback, options, { + dataClass: ClientWallet + }); + + return this._api.method("client_wallets_all", callback, options); + }, + + /** + * Get a client wallet + * @param fundsType Wallet's funds type + * @param currency Currency of the wallet + * @param {Function} callback Callback function + * @param {Object} options Request options + * @return {Object} Promise of the request + */ + getClientWallet: function(fundsType, currency, callback, options) { + options = this._api._getOptions(callback, options, { + path: { + fundsType: fundsType, + currency: currency + }, + dataClass: ClientWallet + }); + + return this._api.method("client_wallets_get", callback, options); + }, + + /** + * Get client wallets by the type of funds + * @param fundsType Wallets funds type + * @param {Function} callback Callback function + * @param {Object} options Request options + * @return {Object} Promise of the request + */ + getClientWalletsByFundsType: function(fundsType, callback, options) { + options = this._api._getOptions(callback, options, { + path: { + fundsType: fundsType + }, + dataClass: ClientWallet + }); + + return this._api.method("client_wallets_by_fundsType", callback, options); + }, + + /** + * Get a client wallet's transactions + * @param fundsType Wallet's funds type + * @param currency Currency of the wallet + * @param {Function} callback Callback function + * @param {Object} options Request options + * @return {Object} Promise of the request + */ + getClientWalletTransactions: function(fundsType, currency, callback, options) { + options = this._api._getOptions(callback, options, { + path: { + fundsType: fundsType, + currency: currency + }, + dataClass: Transaction + }); + + return this._api.method("client_wallets_transactions", callback, options); } + }); module.exports = Clients; \ No newline at end of file diff --git a/test/services/Clients.js b/test/services/Clients.js index 5f40ecc..8a2678b 100644 --- a/test/services/Clients.js +++ b/test/services/Clients.js @@ -2,6 +2,7 @@ var _ = require('underscore'); var path = require('path'); var expect = require('chai').expect; +var ClientWallet = require('../../lib/models/ClientWallet'); describe("Clients", function(){ var client; before(function(done){ @@ -51,4 +52,65 @@ describe("Clients", function(){ }); }); + + describe("Get client wallets by funds type", function(){ + var feesWallets; + var creditWallets; + before(function(done){ + api.Clients.getClientWalletsByFundsType('FEES', function(data, response){ + feesWallets = data; + api.Clients.getClientWalletsByFundsType('CREDIT', function(data, response){ + creditWallets = data; + done(); + }); + }); + }); + + it('should have wallets', function(){ + expect(feesWallets).not.to.be.undefined; + expect(creditWallets).not.to.be.undefined; + }) + }); + + describe("Get client wallet", function(){ + var clientWallets; + var clientWallet; + before(function(done){ + api.Clients.getClientWallets(function(data, response){ + clientWallets = data; + api.Clients.getClientWallet(clientWallets[0].FundsType, clientWallets[0].Currency + , function(data, response){ + clientWallet = data; + done(); + }); + }); + }); + + it('should get the same client wallet', function(){ + expect(clientWallet).not.to.be.undefined; + expect(clientWallet.FundsType).to.equal(clientWallets[0].FundsType); + expect(clientWallet.Currency).to.equal(clientWallets[0].Currency); + }); + }); + + describe("Get client wallet's transactions",function(){ + var clientWallets; + var transactions; + before(function(done){ + api.Clients.getClientWallets(function(data, response){ + clientWallets = data; + api.Clients.getClientWalletTransactions(clientWallets[0].FundsType, clientWallets[0].Currency + , function(data, response){ + transactions = data; + done(); + }); + }); + }); + + it('should get transactions', function(){ + expect(transactions).not.to.be.undefined; + expect(transactions.length).to.be.greaterThan(0); + }) + + }); });