From 1495594eff8d7b78c747b76c9110c0910da6bc12 Mon Sep 17 00:00:00 2001 From: Timo Erdelt Date: Mon, 6 May 2024 16:09:14 +0200 Subject: [PATCH] test: include coinmarketcap API error in importer unit test --- ...info-history-importer.service.spec.ts.snap | 2 +- ...dity-info-history-importer.service.spec.ts | 26 ++++++++++--------- ...liquidity-info-history-importer.service.ts | 4 --- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/tasks/pair-liquidity-info-history-importer/__snapshots__/pair-liquidity-info-history-importer.service.spec.ts.snap b/src/tasks/pair-liquidity-info-history-importer/__snapshots__/pair-liquidity-info-history-importer.service.spec.ts.snap index ac26fb2..d34b712 100644 --- a/src/tasks/pair-liquidity-info-history-importer/__snapshots__/pair-liquidity-info-history-importer.service.spec.ts.snap +++ b/src/tasks/pair-liquidity-info-history-importer/__snapshots__/pair-liquidity-info-history-importer.service.spec.ts.snap @@ -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`] = ` [ [ { diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts index abcccdc..21b8a4a 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts @@ -268,13 +268,15 @@ 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 @@ -282,26 +284,26 @@ describe('PairLiquidityInfoHistoryImporterService', () => { 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)}`], ]); diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts index 6d2dc8a..d975769 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts @@ -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; - // }); } }