Skip to content

Commit

Permalink
test: fix pair-sync.service.e2e-spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt committed Aug 19, 2024
1 parent 6150d8c commit f41dcbc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
62 changes: 55 additions & 7 deletions test/e2e/__snapshots__/tokens.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`TokenController DELETE /tokens/listed/{token_address} should return 200
"malformed": false,
"name": "3",
"noContract": false,
"pairs": 2,
"pairs": 1,
"priceAe": null,
"priceChangeDay": null,
"priceChangeMonth": null,
Expand Down Expand Up @@ -47,7 +47,7 @@ exports[`TokenController DELETE /tokens/listed/{token_address} should return 200
"malformed": false,
"name": "3",
"noContract": false,
"pairs": 2,
"pairs": 1,
"priceAe": null,
"priceChangeDay": null,
"priceChangeMonth": null,
Expand Down Expand Up @@ -123,7 +123,7 @@ exports[`TokenController GET /tokens should return all tokens even if some are l
"malformed": false,
"name": "3",
"noContract": false,
"pairs": 2,
"pairs": 1,
"priceAe": null,
"priceChangeDay": null,
"priceChangeMonth": null,
Expand All @@ -140,6 +140,30 @@ exports[`TokenController GET /tokens should return all tokens even if some are l
"volumeUsdWeek": "0",
"volumeUsdYear": "0",
},
{
"address": "ct_token5",
"decimals": 18,
"listed": false,
"malformed": false,
"name": "5",
"noContract": false,
"pairs": 1,
"priceAe": null,
"priceChangeDay": null,
"priceChangeMonth": null,
"priceChangeWeek": null,
"priceChangeYear": null,
"priceUsd": null,
"symbol": "5",
"totalReserve": null,
"tvlAe": null,
"tvlUsd": null,
"volumeUsdAll": null,
"volumeUsdDay": null,
"volumeUsdMonth": null,
"volumeUsdWeek": null,
"volumeUsdYear": null,
},
]
`;

Expand Down Expand Up @@ -200,7 +224,7 @@ exports[`TokenController GET /tokens should return all tokens when none are list
"malformed": false,
"name": "3",
"noContract": false,
"pairs": 2,
"pairs": 1,
"priceAe": null,
"priceChangeDay": null,
"priceChangeMonth": null,
Expand All @@ -217,6 +241,30 @@ exports[`TokenController GET /tokens should return all tokens when none are list
"volumeUsdWeek": "0",
"volumeUsdYear": "0",
},
{
"address": "ct_token5",
"decimals": 18,
"listed": false,
"malformed": false,
"name": "5",
"noContract": false,
"pairs": 1,
"priceAe": null,
"priceChangeDay": null,
"priceChangeMonth": null,
"priceChangeWeek": null,
"priceChangeYear": null,
"priceUsd": null,
"symbol": "5",
"totalReserve": null,
"tvlAe": null,
"tvlUsd": null,
"volumeUsdAll": null,
"volumeUsdDay": null,
"volumeUsdMonth": null,
"volumeUsdWeek": null,
"volumeUsdYear": null,
},
]
`;

Expand Down Expand Up @@ -278,13 +326,13 @@ exports[`TokenController GET /tokens/{token_address}/pairs should return pairs w
"totalSupply": "2",
},
"oppositeToken": {
"address": "ct_token3",
"address": "ct_token5",
"decimals": 18,
"listed": false,
"malformed": false,
"name": "3",
"name": "5",
"noContract": false,
"symbol": "3",
"symbol": "5",
},
"synchronized": true,
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "../",
"testEnvironment": "node",
"testRegex": "pairs.e2e-spec.ts$",
"testRegex": "e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/pair-sync.service.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service';
import * as data from '@/test/mock-data/context-mock-data';
import { mockContext } from '@/test/utils/context-mock';
import { cleanDb } from '@/test/utils/db-helper';
import { PairLiquidityInfoHistoryImporterService } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service';
import { PairPathCalculatorService } from '@/tasks/pair-path-calculator/pair-path-calculator.service';
import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service';
import { PairLiquidityInfoHistoryErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service';
import { MdwHttpClientService } from '@/clients/mdw-http-client.service';
import { HttpService } from '@/clients/http.service';
import { CoinmarketcapClientService } from '@/clients/coinmarketcap-client.service';
import { CacheModule } from '@nestjs/cache-manager';

// Testing method
// 1. before all create a common context
Expand All @@ -22,13 +30,21 @@ describe('PairSyncService', () => {

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [CacheModule.register({})],
providers: [
PairSyncService,
PrismaService,
TokenDbService,
PairDbService,
HttpService,
CoinmarketcapClientService,
MdwHttpClientService,
MdwWsClientService,
SdkClientService,
PairLiquidityInfoHistoryImporterService,
PairLiquidityInfoHistoryDbService,
PairLiquidityInfoHistoryErrorDbService,
PairPathCalculatorService,
],
}).compile();

Expand Down
5 changes: 4 additions & 1 deletion test/e2e/tokens.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
token1,
token2,
token3,
token5,
} from '@/test/mock-data/pair-liquidity-info-history-mock-data';

// Testing method
Expand Down Expand Up @@ -61,7 +62,9 @@ describe('TokenController', () => {
});

beforeEach(async () => {
await prismaService.token.createMany({ data: [token1, token2, token3] });
await prismaService.token.createMany({
data: [token1, token2, token3, token5],
});
await prismaService.pair.createMany({ data: [pair1, pair2, pair3] });
await prismaService.pairLiquidityInfo.createMany({
data: [liquidityInfo1, liquidityInfo2],
Expand Down

0 comments on commit f41dcbc

Please sign in to comment.