Skip to content

Commit

Permalink
test: include coinmarketcap API error in importer unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt authored and kenodressel committed May 29, 2024
1 parent 6b94847 commit 1495594
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ exports[`PairLiquidityInfoHistoryImporterService import should skip a log if the
]
`;

exports[`PairLiquidityInfoHistoryImporterService import should catch and insert an error on log level 1`] = `
exports[`PairLiquidityInfoHistoryImporterService import should catch and insert any error on log level (e.g. API rate limit reached) 1`] = `
[
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,40 +268,42 @@ describe('PairLiquidityInfoHistoryImporterService', () => {
);
});

it('should catch and insert an error on log level', async () => {
it('should catch and insert any error on log level (e.g. API rate limit reached)', async () => {
const errorMessage =
"You've exceeded your API Key's HTTP request rate limit. Rate limits reset every minute.";
const error = {
pairId: pairWithTokens.id,
microBlockHash: contractLog3.block_hash,
transactionHash: contractLog3.call_tx_hash,
logIndex: parseInt(contractLog3.log_idx),
error: 'Error: error',
error: `Error: ${errorMessage}`,
};

// Mock functions
mockPairDb.getAll.mockResolvedValue([pairWithTokens]);
mockPairLiquidityInfoHistoryErrorDb.getErrorWithinHours.mockResolvedValue(
undefined,
);
mockPairLiquidityInfoHistoryDb.getLastlySyncedLogByPairId
.mockResolvedValueOnce({})
.mockRejectedValueOnce(new Error('error'))
.mockRejectedValueOnce(undefined);
mockMdwClient.getContractLogsUntilCondition.mockResolvedValue([
contractLog3,
contractLog4,
contractLog5,
]);
mockCoinmarketcapClient.getHistoricalPriceDataThrottled.mockResolvedValue(
coinmarketcapResponseAeUsdQuoteData,
);
mockPairLiquidityInfoHistoryDb.upsert.mockResolvedValue(null);
mockPairLiquidityInfoHistoryErrorDb.upsert.mockResolvedValue(null);
mockPairLiquidityInfoHistoryDb.getLastlySyncedLogByPairId
.mockResolvedValueOnce({})
.mockResolvedValueOnce(undefined)
.mockResolvedValueOnce(undefined);
mockCoinmarketcapClient.getHistoricalPriceDataThrottled
.mockRejectedValueOnce(new Error(errorMessage))
.mockResolvedValueOnce(coinmarketcapResponseAeUsdQuoteData);

mockPairLiquidityInfoHistoryDb.upsert.mockResolvedValueOnce(null);
mockPairLiquidityInfoHistoryErrorDb.upsert.mockResolvedValueOnce(null);

// Start import
await service.import();

// Assertions

expect(errorSpy.mock.calls).toEqual([
[`Skipped log. ${JSON.stringify(error)}`],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,5 @@ export class PairLiquidityInfoHistoryImporterService {
return this.coinmarketcapClient
.getHistoricalPriceDataThrottled(microBlockTime)
.then((res) => res.data['1700'].quotes[0].quote.USD.price);
// .catch((err) => {
// console.log(err);
// return 0;
// });
}
}

0 comments on commit 1495594

Please sign in to comment.