Skip to content

Commit 2dc32ec

Browse files
committed
feat: fix failing unit test for migration
1 parent 8ceb635 commit 2dc32ec

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

app/store/migrations/index.test.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const asyncMigration = async (state: any) => {
6565
};
6666

6767
describe('asyncifyMigrations', () => {
68-
it('should convert synchronous migrations to asynchronous', async () => {
68+
it('converts synchronous migrations to asynchronous', async () => {
6969
const testMigrationList = {
7070
...recentMigrations,
7171
[numberOfMigrations]: asyncMigration,
@@ -109,7 +109,7 @@ describe('migrations', () => {
109109
});
110110
});
111111

112-
it('should migrate successfully when latest migration is synchronous', async () => {
112+
it('migrates successfully when latest migration is synchronous', async () => {
113113
const testMigrationList = {
114114
...recentMigrations,
115115
[numberOfMigrations]: synchronousMigration,
@@ -132,7 +132,7 @@ describe('migrations', () => {
132132
expect((migratedState as Record<string, unknown>).test).toEqual('sync');
133133
});
134134

135-
it('should migrate successfully when latest migration is asynchronous', async () => {
135+
it('migrates successfully when latest migration is asynchronous', async () => {
136136
const testMigrationList = {
137137
...recentMigrations,
138138
[numberOfMigrations]: asyncMigration,
@@ -155,7 +155,7 @@ describe('migrations', () => {
155155
expect((migratedState as Record<string, unknown>).test).toEqual('async');
156156
});
157157

158-
it('should migrate successfully when using both synchronous and asynchronous migrations', async () => {
158+
it('migrates successfully when using both synchronous and asynchronous migrations', async () => {
159159
const testMigrationList = {
160160
...recentMigrations,
161161
[numberOfMigrations]: asyncMigration,
@@ -194,21 +194,21 @@ describe('Critical Error Handling', () => {
194194
});
195195

196196
describe('inflateFromControllers error handling', () => {
197-
it('should crash when ControllerStorage.getAllPersistedState fails', async () => {
197+
it('crashes when ControllerStorage.getAllPersistedState fails', async () => {
198198
// Arrange
199199
const storageError = new Error('Storage access failed');
200200
mockedControllerStorage.getAllPersistedState.mockRejectedValue(
201201
storageError,
202202
);
203203

204204
const testMigrationList = {
205-
105: (state: unknown) => state, // Migration > 104 triggers inflation logic
205+
107: (state: unknown) => state, // Migration > 106 triggers inflation logic
206206
};
207207

208208
const asyncMigrations = asyncifyMigrations(testMigrationList);
209209

210210
// Act & Assert
211-
await expect(asyncMigrations['105'](initialState)).rejects.toThrow(
211+
await expect(asyncMigrations['107'](initialState)).rejects.toThrow(
212212
'Critical: Failed to load controller data for migration. Cannot continue safely as migrations may corrupt data without complete state. App will restart to attempt recovery. Error: Error: Storage access failed',
213213
);
214214

@@ -220,18 +220,18 @@ describe('Critical Error Handling', () => {
220220
);
221221
});
222222

223-
it('should not crash when no controllers are found (empty state)', async () => {
223+
it('does not crash when no controllers are found (empty state)', async () => {
224224
// Arrange
225225
mockedControllerStorage.getAllPersistedState.mockResolvedValue({});
226226

227227
const testMigrationList = {
228-
105: (state: unknown) => ({ ...(state as object), test: 'passed' }),
228+
107: (state: unknown) => ({ ...(state as object), test: 'passed' }),
229229
};
230230

231231
const asyncMigrations = asyncifyMigrations(testMigrationList);
232232

233233
// Act
234-
const result = await asyncMigrations['105'](initialState);
234+
const result = await asyncMigrations['107'](initialState);
235235

236236
// Assert
237237
expect((result as Record<string, unknown>).test).toEqual('passed');
@@ -240,7 +240,7 @@ describe('Critical Error Handling', () => {
240240
});
241241

242242
describe('deflateToControllersAndStrip error handling', () => {
243-
it('should crash when any controller fails to save during deflation', async () => {
243+
it('crashes when any controller fails to save during deflation', async () => {
244244
// Arrange
245245
const stateWithControllers = {
246246
...initialState,
@@ -270,14 +270,14 @@ describe('Critical Error Handling', () => {
270270
});
271271

272272
const testMigrationList = {
273-
105: (state: unknown) => state, // This will trigger deflation after migration
273+
107: (state: unknown) => state, // This will trigger deflation after migration (lastVersion >= 106)
274274
};
275275

276276
const asyncMigrations = asyncifyMigrations(testMigrationList);
277277

278278
// Act & Assert
279279
await expect(
280-
asyncMigrations['105'](stateWithControllers),
280+
asyncMigrations['107'](stateWithControllers),
281281
).rejects.toThrow(
282282
"Critical: Migration failed for controller 'TestController'. Cannot continue with partial migration as this would corrupt user data. App will restart to attempt recovery. Error: Error: Disk full",
283283
);
@@ -290,7 +290,7 @@ describe('Critical Error Handling', () => {
290290
);
291291
});
292292

293-
it('should successfully deflate when all controllers save successfully', async () => {
293+
it('deflates successfully when all controllers save successfully', async () => {
294294
// Arrange
295295
const stateWithControllers = {
296296
...initialState,
@@ -314,13 +314,13 @@ describe('Critical Error Handling', () => {
314314
mockedControllerStorage.setItem.mockResolvedValue();
315315

316316
const testMigrationList = {
317-
105: (state: unknown) => ({ ...(state as object), migrated: true }),
317+
107: (state: unknown) => ({ ...(state as object), migrated: true }),
318318
};
319319

320320
const asyncMigrations = asyncifyMigrations(testMigrationList);
321321

322322
// Act
323-
const result = (await asyncMigrations['105'](
323+
const result = (await asyncMigrations['107'](
324324
stateWithControllers,
325325
)) as Record<string, unknown>;
326326

@@ -331,7 +331,7 @@ describe('Critical Error Handling', () => {
331331
expect(mockedCaptureException).not.toHaveBeenCalled(); // No errors captured
332332
});
333333

334-
it('should crash when deflation fails completely', async () => {
334+
it('crashes when deflation fails completely', async () => {
335335
// Arrange
336336
const stateWithControllers = {
337337
...initialState,
@@ -354,14 +354,14 @@ describe('Critical Error Handling', () => {
354354
mockedControllerStorage.setItem.mockRejectedValue(catastrophicError);
355355

356356
const testMigrationList = {
357-
105: (state: unknown) => state,
357+
107: (state: unknown) => state,
358358
};
359359

360360
const asyncMigrations = asyncifyMigrations(testMigrationList);
361361

362362
// Act & Assert
363363
await expect(
364-
asyncMigrations['105'](stateWithControllers),
364+
asyncMigrations['107'](stateWithControllers),
365365
).rejects.toThrow(
366366
"Critical: Migration failed for controller 'TestController'. Cannot continue with partial migration as this would corrupt user data. App will restart to attempt recovery. Error: Error: File system corrupted",
367367
);
@@ -376,29 +376,29 @@ describe('Critical Error Handling', () => {
376376
});
377377

378378
describe('Migration flow integration', () => {
379-
it('should not trigger inflation/deflation for migrations <= 104', async () => {
379+
it('does not trigger inflation/deflation for migrations < 106', async () => {
380380
// Arrange
381381
const testMigrationList = {
382-
104: (state: unknown) => ({
382+
105: (state: unknown) => ({
383383
...(state as object),
384-
test: 'migration104',
384+
test: 'migration105',
385385
}),
386386
};
387387

388388
const asyncMigrations = asyncifyMigrations(testMigrationList);
389389

390390
// Act
391-
const result = await asyncMigrations['104'](initialState);
391+
const result = await asyncMigrations['105'](initialState);
392392

393393
// Assert
394-
expect((result as Record<string, unknown>).test).toEqual('migration104');
394+
expect((result as Record<string, unknown>).test).toEqual('migration105');
395395
expect(
396396
mockedControllerStorage.getAllPersistedState,
397397
).not.toHaveBeenCalled();
398398
expect(mockedControllerStorage.setItem).not.toHaveBeenCalled();
399399
});
400400

401-
it('should handle mixed migration versions correctly', async () => {
401+
it('handles mixed migration versions correctly', async () => {
402402
// Arrange - Reset all mocks to clean state
403403
jest.clearAllMocks();
404404
mockedControllerStorage.getAllPersistedState.mockResolvedValue({});
@@ -410,25 +410,25 @@ describe('Critical Error Handling', () => {
410410
} as PersistedState;
411411

412412
const testMigrationList = {
413-
103: (state: unknown) => ({ ...(state as object), step103: true }),
414-
104: (state: unknown) => ({ ...(state as object), step104: true }),
415413
105: (state: unknown) => ({ ...(state as object), step105: true }),
414+
106: (state: unknown) => ({ ...(state as object), step106: true }),
415+
107: (state: unknown) => ({ ...(state as object), step107: true }),
416416
};
417417

418418
const asyncMigrations = asyncifyMigrations(testMigrationList);
419419

420420
// Act - Run migrations in sequence
421421
let state = stateWithoutControllers;
422-
state = (await asyncMigrations['103'](state)) as PersistedState;
423-
state = (await asyncMigrations['104'](state)) as PersistedState;
424-
const finalState = await asyncMigrations['105'](state);
422+
state = (await asyncMigrations['105'](state)) as PersistedState;
423+
state = (await asyncMigrations['106'](state)) as PersistedState;
424+
const finalState = await asyncMigrations['107'](state);
425425

426426
// Assert
427-
expect((finalState as Record<string, unknown>).step103).toBe(true);
428-
expect((finalState as Record<string, unknown>).step104).toBe(true);
429427
expect((finalState as Record<string, unknown>).step105).toBe(true);
428+
expect((finalState as Record<string, unknown>).step106).toBe(true);
429+
expect((finalState as Record<string, unknown>).step107).toBe(true);
430430

431-
// Inflation should only be called once for migration 105
431+
// Inflation should only be called once for migration 107 (> 106)
432432
expect(
433433
mockedControllerStorage.getAllPersistedState,
434434
).toHaveBeenCalledTimes(1);

app/store/migrations/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const migrationList: MigrationsList = {
229229
103: migration103,
230230
104: migration104,
231231
105: migration105,
232-
106: migration106
232+
106: migration106,
233233
};
234234

235235
// Enable both synchronous and asynchronous migrations

0 commit comments

Comments
 (0)