From f4e180d339ad529cff8296d09cf45f9d9b0cfd91 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Fri, 24 Apr 2020 20:17:07 +0200 Subject: [PATCH] Automated cherry pick of #4225 (#4228) * MM-24451 Set prev app version to current on logout/reset cache * Fix unit tests for master Co-authored-by: Elias Nahum --- app/init/global_event_handler.js | 2 +- app/store/utils.js | 5 ++++- app/store/utils.test.js | 10 ++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/init/global_event_handler.js b/app/init/global_event_handler.js index 9bc18c0f7..429ed41a5 100644 --- a/app/init/global_event_handler.js +++ b/app/init/global_event_handler.js @@ -279,7 +279,7 @@ class GlobalEventHandler { app: { build: DeviceInfo.getBuildNumber(), version: DeviceInfo.getVersion(), - previousVersion: state.app?.previousVersion || DeviceInfo.getVersion(), + previousVersion: DeviceInfo.getVersion(), }, entities: { ...initialState.entities, diff --git a/app/store/utils.js b/app/store/utils.js index db4edb944..9bafa74af 100644 --- a/app/store/utils.js +++ b/app/store/utils.js @@ -86,7 +86,10 @@ export function getStateForReset(initialState, currentState) { }); const resetState = merge(initialState, { - app, + app: { + ...app, + previousVersion: DeviceInfo.getVersion(), + }, entities: { general: currentState.entities.general, users: { diff --git a/app/store/utils.test.js b/app/store/utils.test.js index b91302b7e..64095970c 100644 --- a/app/store/utils.test.js +++ b/app/store/utils.test.js @@ -1,6 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import DeviceInfo from 'react-native-device-info'; + import initialState from '@store/initial_state'; import {getStateForReset} from '@store/utils'; @@ -21,8 +23,8 @@ describe('getStateForReset', () => { const currentTeamId = 'current-team-id'; const currentState = { app: { - build: 'build', - version: 'version', + build: DeviceInfo.getBuildNumber(), + version: DeviceInfo.getVersion(), previousVersion: 'previousVersion', }, entities: { @@ -87,9 +89,9 @@ describe('getStateForReset', () => { expect(themeKeys.length).toEqual(preferenceKeys.length); }); - it('should keep app', () => { + it('should set previous version as current', () => { const resetState = getStateForReset(initialState, currentState); const {app} = resetState; - expect(app).toStrictEqual(currentState.app); + expect(app.previousVersion).toStrictEqual(currentState.app.version); }); });