diff --git a/nyc.config.coverage.json b/nyc.config.coverage.json index a6381285..8f17700d 100644 --- a/nyc.config.coverage.json +++ b/nyc.config.coverage.json @@ -1,14 +1,14 @@ { "all": true, - "branches": 90, + "branches": 100, "check-coverage": true, "exclude": ["**/*.d.ts", "**/*.test*.ts", "**/index.ts", "**/demo/**/*"], "extension": [".ts"], - "functions": 90, + "functions": 100, "include": ["src/**/*.ts"], - "lines": 90, + "lines": 100, "per-file": false, "reporter": ["html", "lcov", "text"], "require": ["ts-node/register"], - "statements": 90 + "statements": 100 } diff --git a/src/dealing/DealingAPI.test.ts b/src/dealing/DealingAPI.test.ts index 9ea2af4a..e4992eb5 100644 --- a/src/dealing/DealingAPI.test.ts +++ b/src/dealing/DealingAPI.test.ts @@ -1,19 +1,19 @@ import nock from 'nock'; import {APIClient} from '../APIClient'; import { + AffectedDealStatus, DealingAPI, - PositionCreateRequest, - PositionCloseRequest, - PositionUpdateRequest, DealReferenceResponse, - OrderCreateRequest, - OrderUpdateRequest, - Direction, - PositionOrderType, DealStatus, - AffectedDealStatus, + Direction, + OrderCreateRequest, OrderTimeInForce, OrderType, + OrderUpdateRequest, + PositionCloseRequest, + PositionCreateRequest, + PositionOrderType, + PositionUpdateRequest, } from './DealingAPI'; describe('DealingAPI', () => { @@ -368,6 +368,62 @@ describe('DealingAPI', () => { const deleteOrder = await global.client.rest.dealing.deleteOrder(dealId); expect(deleteOrder.dealReference).toBe('54321'); }); + + it('fails to delete an order', async () => { + const dealId = '12345'; + + nock(APIClient.URL_DEMO) + .post( + DealingAPI.URL.WORKINGORDERS_OTC + dealId, + {}, + { + reqheaders: { + _method: 'DELETE', + }, + } + ) + .reply(403); + + global.client.rest.defaults['axios-retry'] = { + retries: 1, + }; + await expectAsync(global.client.rest.dealing.deleteOrder(dealId)).toBeRejected(); + }); + + it('retries when being rate limited', async () => { + const dealId = '12345'; + + nock(APIClient.URL_DEMO) + .post( + DealingAPI.URL.WORKINGORDERS_OTC + dealId, + {}, + { + reqheaders: { + _method: 'DELETE', + }, + } + ) + .reply( + 403, + JSON.stringify({ + errorCode: 'error.public-api.exceeded-api-key-allowance', + }) + ); + + const amountOfRetries = 2; + + global.client.rest.defaults['axios-retry'] = { + retries: amountOfRetries, + }; + + try { + await global.client.rest.dealing.deleteOrder(dealId); + fail('Expected error'); + } catch (error) { + expect(error.isAxiosError).toBe(true); + expect(error.config['axios-retry'].retryCount).toBe(amountOfRetries); + } + }, 10_000); }); describe('updateOrder', () => { @@ -396,27 +452,4 @@ describe('DealingAPI', () => { expect(updateOrder.dealReference).toBe('54321'); }); }); - - describe('failedDelete', () => { - it('fails to delete an order', async () => { - const dealId = '12345'; - - nock(APIClient.URL_DEMO) - .post( - DealingAPI.URL.WORKINGORDERS_OTC + dealId, - {}, - { - reqheaders: { - _method: 'DELETE', - }, - } - ) - .reply(403); - - global.client.rest.defaults['axios-retry'] = { - retries: 1, - }; - await expectAsync(global.client.rest.dealing.deleteOrder(dealId)).toBeRejected(); - }); - }); });