UNPKG

upstox-js-sdk

Version:

The official Node Js client for communicating with the Upstox API

139 lines (128 loc) 5.4 kB
/* * OpenAPI definition * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) * * OpenAPI spec version: v0 * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * * Swagger Codegen version: 3.0.79 * * Do not edit the class manually. * */ (function(root, factory) { if (typeof define === 'function' && define.amd) { // AMD. define(['expect.js', '../../src/index', 'sinon'], factory); } else if (typeof module === 'object' && module.exports) { // CommonJS-like environments that support module.exports, like Node. factory(require('expect.js'), require('../../src/index'), require('sinon')); } else { // Browser globals (root is window) factory(root.expect, root.UpstoxClient, root.sinon); } }(this, function(expect, UpstoxClient, sinon) { 'use strict'; var instance; var mockApiClient; beforeEach(function() { mockApiClient = new UpstoxClient.ApiClient(); sinon.stub(mockApiClient, 'callApi').callsFake(function(path, httpMethod, pathParams, queryParams, headerParams, formParams, postBody, authNames, contentTypes, accepts, returnType, callback) { callback(null, {}, {status: 200}); }); instance = new UpstoxClient.MutualFundApi(mockApiClient); }); afterEach(function() { mockApiClient.callApi.restore(); }); describe('(package)', function() { describe('MutualFundApi', function() { describe('getMutualFundHoldings', function() { it('should invoke callApi for GET /v2/mf/holdings with OAUTH2', function(done) { instance.getMutualFundHoldings(function(error, data, response) { expect(error).to.be(null); expect(mockApiClient.callApi.calledOnce).to.be(true); var args = mockApiClient.callApi.getCall(0).args; expect(args[0]).to.be('/v2/mf/holdings'); expect(args[1]).to.be('GET'); expect(args[7]).to.eql(['OAUTH2']); expect(args[10]).to.be(UpstoxClient.GetMutualFundHoldingsResponse); done(); }); }); }); describe('getMutualFundOrder', function() { it('should throw when orderId is missing', function() { expect(function() { instance.getMutualFundOrder(undefined, function() {}); }).to.throwError(/orderId/); expect(function() { instance.getMutualFundOrder(null, function() {}); }).to.throwError(/orderId/); }); it('should invoke callApi for GET /v2/mf/orders/{order_id}', function(done) { var orderId = 'order-uuid-1'; instance.getMutualFundOrder(orderId, function(error, data, response) { expect(error).to.be(null); expect(mockApiClient.callApi.calledOnce).to.be(true); var args = mockApiClient.callApi.getCall(0).args; expect(args[0]).to.be('/v2/mf/orders/{order_id}'); expect(args[1]).to.be('GET'); expect(args[2]).to.eql({order_id: orderId}); expect(args[10]).to.be(UpstoxClient.GetMutualFundOrderDetailsResponse); done(); }); }); }); describe('getMutualFundOrders', function() { it('should pass query params from opts', function(done) { var opts = { status: 'COMPLETED', transactionType: 'BUY', pageNumber: 2, records: 25 }; instance.getMutualFundOrders(opts, function(error, data, response) { expect(error).to.be(null); var queryParams = mockApiClient.callApi.getCall(0).args[3]; expect(queryParams.status).to.be('COMPLETED'); expect(queryParams.transaction_type).to.be('BUY'); expect(queryParams.page_number).to.be(2); expect(queryParams.records).to.be(25); expect(mockApiClient.callApi.getCall(0).args[0]).to.be('/v2/mf/orders'); expect(mockApiClient.callApi.getCall(0).args[10]).to.be(UpstoxClient.GetMutualFundOrdersResponse); done(); }); }); it('should default opts to empty query map', function(done) { instance.getMutualFundOrders({}, function(error, data, response) { expect(error).to.be(null); var queryParams = mockApiClient.callApi.getCall(0).args[3]; expect(queryParams).to.eql({ status: undefined, transaction_type: undefined, page_number: undefined, records: undefined }); done(); }); }); }); describe('getMutualFundSips', function() { it('should pass pagination query params from opts', function(done) { instance.getMutualFundSips({pageNumber: 3, records: 15}, function(error, data, response) { expect(error).to.be(null); var queryParams = mockApiClient.callApi.getCall(0).args[3]; expect(queryParams.page_number).to.be(3); expect(queryParams.records).to.be(15); expect(mockApiClient.callApi.getCall(0).args[0]).to.be('/v2/mf/sips'); expect(mockApiClient.callApi.getCall(0).args[10]).to.be(UpstoxClient.GetMutualFundSipsResponse); done(); }); }); }); }); }); }));