diff --git a/app/actions/views/login.js b/app/actions/views/login.js index c2416b143..c5d762e9f 100644 --- a/app/actions/views/login.js +++ b/app/actions/views/login.js @@ -17,6 +17,7 @@ import {setAppCredentials} from 'app/init/credentials'; import PushNotifications from 'app/push_notifications'; import {getDeviceTimezoneAsync} from 'app/utils/timezone'; import {setCSRFFromCookie} from 'app/utils/security'; +import {loadConfigAndLicense} from 'app/actions/views/root'; export function handleLoginIdChanged(loginId) { return async (dispatch, getState) => { @@ -38,6 +39,8 @@ export function handlePasswordChanged(password) { export function handleSuccessfulLogin() { return async (dispatch, getState) => { + await dispatch(loadConfigAndLicense()); + const state = getState(); const config = getConfig(state); const license = getLicense(state); diff --git a/app/actions/views/login.test.js b/app/actions/views/login.test.js index f75dee2f2..7960d67db 100644 --- a/app/actions/views/login.test.js +++ b/app/actions/views/login.test.js @@ -4,11 +4,14 @@ import configureStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import * as GeneralActions from 'mattermost-redux/actions/general'; + import {ViewTypes} from 'app/constants'; import { handleLoginIdChanged, handlePasswordChanged, + handleSuccessfulLogin, } from 'app/actions/views/login'; jest.mock('app/init/credentials', () => ({ @@ -36,7 +39,16 @@ describe('Actions.Views.Login', () => { let store; beforeEach(() => { - store = mockStore({}); + store = mockStore({ + entities: { + users: { + currentUserId: 'current-user-id', + }, + general: { + config: {}, + }, + }, + }); }); test('handleLoginIdChanged', () => { @@ -60,4 +72,13 @@ describe('Actions.Views.Login', () => { store.dispatch(handlePasswordChanged(password)); expect(store.getActions()).toEqual([action]); }); + + test('handleSuccessfulLogin gets config and license ', async () => { + const getClientConfig = jest.spyOn(GeneralActions, 'getClientConfig'); + const getLicenseConfig = jest.spyOn(GeneralActions, 'getLicenseConfig'); + + await store.dispatch(handleSuccessfulLogin()); + expect(getClientConfig).toHaveBeenCalled(); + expect(getLicenseConfig).toHaveBeenCalled(); + }); }); diff --git a/app/init/fetch.js b/app/init/fetch.js index edd05091e..3abc59ecd 100644 --- a/app/init/fetch.js +++ b/app/init/fetch.js @@ -8,6 +8,8 @@ import urlParse from 'url-parse'; import {Client4} from 'mattermost-redux/client'; import {ClientError, HEADER_X_VERSION_ID} from 'mattermost-redux/client/client4'; +import EventEmitter from 'mattermost-redux/utils/event_emitter'; +import {General} from 'mattermost-redux/constants'; import mattermostBucket from 'app/mattermost_bucket'; import mattermostManaged from 'app/mattermost_managed'; @@ -112,6 +114,7 @@ Client4.doFetchWithResponse = async (url, options) => { const serverVersion = headers[HEADER_X_VERSION_ID] || headers[HEADER_X_VERSION_ID.toLowerCase()]; if (serverVersion && !headers['Cache-Control'] && Client4.serverVersion !== serverVersion) { Client4.serverVersion = serverVersion; /* eslint-disable-line require-atomic-updates */ + EventEmitter.emit(General.SERVER_VERSION_CHANGED, serverVersion); } if (response.ok) { diff --git a/app/init/fetch.test.js b/app/init/fetch.test.js index 316fc53c6..4255d5d27 100644 --- a/app/init/fetch.test.js +++ b/app/init/fetch.test.js @@ -3,6 +3,8 @@ import {Client4} from 'mattermost-redux/client'; import {HEADER_X_VERSION_ID} from 'mattermost-redux/client/client4'; +import EventEmitter from 'mattermost-redux/utils/event_emitter'; +import {General} from 'mattermost-redux/constants'; import { HEADER_X_CLUSTER_ID, @@ -61,4 +63,22 @@ describe('Fetch', () => { expect(Client4.clusterId).toEqual(headers[HEADER_X_CLUSTER_ID.toLowerCase()]); expect(setToken).toHaveBeenCalledWith(headers[HEADER_TOKEN.toLowerCase()]); }); + + test('doFetchWithResponse handles server version change', async () => { + const emit = jest.spyOn(EventEmitter, 'emit'); + const serverVersion1 = 'version1'; + const response = { + json: () => Promise.resolve('data'), + ok: true, + headers: { + [HEADER_X_VERSION_ID]: serverVersion1, + }, + }; + global.fetch.mockReturnValueOnce(response); + + expect(Client4.serverVersion).not.toEqual(serverVersion1); + await Client4.doFetchWithResponse('https://mattermost.com', {method: 'GET'}); + expect(Client4.serverVersion).toEqual(serverVersion1); + expect(emit).toHaveBeenCalledWith(General.SERVER_VERSION_CHANGED, serverVersion1); + }); }); \ No newline at end of file