Automated cherry pick of #3819 (#3822)

* Dispatch loadConfigAndLicense on successful login

* Emit server version changed event

* Make linter happy

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
Mattermost Build
2020-01-20 16:31:17 +01:00
committed by Miguel Alatzar
parent 373eb17236
commit f28b9b3a64
4 changed files with 48 additions and 1 deletions

View File

@@ -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);

View File

@@ -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();
});
});

View File

@@ -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) {

View File

@@ -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);
});
});