Skip to content

Commit cba02f7

Browse files
authored
Merge pull request #360 from trinnode/issues-resolved-trinnode
Resolve issues #200, #201, #221, #222: Add comprehensive unit tests
2 parents fec1df8 + b69f6f7 commit cba02f7

11 files changed

Lines changed: 2473 additions & 143 deletions

indexer/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
"testEnvironment": "node"
3737
},
3838
"dependencies": {
39+
"@nestjs/bullmq": "^11.0.4",
3940
"@nestjs/common": "^10.4.0",
4041
"@nestjs/config": "^4.0.3",
4142
"@nestjs/core": "^10.4.0",
4243
"@nestjs/typeorm": "^10.0.2",
4344
"@stellar/stellar-sdk": "^14.5.0",
45+
"bullmq": "^5.76.1",
4446
"ioredis": "^5.9.3",
4547
"pg": "^8.13.1",
4648
"reflect-metadata": "^0.2.0",

indexer/pnpm-lock.yaml

Lines changed: 931 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

indexer/src/cache/cache.service.ts

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type CacheStats = {
1313
@Injectable()
1414
export class CacheService implements OnModuleInit, OnModuleDestroy {
1515
private readonly logger = new Logger(CacheService.name);
16-
private redis: Redis.Redis;
16+
private redis: any;
1717

1818
private readonly MEM_WARN_THRESHOLD = 80;
1919
private readonly MEM_CRIT_THRESHOLD = 90;
@@ -185,11 +185,11 @@ export class CacheService implements OnModuleInit, OnModuleDestroy {
185185

186186
async getMemoryUsage(): Promise<{ usedMemory: number; maxMemory: number; usagePercent: number }> {
187187
const info = await this.redis.info('memory');
188-
const parsed = info
188+
const parsed: Record<string, string> = info
189189
.split('\n')
190-
.map((line) => line.trim())
191-
.filter((line) => line && !line.startsWith('#'))
192-
.reduce<Record<string, string>>((acc, line) => {
190+
.map((line: string) => line.trim())
191+
.filter((line: string) => line && !line.startsWith('#'))
192+
.reduce((acc: Record<string, string>, line: string) => {
193193
const [k, v] = line.split(':');
194194
if (k && v) acc[k] = v;
195195
return acc;
@@ -243,66 +243,3 @@ export class CacheService implements OnModuleInit, OnModuleDestroy {
243243
};
244244
}
245245
}
246-
247-
248-
async getActiveRaffles(): Promise<any | null> {
249-
return this.get('raffle:active');
250-
}
251-
252-
async setActiveRaffles(raffles: any): Promise<void> {
253-
await this.set('raffle:active', raffles, this.TTLS.ACTIVE_RAFFLES);
254-
}
255-
256-
async invalidateActiveRaffles(): Promise<void> {
257-
await this.del('raffle:active');
258-
}
259-
260-
261-
async getRaffleDetail(id: string): Promise<any | null> {
262-
return this.get(`raffle:${id}`);
263-
}
264-
265-
async setRaffleDetail(id: string, detail: any): Promise<void> {
266-
await this.set(`raffle:${id}`, detail, this.TTLS.RAFFLE_DETAIL);
267-
}
268-
269-
async invalidateRaffleDetail(id: string): Promise<void> {
270-
await this.del(`raffle:${id}`);
271-
}
272-
273-
async getLeaderboard(): Promise<any | null> {
274-
return this.get('leaderboard');
275-
}
276-
277-
async setLeaderboard(leaderboard: any): Promise<void> {
278-
await this.set('leaderboard', leaderboard, this.TTLS.LEADERBOARD);
279-
}
280-
281-
async invalidateLeaderboard(): Promise<void> {
282-
await this.del('leaderboard');
283-
}
284-
285-
async getUserProfile(address: string): Promise<any | null> {
286-
return this.get(`user:${address}`);
287-
}
288-
289-
async setUserProfile(address: string, profile: any): Promise<void> {
290-
await this.set(`user:${address}`, profile, this.TTLS.USER_PROFILE);
291-
}
292-
293-
async invalidateUserProfile(address: string): Promise<void> {
294-
await this.del(`user:${address}`);
295-
}
296-
297-
async getPlatformStats(): Promise<any | null> {
298-
return this.get('stats:platform');
299-
}
300-
301-
async setPlatformStats(stats: any): Promise<void> {
302-
await this.set('stats:platform', stats, this.TTLS.PLATFORM_STATS);
303-
}
304-
305-
async invalidatePlatformStats(): Promise<void> {
306-
await this.del('stats:platform');
307-
}
308-
}

0 commit comments

Comments
 (0)