Skip to content

Commit 9022c36

Browse files
remove comments
1 parent 5c5d474 commit 9022c36

1 file changed

Lines changed: 6 additions & 30 deletions

File tree

tests/unit/storageEvictionTest.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Storage from '../../lib/storage';
44
import {OnyxStorageManager} from '../../lib/OnyxStorageManager';
55
import type {StorageUsageConfig, StorageMetadata} from '../../lib/OnyxStorageManager/types';
66

7-
// Mock the Storage module
87
const storageSetItemSpy = jest.spyOn(Storage, 'setItem').mockImplementation(() => Promise.resolve());
98
const storageGetItemSpy = jest.spyOn(Storage, 'getItem').mockImplementation(() => Promise.resolve(null));
109
const storageRemoveItemSpy = jest.spyOn(Storage, 'removeItem').mockImplementation(() => Promise.resolve());
@@ -15,13 +14,10 @@ describe('Storage Eviction Tests', () => {
1514
const originalDateNow = Date.now;
1615

1716
beforeEach(() => {
18-
// Clear all mocks
1917
jest.clearAllMocks();
2018

21-
// Reset Date.now to current time
2219
Date.now = originalDateNow;
2320

24-
// Create a fresh instance for each test
2521
storageManager = new OnyxStorageManager();
2622
});
2723

@@ -32,8 +28,6 @@ describe('Storage Eviction Tests', () => {
3228

3329
describe('Metadata Creation', () => {
3430
it('should create metadata when key is accessed for the first time', async () => {
35-
// Test scenario 1: If there is no metadata key in storage it should be created when key was accessed
36-
3731
const config: StorageUsageConfig = {
3832
enabled: true,
3933
evictableKeys: ['test_key'],
@@ -42,20 +36,17 @@ describe('Storage Eviction Tests', () => {
4236
cleanupInterval: 5 * 60 * 1000,
4337
};
4438

45-
// Mock that the key exists in storage but no metadata
4639
storageGetAllKeysSpy.mockResolvedValue(['test_key']);
4740
storageGetItemSpy.mockImplementation((key) => {
4841
if (key === '__onyx_meta_test_key') {
49-
return Promise.resolve(null); // No metadata exists
42+
return Promise.resolve(null);
5043
}
51-
return Promise.resolve('some_value'); // Key has value
44+
return Promise.resolve('some_value');
5245
});
5346

54-
// Initialize the storage manager
5547
await storageManager.initialize(config);
5648
await waitForPromisesToResolve();
5749

58-
// Verify metadata was created for the evictable key
5950
expect(storageSetItemSpy).toHaveBeenCalledWith(
6051
'__onyx_meta_test_key',
6152
expect.objectContaining({
@@ -74,7 +65,6 @@ describe('Storage Eviction Tests', () => {
7465
cleanupInterval: 5 * 60 * 1000,
7566
};
7667

77-
// Initialize with existing metadata
7868
const existingMetadata: StorageMetadata = {
7969
lastAccessed: Date.now() - 1000,
8070
createdAt: Date.now() - 10000,
@@ -90,19 +80,17 @@ describe('Storage Eviction Tests', () => {
9080
await storageManager.initialize(config);
9181
await waitForPromisesToResolve();
9282

93-
// Track a key access
9483
const accessTime = Date.now();
9584
Date.now = jest.fn(() => accessTime);
9685

9786
storageManager.trackKeySet('test_key');
9887
await waitForPromisesToResolve();
9988

100-
// Verify metadata was updated with new access
10189
expect(storageSetItemSpy).toHaveBeenCalledWith(
10290
'__onyx_meta_test_key',
10391
expect.objectContaining({
10492
lastAccessed: accessTime,
105-
createdAt: existingMetadata.createdAt, // Should remain same
93+
createdAt: existingMetadata.createdAt,
10694
}),
10795
);
10896
});
@@ -173,24 +161,20 @@ describe('Storage Eviction Tests', () => {
173161
await storageManager.initialize(config);
174162
await waitForPromisesToResolve();
175163

176-
// Perform cleanup
177164
const result = await storageManager.performCleanup();
178165

179-
// Verify the recent key was NOT removed
180166
expect(result.cleanedKeys).not.toContain('recent_key');
181167
expect(storageRemoveItemSpy).not.toHaveBeenCalledWith('recent_key');
182168
});
183169
});
184170

185171
describe('Automatic Cleanup - Age', () => {
186172
it('should automatically clean up items older than maxAgeDays regardless of access', async () => {
187-
// Test scenario 3: When the item is longer in storage than provided in the config it should be removed automatically
188-
189173
const config: StorageUsageConfig = {
190174
enabled: true,
191175
evictableKeys: ['very_old_key'],
192176
maxIdleDays: 7,
193-
maxAgeDays: 30, // 30 days max age
177+
maxAgeDays: 30,
194178
cleanupInterval: 5 * 60 * 1000,
195179
};
196180

@@ -214,7 +198,6 @@ describe('Storage Eviction Tests', () => {
214198
await storageManager.initialize(config);
215199
await waitForPromisesToResolve();
216200

217-
// Perform cleanup
218201
const result = await storageManager.performCleanup();
219202

220203
// Verify the old key was removed despite recent access
@@ -249,7 +232,6 @@ describe('Storage Eviction Tests', () => {
249232
await storageManager.initialize(config);
250233
await waitForPromisesToResolve();
251234

252-
// Perform cleanup
253235
const result = await storageManager.performCleanup();
254236

255237
// Verify the new key was NOT removed
@@ -260,8 +242,6 @@ describe('Storage Eviction Tests', () => {
260242

261243
describe('Evictable Keys Filter', () => {
262244
it('should only remove items which keys are added to evictableKeys', async () => {
263-
// Test scenario 4: Only remove items which keys are added to evictableKeys
264-
265245
const config: StorageUsageConfig = {
266246
enabled: true,
267247
evictableKeys: ['evictable_key'], // Only this key is evictable
@@ -288,7 +268,6 @@ describe('Storage Eviction Tests', () => {
288268
await storageManager.initialize(config);
289269
await waitForPromisesToResolve();
290270

291-
// Perform cleanup
292271
const result = await storageManager.performCleanup();
293272

294273
// Verify only the evictable key was removed
@@ -301,7 +280,7 @@ describe('Storage Eviction Tests', () => {
301280
it('should support key patterns with underscore suffix', async () => {
302281
const config: StorageUsageConfig = {
303282
enabled: true,
304-
evictableKeys: ['temp_'], // Pattern: keys starting with 'temp_'
283+
evictableKeys: ['temp_'],
305284
maxIdleDays: 1,
306285
maxAgeDays: 1,
307286
cleanupInterval: 5 * 60 * 1000,
@@ -324,7 +303,6 @@ describe('Storage Eviction Tests', () => {
324303
await storageManager.initialize(config);
325304
await waitForPromisesToResolve();
326305

327-
// Perform cleanup
328306
const result = await storageManager.performCleanup();
329307

330308
// Verify only temp_ prefixed keys were removed
@@ -336,7 +314,7 @@ describe('Storage Eviction Tests', () => {
336314
it('should not evict anything when evictableKeys is empty', async () => {
337315
const config: StorageUsageConfig = {
338316
enabled: true,
339-
evictableKeys: [], // No keys are evictable
317+
evictableKeys: [],
340318
maxIdleDays: 1,
341319
maxAgeDays: 1,
342320
cleanupInterval: 5 * 60 * 1000,
@@ -359,7 +337,6 @@ describe('Storage Eviction Tests', () => {
359337
await storageManager.initialize(config);
360338
await waitForPromisesToResolve();
361339

362-
// Perform cleanup
363340
const result = await storageManager.performCleanup();
364341

365342
// Verify no keys were removed
@@ -395,7 +372,6 @@ describe('Storage Eviction Tests', () => {
395372
await storageManager.initialize(config);
396373
await waitForPromisesToResolve();
397374

398-
// Perform cleanup
399375
const result = await storageManager.performCleanup();
400376

401377
// Verify no cleanup was performed

0 commit comments

Comments
 (0)