From 0b1bddb409ae55f176983a4771e99267f853718b Mon Sep 17 00:00:00 2001 From: Timo Erdelt Date: Tue, 20 Aug 2024 09:55:41 +0200 Subject: [PATCH] test: unskip test in pair-liquidity-info-history.controller.spec.ts --- ...idity-info-history.controller.spec.ts.snap | 52 +++++++++++++++++ ...-liquidity-info-history.controller.spec.ts | 57 +++++++------------ 2 files changed, 71 insertions(+), 38 deletions(-) create mode 100644 src/api/pair-liquidity-info-history/__snapshots__/pair-liquidity-info-history.controller.spec.ts.snap diff --git a/src/api/pair-liquidity-info-history/__snapshots__/pair-liquidity-info-history.controller.spec.ts.snap b/src/api/pair-liquidity-info-history/__snapshots__/pair-liquidity-info-history.controller.spec.ts.snap new file mode 100644 index 0000000..5f7dc8d --- /dev/null +++ b/src/api/pair-liquidity-info-history/__snapshots__/pair-liquidity-info-history.controller.spec.ts.snap @@ -0,0 +1,52 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`PairLiquidityInfoHistoryController GET /history should return history entries and use default values for empty params 1`] = ` +[ + { + "aeUsdPrice": "0.050559", + "delta0UsdValue": "2.556212481e-18", + "delta1UsdValue": "2.556212481e-18", + "deltaReserve0": "1000", + "deltaReserve1": "1000", + "height": 100001, + "logIndex": 1, + "microBlockHash": "mh_entry1", + "microBlockTime": "1000000000001", + "pairAddress": "ct_pair1", + "reserve0": "1000", + "reserve0Usd": "2.556212481e-18", + "reserve1": "1000", + "reserve1Usd": "2.556212481e-18", + "senderAccount": "", + "token0AePrice": "0.050559", + "token1AePrice": "0.050559", + "transactionHash": "th_entry1", + "transactionIndex": "100001", + "txUsdFee": "7.668637443e-21", + "type": "PairMint", + }, + { + "aeUsdPrice": "0.050559", + "delta0UsdValue": "2.556212481e-18", + "delta1UsdValue": "2.556212481e-18", + "deltaReserve0": "1000", + "deltaReserve1": "1000", + "height": 300003, + "logIndex": 1, + "microBlockHash": "mh_entry3", + "microBlockTime": "3000000000003", + "pairAddress": "ct_pair2", + "reserve0": "1000", + "reserve0Usd": "2.556212481e-18", + "reserve1": "1000", + "reserve1Usd": "2.556212481e-18", + "senderAccount": "", + "token0AePrice": "0.050559", + "token1AePrice": "0.050559", + "transactionHash": "th_entry3", + "transactionIndex": "300003", + "txUsdFee": "7.668637443e-21", + "type": "PairMint", + }, +] +`; diff --git a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts index 2c04611..08ca91a 100644 --- a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts +++ b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts @@ -1,17 +1,19 @@ import { CacheModule } from '@nestjs/cache-manager'; import { INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { Pair, PairLiquidityInfoHistory } from '@prisma/client'; import * as request from 'supertest'; import { OrderQueryEnum } from '@/api/api.model'; import { PairLiquidityInfoHistoryController } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.controller'; +import { PairLiquidityInfoHistoryWithTokens } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.model'; import { PairLiquidityInfoHistoryService } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.service'; import { historyEntry1, historyEntry3, pair1, pair2, + token1, + token2, } from '@/test/mock-data/pair-liquidity-info-history-mock-data'; const mockPairLiquidityInfoHistoryService = { @@ -46,17 +48,16 @@ describe('PairLiquidityInfoHistoryController', () => { jest.clearAllMocks(); }); - // TODO fix with updated return - it.skip('should return history entries and use default values for empty params', async () => { + it('should return history entries and use default values for empty params', async () => { // Mocks - const historyEntryWithPair1: { pair: Pair } & PairLiquidityInfoHistory = { + const historyEntryWithPair1: PairLiquidityInfoHistoryWithTokens = { ...historyEntry1, - pair: pair1, + pair: { ...pair1, token0: token1, token1: token2 }, }; - const historyEntryWithPair2: { pair: Pair } & PairLiquidityInfoHistory = { + const historyEntryWithPair2: PairLiquidityInfoHistoryWithTokens = { ...historyEntry3, - pair: pair2, + pair: { ...pair2, token0: token2, token1: token2 }, }; mockPairLiquidityInfoHistoryService.getAllHistoryEntries.mockResolvedValue( @@ -69,38 +70,18 @@ describe('PairLiquidityInfoHistoryController', () => { // Assertions expect( mockPairLiquidityInfoHistoryService.getAllHistoryEntries, - ).toHaveBeenCalledWith( - 100, - 0, - OrderQueryEnum.asc, - undefined, - undefined, - undefined, - undefined, - ); + ).toHaveBeenCalledWith({ + limit: 100, + offset: 0, + order: OrderQueryEnum.asc, + pairAddress: undefined, + tokenAddress: undefined, + height: undefined, + fromBlockTime: undefined, + toBlockTime: undefined, + }); expect(result.status).toBe(200); - expect(result.body).toEqual([ - { - pairAddress: historyEntryWithPair1.pair.address, - liquidityInfo: { - reserve0: historyEntryWithPair1.reserve0, - reserve1: historyEntryWithPair1.reserve1, - }, - height: historyEntryWithPair1.height, - microBlockHash: historyEntryWithPair1.microBlockHash, - microBlockTime: historyEntryWithPair1.microBlockTime.toString(), - }, - { - pairAddress: historyEntryWithPair2.pair.address, - liquidityInfo: { - reserve0: historyEntryWithPair2.reserve0, - reserve1: historyEntryWithPair2.reserve1, - }, - height: historyEntryWithPair2.height, - microBlockHash: historyEntryWithPair2.microBlockHash, - microBlockTime: historyEntryWithPair2.microBlockTime.toString(), - }, - ]); + expect(result.body).toMatchSnapshot(); }); it('should parse all query params correctly', async () => {