Skip to content

Commit afa115d

Browse files
committed
chore: fix eslint error
Signed-off-by: nikolay <n.atanasow94@gmail.com>
1 parent 3988dfb commit afa115d

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

packages/relay/src/lib/decorators/cache.decorator.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,13 @@ export function cache(cacheService: CacheService, options: CacheOptions = {}) {
204204
};
205205
}
206206

207-
// this class will be used for test purpose only
208-
export class CacheHelper {
209-
private static shouldSkipCachingForSingleParams(args: any, params: CacheSingleParam[] = []): boolean {
210-
return shouldSkipCachingForSingleParams(args, params);
211-
}
212-
213-
private static shouldSkipCachingForNamedParams(args: any, params: CacheNamedParams[] = []): boolean {
214-
return shouldSkipCachingForNamedParams(args, params);
215-
}
216-
217-
private static generateCacheKey(methodName: string, args: any): string {
218-
return generateCacheKey(methodName, args);
219-
}
220-
221-
private static extractRequestDetails(args: any): RequestDetails {
222-
return extractRequestDetails(args);
223-
}
224-
}
207+
// export private methods under __test__ "namespace" but using const
208+
// due to `ES2015 module syntax is preferred over namespaces` eslint warning
209+
export const __test__ = {
210+
__private: {
211+
shouldSkipCachingForSingleParams,
212+
shouldSkipCachingForNamedParams,
213+
generateCacheKey,
214+
extractRequestDetails,
215+
},
216+
};

packages/relay/tests/lib/decorators/cache.spec.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'
44
import { expect } from 'chai';
55
import sinon from 'sinon';
66

7-
import { cache, CacheHelper } from '../../../dist/lib/decorators';
7+
import { __test__, cache } from '../../../dist/lib/decorators';
88
import { CacheService } from '../../../dist/lib/services/cacheService/cacheService';
99
import { RequestDetails } from '../../../src/lib/types';
1010

@@ -108,7 +108,7 @@ describe('cache decorator', () => {
108108
describe('shouldSkipCachingForSingleParams', () => {
109109
it('should return false if no skip rules are provided', () => {
110110
const args = ['safe', 'latest'] as unknown as IArguments;
111-
const result = CacheHelper['shouldSkipCachingForSingleParams'](args, []);
111+
const result = __test__.__private.shouldSkipCachingForSingleParams(args, []);
112112
expect(result).to.be.false;
113113
});
114114

@@ -118,36 +118,36 @@ describe('cache decorator', () => {
118118
{ index: '0', value: 'pending' },
119119
{ index: '1', value: 'safe|finalized' },
120120
];
121-
const result = CacheHelper['shouldSkipCachingForSingleParams'](args, params);
121+
const result = __test__.__private.shouldSkipCachingForSingleParams(args, params);
122122
expect(result).to.be.false;
123123
});
124124

125125
it('should return true if a param at index matches any value in the pipe-separated list', () => {
126126
const args = ['earliest', 'safe'] as unknown as IArguments;
127127
const params = [{ index: '1', value: 'pending|safe' }];
128-
const result = CacheHelper['shouldSkipCachingForSingleParams'](args, params);
128+
const result = __test__.__private.shouldSkipCachingForSingleParams(args, params);
129129
expect(result).to.be.true;
130130
});
131131

132132
it('should return true if the argument at index is missing (do not cache optional parameters)', () => {
133133
const args = ['latest'] as unknown as IArguments;
134134
const params = [{ index: '1', value: 'pending|safe' }];
135-
const result = CacheHelper['shouldSkipCachingForSingleParams'](args, params);
135+
const result = __test__.__private.shouldSkipCachingForSingleParams(args, params);
136136
expect(result).to.be.true;
137137
});
138138

139139
it('should return true if the argument at index is explicitly undefined', () => {
140140
const args = ['finalized', undefined] as unknown as IArguments;
141141
const params = [{ index: '1', value: 'pending|safe' }];
142-
const result = CacheHelper['shouldSkipCachingForSingleParams'](args, params);
142+
const result = __test__.__private.shouldSkipCachingForSingleParams(args, params);
143143
expect(result).to.be.true;
144144
});
145145
});
146146

147147
describe('shouldSkipCachingForNamedParams', () => {
148148
it('should return false when no rules are provided', () => {
149149
const args = [{ fromBlock: 'safe' }] as unknown as IArguments;
150-
const result = CacheHelper['shouldSkipCachingForNamedParams'](args, []);
150+
const result = __test__.__private.shouldSkipCachingForNamedParams(args, []);
151151
expect(result).to.be.false;
152152
});
153153

@@ -159,7 +159,7 @@ describe('cache decorator', () => {
159159
fields: [{ name: 'fromBlock', value: 'pending|safe' }],
160160
},
161161
];
162-
const result = CacheHelper['shouldSkipCachingForNamedParams'](args, params);
162+
const result = __test__.__private.shouldSkipCachingForNamedParams(args, params);
163163
expect(result).to.be.false;
164164
});
165165

@@ -174,7 +174,7 @@ describe('cache decorator', () => {
174174
],
175175
},
176176
];
177-
const result = CacheHelper['shouldSkipCachingForNamedParams'](args, params);
177+
const result = __test__.__private.shouldSkipCachingForNamedParams(args, params);
178178
expect(result).to.be.false;
179179
});
180180

@@ -186,7 +186,7 @@ describe('cache decorator', () => {
186186
fields: [{ name: 'fromBlock', value: 'pending|safe' }],
187187
},
188188
];
189-
const result = CacheHelper['shouldSkipCachingForNamedParams'](args, params);
189+
const result = __test__.__private.shouldSkipCachingForNamedParams(args, params);
190190
expect(result).to.be.true;
191191
});
192192

