[MM-24451] Handle setting previousVersion on logout and clearing data (#4205)

* Handle setting previousVersion on login and clearing data

* Fix unused import error

* Update test

* Just add previous version on logout
This commit is contained in:
Miguel Alatzar 2020-04-22 21:04:24 -07:00 committed by GitHub
parent 318cd13064
commit da701268d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -280,6 +280,7 @@ class GlobalEventHandler {
app: {
build: DeviceInfo.getBuildNumber(),
version: DeviceInfo.getVersion(),
previousVersion: state.app?.previousVersion || DeviceInfo.getVersion(),
},
},
},

View file

@ -2,7 +2,6 @@
// See LICENSE.txt for license information.
import merge from 'deepmerge';
import DeviceInfo from 'react-native-device-info';
function transformFromSet(incoming) {
const state = {...incoming};
@ -67,6 +66,7 @@ export function waitForHydration(store, callback) {
}
export function getStateForReset(initialState, currentState) {
const {app} = currentState;
const {currentUserId} = currentState.entities.users;
const currentUserProfile = currentState.entities.users.profiles[currentUserId];
const {currentTeamId} = currentState.entities.teams;
@ -78,10 +78,7 @@ export function getStateForReset(initialState, currentState) {
});
const resetState = merge(initialState, {
app: {
build: DeviceInfo.getBuildNumber(),
version: DeviceInfo.getVersion(),
},
app,
entities: {
users: {
currentUserId,

View file

@ -20,6 +20,11 @@ describe('getStateForReset', () => {
const otherUserId = 'other-user-id';
const currentTeamId = 'current-team-id';
const currentState = {
app: {
build: 'build',
version: 'version',
previousVersion: 'previousVersion',
},
entities: {
users: {
currentUserId,
@ -76,4 +81,10 @@ describe('getStateForReset', () => {
expect(themeKeys.length).not.toEqual(0);
expect(themeKeys.length).toEqual(preferenceKeys.length);
});
it('should keep app', () => {
const resetState = getStateForReset(initialState, currentState);
const {app} = resetState;
expect(app).toStrictEqual(currentState.app);
});
});