Skip to content

Commit

Permalink
test: Enforce 100% code coverage (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Apr 27, 2021
1 parent 694d481 commit 48060f1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 35 deletions.
8 changes: 4 additions & 4 deletions 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
}
95 changes: 64 additions & 31 deletions 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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 48060f1

Please sign in to comment.