@@ -201,7 +201,7 @@ describe('cache decorator', () => {
201201
],
202202
},
203203
];
204-
const result = CacheHelper['shouldSkipCachingForNamedParams'](args, params);
204+
const result = __test__.__private.shouldSkipCachingForNamedParams(args, params);
205205
expect(result).to.be.true;
206206
});
207207
});
@@ -210,21 +210,21 @@ describe('cache decorator', () => {
210210
it('should return only the method name when args are empty', () => {
211211
const args = [] as unknown as IArguments;
212212

213-
const result = CacheHelper['generateCacheKey']('eth_getBalance', args);
213+
const result = __test__.__private.generateCacheKey('eth_getBalance', args);
214214
expect(result).to.equal('eth_getBalance');
215215
});
216216

217217
it('should append primitive arguments to the cache key', () => {
218218
const args = ['0xabc', 'latest'] as unknown as IArguments;
219219

220-
const result = CacheHelper['generateCacheKey']('eth_getBalance', args);
220+
const result = __test__.__private.generateCacheKey('eth_getBalance', args);
221221
expect(result).to.equal('eth_getBalance_0xabc_latest');
222222
});
223223

224224
it('should append object key-value pairs to the cache key', () => {
225225
const args = [{ fromBlock: 'earliest', toBlock: 5644 }] as unknown as IArguments;
226226

227-
const result = CacheHelper['generateCacheKey']('eth_getLogs', args);
227+
const result = __test__.__private.generateCacheKey('eth_getLogs', args);
228228
expect(result).to.equal('eth_getLogs_fromBlock_earliest_toBlock_5644');
229229
});
230230

@@ -235,28 +235,28 @@ describe('cache decorator', () => {
235235
};
236236
const args = [mockRequestDetails, 'earliest'] as unknown as IArguments;
237237

238-
const result = CacheHelper['generateCacheKey']('eth_call', args);
238+
const result = __test__.__private.generateCacheKey('eth_call', args);
239239
expect(result).to.equal('eth_call_earliest');
240240
});
241241

242242
it('should not skip null or undefined args', () => {
243243
const args = [undefined, null, 'pending'] as unknown as IArguments;
244244

245-
const result = CacheHelper['generateCacheKey']('eth_call', args);
245+
const result = __test__.__private.generateCacheKey('eth_call', args);
246246
expect(result).to.equal('eth_call_undefined_null_pending');
247247
});
248248

249249
it('should process multiple arguments correctly', () => {
250250
const args = [{ fromBlock: '0xabc' }, 5644, 'safe'] as unknown as IArguments;
251251

252-
const result = CacheHelper['generateCacheKey']('eth_getLogs', args);
252+
const result = __test__.__private.generateCacheKey('eth_getLogs', args);
253253
expect(result).to.equal('eth_getLogs_fromBlock_0xabc_5644_safe');
254254
});
255255

256256
it('should work with mixed types including booleans and numbers', () => {
257257
const args = [true, 42, { fromBlock: 'safe' }] as unknown as IArguments;
258258

259-
const result = CacheHelper['generateCacheKey']('custom_method', args);
259+
const result = __test__.__private.generateCacheKey('custom_method', args);
260260
expect(result).to.equal('custom_method_true_42_fromBlock_safe');
261261
});
262262
});
@@ -266,23 +266,23 @@ describe('cache decorator', () => {
266266
const requestDetails = new RequestDetails({ requestId: 'abc123', ipAddress: '127.0.0.1' });
267267
const args = [5644, requestDetails, 'other'] as unknown as IArguments;
268268

269-
const result = CacheHelper['extractRequestDetails'](args);
269+
const result = __test__.__private.extractRequestDetails(args);
270270
expect(result.requestId).to.equal('abc123');
271271
expect(result.ipAddress).to.equal('127.0.0.1');
272272
});
273273

274274
it('should return a new default RequestDetails if not found', () => {
275275
const args = [5644, { fromBlock: 'pending' }, 'value'] as unknown as IArguments;
276276

277-
const result = CacheHelper['extractRequestDetails'](args);
277+
const result = __test__.__private.extractRequestDetails(args);
278278
expect(result.requestId).to.equal('');
279279
expect(result.ipAddress).to.equal('');
280280
});
281281

282282
it('should return new RequestDetails when args is empty', () => {
283283
const args = [] as unknown as IArguments;
284284

285-
const result = CacheHelper['extractRequestDetails'](args);
285+
const result = __test__.__private.extractRequestDetails(args);
286286
expect(result.requestId).to.equal('');
287287
expect(result.ipAddress).to.equal('');
288288
});
@@ -292,14 +292,14 @@ describe('cache decorator', () => {
292292
const rd2 = new RequestDetails({ requestId: 'second', ipAddress: '2.2.2.2' });
293293
const args = [rd1, rd2] as unknown as IArguments;
294294

295-
const result = CacheHelper['extractRequestDetails'](args);
295+
const result = __test__.__private.extractRequestDetails(args);
296296
expect(result).to.equal(rd1);
297297
});
298298

299299
it('should handle null or undefined values in args', () => {
300300
const args = [undefined, null, 5644] as unknown as IArguments;
301301

302-
const result = CacheHelper['extractRequestDetails'](args);
302+
const result = __test__.__private.extractRequestDetails(args);
303303
expect(result.requestId).to.equal('');
304304
expect(result.ipAddress).to.equal('');
305305
});

0 commit comments

Comments
 (0)