mattermost-mobile/app/mm-redux/actions/helpers.test.js
Daniel Espino García 4c8594d330
Add linter rules for import order and type member delimiters (#5514)
* Add linter rules for import order and type member delimiters

* Remove unneeded group

* Group all app/* imports before the internal imports

* Move app/ imports before parent imports

* Separate @node_modules imports into a different group

* Substitute app paths by aliases

* Fix @node_modules import order and add test related modules

* Add aliases for types and test, and group import types
2021-07-23 11:06:04 +02:00

106 lines
3.4 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import assert from 'assert';
import {Client4} from '@client/rest';
import ClientError from '@client/rest/error';
import {forceLogoutIfNecessary} from '@mm-redux/actions/helpers';
import configureStore, {mockDispatch} from '@test/test_store';
describe('Actions.Helpers', () => {
describe('forceLogoutIfNecessary', () => {
const token = 'token';
beforeEach(() => {
Client4.setToken(token);
});
it('should do nothing when passed a client error', async () => {
const store = await configureStore({
entities: {
users: {
currentUserId: 'user',
},
},
});
const dispatch = mockDispatch(store.dispatch);
const error = new ClientError(Client4.getUrl(), {
message: 'no internet connection',
url: '/api/v4/foo/bar',
});
forceLogoutIfNecessary(error, dispatch, store.getState);
assert.equal(Client4.token, token);
assert.deepEqual(dispatch.actions, []);
});
it('should do nothing when passed a non-401 server error', async () => {
const store = await configureStore({
entities: {
users: {
currentUserId: 'user',
},
},
});
const dispatch = mockDispatch(store.dispatch);
const error = new ClientError(Client4.getUrl(), {
message: 'Failed to do something',
status_code: 403,
url: '/api/v4/foo/bar',
});
forceLogoutIfNecessary(error, dispatch, store.getState);
assert.equal(Client4.token, token);
assert.deepEqual(dispatch.actions, []);
});
it('should do nothing when failing to log in', async () => {
const store = await configureStore({
entities: {
users: {
currentUserId: 'user',
},
},
});
const dispatch = mockDispatch(store.dispatch);
const error = new ClientError(Client4.getUrl(), {
message: 'Failed to do something',
status_code: 401,
url: '/api/v4/login',
});
forceLogoutIfNecessary(error, dispatch, store.getState);
assert.equal(Client4.token, token);
assert.deepEqual(dispatch.actions, []);
});
it('should do nothing when not logged in', async () => {
const store = await configureStore({
entities: {
users: {
currentUserId: '',
},
},
});
const dispatch = mockDispatch(store.dispatch);
const error = new ClientError(Client4.getUrl(), {
message: 'Failed to do something',
status_code: 401,
url: '/api/v4/foo/bar',
});
forceLogoutIfNecessary(error, dispatch, store.getState);
assert.equal(Client4.token, token);
assert.deepEqual(dispatch.actions, []);
});
});
});