1. Run tests
2. Add one more async migration and check if it works
Tests could not be added directly, this function will read something from local storage - that being said this test will fail, but code I used:
```
// @flow
import { creatAsyncMigrate } from './create-async-migrate.js';
describe('async redux migrations', () => {
it('should run migrations with async functions', async () => {
const persistedState = {
oldKey: 'oldKeyValue',
_persist: {
version: 1,
rehydrated: false,
},
};
const asyncMigrations = {
[1]: async state => {
return {
...state,
oldKey: 'oldKeyValue',
};
},
// needs to run
[2]: async state => {
return {
...state,
newKey: 'newKeyValue',
};
},
// needs to run
[3]: async state => {
return {
...state,
oldKey: 'oldKeyUpdated',
};
},
};
const migrate = creatAsyncMigrate(asyncMigrations, {
debug: true,
});
const currentVersion = 3;
const migratedState = await migrate(persistedState, currentVersion);
expect(migratedState).toEqual({
oldKey: 'oldKeyUpdated',
newKey: 'newKeyValue',
_persist: {
version: 1,
rehydrated: false,
},
});
});
it(`should do nothing when inboundVersion and currentVersion match`, async () => {
const persistedState = {
oldKey: 'oldKeyValue',
_persist: {
version: 3,
rehydrated: false,
},
};
const asyncMigrations = {
[1]: async state => {
return {
...state,
oldKey: 'oldKeyValue',
};
},
[2]: async state => {
return {
...state,
newKey: 'newKeyValue',
};
},
[3]: async state => {
return {
...state,
oldKey: 'oldKeyUpdated',
};
},
};
const migrate = creatAsyncMigrate(asyncMigrations, {
debug: true,
});
const currentVersion = 3;
const migratedState = await migrate(persistedState, currentVersion);
expect(migratedState).toEqual(persistedState);
});
it(`should return undefined for undefined persisted state`, async () => {
const persistedState = undefined;
const asyncMigrations = {
[1]: async state => {
return {
...state,
oldKey: 'oldKeyValue',
};
},
};
const migrate = creatAsyncMigrate(asyncMigrations, {
debug: true,
});
const currentVersion = 1;
const migratedState = await migrate(persistedState, currentVersion);
expect(migratedState).toBeUndefined();
});
});
```