Migrate completedOnboarding and firstTimeFlowType state into onboardingController (#12356)
* migrate completedOnboarding state into onboardingController * migrate firstTimeFlowType state from preferencesController to onboardingControllerfeature/default_network_editable
parent
9cff1cb949
commit
71f91568db
@ -0,0 +1,39 @@ |
||||
import { cloneDeep } from 'lodash'; |
||||
|
||||
const version = 65; |
||||
|
||||
/** |
||||
* Removes metaMetricsSendCount from MetaMetrics controller |
||||
*/ |
||||
export default { |
||||
version, |
||||
async migrate(originalVersionedData) { |
||||
const versionedData = cloneDeep(originalVersionedData); |
||||
versionedData.meta.version = version; |
||||
const state = versionedData.data; |
||||
const newState = transformState(state); |
||||
versionedData.data = newState; |
||||
return versionedData; |
||||
}, |
||||
}; |
||||
|
||||
function transformState(state) { |
||||
if (state.PreferencesController) { |
||||
const { |
||||
completedOnboarding, |
||||
firstTimeFlowType, |
||||
} = state.PreferencesController; |
||||
state.OnboardingController = state.OnboardingController ?? {}; |
||||
|
||||
if (completedOnboarding !== undefined) { |
||||
state.OnboardingController.completedOnboarding = completedOnboarding; |
||||
delete state.PreferencesController.completedOnboarding; |
||||
} |
||||
if (firstTimeFlowType !== undefined) { |
||||
state.OnboardingController.firstTimeFlowType = firstTimeFlowType; |
||||
delete state.PreferencesController.firstTimeFlowType; |
||||
} |
||||
} |
||||
|
||||
return state; |
||||
} |
@ -0,0 +1,145 @@ |
||||
import migration65 from './065'; |
||||
|
||||
describe('migration #65', () => { |
||||
it('should update the version metadata', async () => { |
||||
const oldStorage = { |
||||
meta: { |
||||
version: 64, |
||||
}, |
||||
data: {}, |
||||
}; |
||||
|
||||
const newStorage = await migration65.migrate(oldStorage); |
||||
expect(newStorage.meta).toStrictEqual({ |
||||
version: 65, |
||||
}); |
||||
}); |
||||
|
||||
it('should move completedOnboarding from PreferencesController to OnboardingController when completedOnboarding is true', async () => { |
||||
const oldStorage = { |
||||
meta: {}, |
||||
data: { |
||||
PreferencesController: { |
||||
completedOnboarding: true, |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
foo: 'bar', |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration65.migrate(oldStorage); |
||||
expect(newStorage.data).toStrictEqual({ |
||||
PreferencesController: { |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
completedOnboarding: true, |
||||
foo: 'bar', |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should move completedOnboarding from PreferencesController to OnboardingController when completedOnboarding is false', async () => { |
||||
const oldStorage = { |
||||
meta: {}, |
||||
data: { |
||||
PreferencesController: { |
||||
completedOnboarding: false, |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
foo: 'bar', |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration65.migrate(oldStorage); |
||||
expect(newStorage.data).toStrictEqual({ |
||||
PreferencesController: { |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
completedOnboarding: false, |
||||
foo: 'bar', |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should move firstTimeFlowType from PreferencesController to OnboardingController when firstTimeFlowType is truthy', async () => { |
||||
const oldStorage = { |
||||
meta: {}, |
||||
data: { |
||||
PreferencesController: { |
||||
firstTimeFlowType: 'create', |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
foo: 'bar', |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration65.migrate(oldStorage); |
||||
expect(newStorage.data).toStrictEqual({ |
||||
PreferencesController: { |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
firstTimeFlowType: 'create', |
||||
foo: 'bar', |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should move firstTimeFlowType from PreferencesController to OnboardingController when firstTimeFlowType is falsy', async () => { |
||||
const oldStorage = { |
||||
meta: {}, |
||||
data: { |
||||
PreferencesController: { |
||||
firstTimeFlowType: null, |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
foo: 'bar', |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration65.migrate(oldStorage); |
||||
expect(newStorage.data).toStrictEqual({ |
||||
PreferencesController: { |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
firstTimeFlowType: null, |
||||
foo: 'bar', |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
it('should not modify PreferencesController or OnboardingController when completedOnboarding and firstTimeFlowType are undefined', async () => { |
||||
const oldStorage = { |
||||
meta: {}, |
||||
data: { |
||||
PreferencesController: { |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
foo: 'bar', |
||||
}, |
||||
}, |
||||
}; |
||||
|
||||
const newStorage = await migration65.migrate(oldStorage); |
||||
expect(newStorage.data).toStrictEqual({ |
||||
PreferencesController: { |
||||
bar: 'baz', |
||||
}, |
||||
OnboardingController: { |
||||
foo: 'bar', |
||||
}, |
||||
}); |
||||
}); |
||||
}); |
Loading…
Reference in new issue