diff --git a/app/store/middleware.js b/app/store/middleware.js index fd352e2ab..de8c53468 100644 --- a/app/store/middleware.js +++ b/app/store/middleware.js @@ -348,7 +348,7 @@ function cleanupState(action, keepCurrent = false) { nextState.errors = payload.errors; return { - type: 'persist/REHYDRATE', + type: action.type, payload: nextState, error: action.error, }; diff --git a/app/store/middleware.test.js b/app/store/middleware.test.js new file mode 100644 index 000000000..93738be70 --- /dev/null +++ b/app/store/middleware.test.js @@ -0,0 +1,73 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +/* eslint-disable max-nested-callbacks */ + +import assert from 'assert'; + +import {ViewTypes} from 'app/constants'; +import {messageRetention} from 'app/store/middleware'; + +jest.mock('react-native-fetch-blob', () => { + return { + DocumentDir: () => null, + polyfill: () => null, + fs: { + dirs: { + }, + }, + }; +}); + +jest.mock('react-native-device-info', () => { + return { + getVersion: () => '0.0.0', + getBuildNumber: () => '0', + }; +}); + +describe('store/middleware', () => { + describe('messageRetention', () => { + describe('should chain the same incoming action type', () => { + const actions = [ + { + type: 'persist/REHYDRATE', + payload: { + views: { + team: { + }, + }, + }, + }, + { + type: ViewTypes.DATA_CLEANUP, + payload: { + entities: { + channels: { + }, + posts: { + }, + }, + views: { + team: { + }, + }, + }, + }, + { + type: 'other', + }, + ]; + + actions.forEach((action) => { + it(`for action type ${action.type}`, () => { + const store = {}; + const next = (a) => a; + + const nextAction = messageRetention(store)(next)(action); + assert.equal(action.type, nextAction.type); + }); + }); + }); + }); +});