Skip to content

Commit

Permalink
refactor: make private methods private, use square brackets accessor …
Browse files Browse the repository at this point in the history
…for tests
  • Loading branch information
tmrdlt committed Mar 26, 2024
1 parent 699b232 commit f8bcda8
Show file tree
Hide file tree
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
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/tasks/pair-sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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...`);
Expand All @@ -121,7 +121,7 @@ export class PairSyncService implements OnModuleInit {
this.logger.log(`Pairs liquidity refresh completed`);
};

createOnEventReceived =
private createOnEventReceived =
(
ctx: Context,
logger: Logger,
Expand Down
2 changes: 1 addition & 1 deletion test/mdw-ws-client.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};

Expand Down
12 changes: 6 additions & 6 deletions test/pair-sync.service.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 },
Expand All @@ -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' },
});
Expand All @@ -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' },
Expand All @@ -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 },
});
Expand Down
2 changes: 1 addition & 1 deletion test/pair-sync.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions test/pairs.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
14 changes: 7 additions & 7 deletions test/tokens.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit f8bcda8

Please sign in to comment.