Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make private methods private, use square brackets accessor …
Browse files Browse the repository at this point in the history
…for tests
tmrdlt committed Mar 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 699b232 commit f8bcda8
Showing 7 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/clients/mdw-ws-client.service.ts
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ export class MdwWsClientService {
return ws;
};

createMessageHandler =
private createMessageHandler =
(callbacks: Callbacks, ws: WebSocket, logger: Logger) =>
async (msg: WebSocket.RawData) => {
const stringMessage = msg.toString();
8 changes: 4 additions & 4 deletions src/tasks/pair-sync.service.ts
Original file line number Diff line number Diff line change
@@ -51,12 +51,12 @@ export class PairSyncService implements OnModuleInit {
});
};

unsyncAllPairs = async () => {
private unsyncAllPairs = async () => {
const batch = await this.pairDbService.unsyncAllPairs();
this.logger.log(`${batch.count} pairs marked as unsync`);
};

refreshPairs = async (ctx: Context): Promise<ContractAddress[]> => {
private refreshPairs = async (ctx: Context): Promise<ContractAddress[]> => {
this.logger.log(`Getting all pairs from Factory...`);
const { decodedResult: allFactoryPairs } =
await ctx.factory.get_all_pairs();
@@ -111,7 +111,7 @@ export class PairSyncService implements OnModuleInit {
return newAddresses.concat(futurePairs);
};

refreshPairsLiquidity = async (ctx: Context) => {
private refreshPairsLiquidity = async (ctx: Context) => {
//get the all pairs
const dbPairs = await this.pairDbService.getAllWithCondition(true);
this.logger.log(`Refreshing pairs liquidity...`);
@@ -121,7 +121,7 @@ export class PairSyncService implements OnModuleInit {
this.logger.log(`Pairs liquidity refresh completed`);
};

createOnEventReceived =
private createOnEventReceived =
(
ctx: Context,
logger: Logger,
2 changes: 1 addition & 1 deletion test/mdw-ws-client.service.spec.ts
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ describe('MdwWsClientService', () => {
const callbacks = mock<Callbacks>();
const ws = mock<WebSocket>();
const logger = mock<Logger>();
const msgHandler = service.createMessageHandler(callbacks, ws, logger);
const msgHandler = service['createMessageHandler'](callbacks, ws, logger);
return { callbacks, ws, logger, msgHandler };
};

12 changes: 6 additions & 6 deletions test/pair-sync.service.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ describe('PairSyncService', () => {
beforeEach(async () => {
await cleanDb(prismaService);
const ctx = mockContext(data.context2);
await service.refreshPairs(ctx);
await service['refreshPairs'](ctx);
});

afterAll(async () => {
@@ -56,7 +56,7 @@ describe('PairSyncService', () => {

it('refresh pairs liquidity', async () => {
const ctx = mockContext(data.context2);
await service.refreshPairsLiquidity(ctx);
await service['refreshPairsLiquidity'](ctx);

const pairs = await prismaService.pair.findMany({
include: { liquidityInfo: true },
@@ -74,7 +74,7 @@ describe('PairSyncService', () => {

it('refresh new added pairs', async () => {
const ctx = mockContext(data.context21);
await service.refreshPairs(ctx);
await service['refreshPairs'](ctx);
const pairs: prisma.Pair[] = await prismaService.pair.findMany({
orderBy: { id: 'asc' },
});
@@ -87,8 +87,8 @@ describe('PairSyncService', () => {

it('refresh liquidity for new added pairs', async () => {
const ctx = mockContext(data.context21);
await service.refreshPairs(ctx);
await service.refreshPairsLiquidity(ctx);
await service['refreshPairs'](ctx);
await service['refreshPairsLiquidity'](ctx);
const pairs = await prismaService.pair.findMany({
include: { liquidityInfo: true },
orderBy: { address: 'asc' },
@@ -102,7 +102,7 @@ describe('PairSyncService', () => {
});

it('unsync all pairs', async () => {
await service.unsyncAllPairs();
await service['unsyncAllPairs']();
const pairs = await prismaService.pair.findMany({
where: { synchronized: true },
});
2 changes: 1 addition & 1 deletion test/pair-sync.service.spec.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const initTestContext = (service: PairSyncService) => {
};
const { onFactory, refreshPairsLiquidity, getAllAddresses } = mock<Ev>();
const logger = mock<Logger>();
const eventHandler = service.createOnEventReceived(
const eventHandler = service['createOnEventReceived'](
ctx,
logger,
onFactory,
26 changes: 13 additions & 13 deletions test/pairs.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ describe('PairsController', () => {
beforeEach(async () => {
await cleanDb(prismaService);
const ctx = mockContext(data.context2);
await pairSyncService.refreshPairs(ctx);
await pairSyncService['refreshPairs'](ctx);
});

describe('/pairs', () => {
@@ -87,7 +87,7 @@ describe('PairsController', () => {

it('/pairs (GET) 200 synchronized', async () => {
const ctx1 = mockContext(data.context2);
await pairSyncService.refreshPairsLiquidity(ctx1);
await pairSyncService['refreshPairsLiquidity'](ctx1);
const response = await request(app.getHttpServer())
.get('/pairs')
.expect(200);
@@ -116,9 +116,9 @@ describe('PairsController', () => {

it('/pairs (GET) 200 with new pair', async () => {
const ctx1 = mockContext(data.context2);
await pairSyncService.refreshPairsLiquidity(ctx1);
await pairSyncService['refreshPairsLiquidity'](ctx1);
const ctx2 = mockContext(data.context21);
await pairSyncService.refreshPairs(ctx2);
await pairSyncService['refreshPairs'](ctx2);
const response = await request(app.getHttpServer())
.get('/pairs')
.expect(200);
@@ -153,9 +153,9 @@ describe('PairsController', () => {

it('/pairs (GET) 200 only-listed=true', async () => {
const ctx1 = mockContext(data.context2);
await pairSyncService.refreshPairsLiquidity(ctx1);
await pairSyncService['refreshPairsLiquidity'](ctx1);
const ctx2 = mockContext(data.context21);
await pairSyncService.refreshPairs(ctx2);
await pairSyncService['refreshPairs'](ctx2);

let response = await request(app.getHttpServer())
.get('/pairs?only-listed=true')
@@ -215,7 +215,7 @@ describe('PairsController', () => {

it('/pairs/by-address/ct_p1 (GET) 200 synchronized', async () => {
const ctx1 = mockContext(data.context2);
await pairSyncService.refreshPairsLiquidity(ctx1);
await pairSyncService['refreshPairsLiquidity'](ctx1);
return request(app.getHttpServer())
.get('/pairs/by-address/ct_p1')
.expect(200)
@@ -251,8 +251,8 @@ describe('PairsController', () => {

it('/pairs/by-address/ct_p1 (GET) 200 unsynchronized with liquidity', async () => {
const ctx1 = mockContext(data.context2);
await pairSyncService.refreshPairsLiquidity(ctx1);
await pairSyncService.unsyncAllPairs();
await pairSyncService['refreshPairsLiquidity'](ctx1);
await pairSyncService['unsyncAllPairs']();
return request(app.getHttpServer())
.get('/pairs/by-address/ct_p1')
.expect(200)
@@ -318,7 +318,7 @@ describe('PairsController', () => {
},
}),
});
await pairSyncService.refreshPairs(ctx);
await pairSyncService['refreshPairs'](ctx);

return request(app.getHttpServer())
.get('/pairs/swap-routes/ct_t0/ct_t5')
@@ -328,7 +328,7 @@ describe('PairsController', () => {

it('/pairs/swap-routes/ct_t0/ct_t4 (GET) 200 direct path', async () => {
const ctx = mockContext(data.context21);
await pairSyncService.refreshPairs(ctx);
await pairSyncService['refreshPairs'](ctx);

return request(app.getHttpServer())
.get('/pairs/swap-routes/ct_t0/ct_t4')
@@ -347,7 +347,7 @@ describe('PairsController', () => {

it('/pairs/swap-routes/ct_t0/ct_t3 (GET) 200 synchronized', async () => {
const ctx = mockContext(data.context21);
await pairSyncService.refreshPairsLiquidity(ctx);
await pairSyncService['refreshPairsLiquidity'](ctx);

return request(app.getHttpServer())
.get('/pairs/swap-routes/ct_t0/ct_t1')
@@ -486,7 +486,7 @@ describe('PairsController', () => {
t1: 3,
}),
});
await pairSyncService.refreshPairs(ctx);
await pairSyncService['refreshPairs'](ctx);

return request(app.getHttpServer())
.get('/pairs/swap-routes/ct_t0/ct_t1')
14 changes: 7 additions & 7 deletions test/tokens.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ describe('TokenController', () => {
beforeEach(async () => {
await cleanDb(prismaService);
const ctx = mockContext(data.context2);
await pairSyncService.refreshPairs(ctx);
await pairSyncService['refreshPairs'](ctx);
});

afterAll(async () => {
@@ -244,8 +244,8 @@ describe('TokenController', () => {

it('/tokens/by-address/ct_t0/pairs (GET) 200 with pairs only on pairs0', async () => {
const ctx = utils.mockContext(data.context21);
await pairSyncService.refreshPairs(ctx);
await pairSyncService.refreshPairsLiquidity(ctx);
await pairSyncService['refreshPairs'](ctx);
await pairSyncService['refreshPairsLiquidity'](ctx);

const response = await request(app.getHttpServer())
.get('/tokens/by-address/ct_t0/pairs')
@@ -317,8 +317,8 @@ describe('TokenController', () => {

it('/tokens/by-address/ct_t3/pairs (GET) 200 with pairs only on pairs1', async () => {
const ctx = utils.mockContext(data.context21);
await pairSyncService.refreshPairs(ctx);
await pairSyncService.refreshPairsLiquidity(ctx);
await pairSyncService['refreshPairs'](ctx);
await pairSyncService['refreshPairsLiquidity'](ctx);
await utils.listToken(prismaService, 'ct_t0');
await utils.listToken(prismaService, 'ct_t3');

@@ -393,8 +393,8 @@ describe('TokenController', () => {
},
]),
});
await pairSyncService.refreshPairs(ctx);
await pairSyncService.refreshPairsLiquidity(ctx);
await pairSyncService['refreshPairs'](ctx);
await pairSyncService['refreshPairsLiquidity'](ctx);
await utils.listToken(prismaService, 'ct_t0');
await utils.listToken(prismaService, 'ct_t3');

0 comments on commit f8bcda8

Please sign in to comment.