From da701268d5d4da98e9103f89e22bab1640b3e23a Mon Sep 17 00:00:00 2001 From: Miguel Alatzar Date: Wed, 22 Apr 2020 21:04:24 -0700 Subject: [PATCH] [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 --- app/init/global_event_handler.js | 1 + app/store/utils.js | 7 ++----- app/store/utils.test.js | 11 +++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/init/global_event_handler.js b/app/init/global_event_handler.js index e830c10b5..5418052bf 100644 --- a/app/init/global_event_handler.js +++ b/app/init/global_event_handler.js @@ -280,6 +280,7 @@ class GlobalEventHandler { app: { build: DeviceInfo.getBuildNumber(), version: DeviceInfo.getVersion(), + previousVersion: state.app?.previousVersion || DeviceInfo.getVersion(), }, }, }, diff --git a/app/store/utils.js b/app/store/utils.js index 74b75b433..5680af4a5 100644 --- a/app/store/utils.js +++ b/app/store/utils.js @@ -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, diff --git a/app/store/utils.test.js b/app/store/utils.test.js index 305fbce97..c8dac7cdd 100644 --- a/app/store/utils.test.js +++ b/app/store/utils.test.js @@ -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); + }); });