Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Unskip history test #41

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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",
},
]
`;
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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(
Expand All @@ -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 () => {
Expand Down