2016-09-21 03:07:32 +00:00
|
|
|
import { mount } from 'enzyme';
|
2016-10-19 20:22:18 +00:00
|
|
|
|
2016-09-21 03:07:32 +00:00
|
|
|
import ConnectedAdminRoutes from './AuthenticatedAdminRoutes';
|
|
|
|
import { connectedComponent, reduxMockStore } from '../../test/helpers';
|
|
|
|
|
|
|
|
describe('AuthenticatedAdminRoutes - layout', () => {
|
|
|
|
const redirectToHomeAction = {
|
|
|
|
type: '@@router/CALL_HISTORY_METHOD',
|
|
|
|
payload: {
|
|
|
|
method: 'push',
|
|
|
|
args: ['/'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('redirects to the homepage if the user is not an admin', () => {
|
|
|
|
const user = { id: 1, admin: false };
|
|
|
|
const storeWithoutAdminUser = { auth: { user } };
|
|
|
|
const mockStore = reduxMockStore(storeWithoutAdminUser);
|
|
|
|
mount(
|
2020-07-07 02:31:48 +00:00
|
|
|
connectedComponent(ConnectedAdminRoutes, { mockStore }),
|
2016-09-21 03:07:32 +00:00
|
|
|
);
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(mockStore.getActions()).toContainEqual(redirectToHomeAction);
|
2016-09-21 03:07:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not redirect if the user is an admin', () => {
|
|
|
|
const user = { id: 1, admin: true };
|
|
|
|
const storeWithAdminUser = { auth: { user } };
|
|
|
|
const mockStore = reduxMockStore(storeWithAdminUser);
|
|
|
|
mount(
|
2020-07-07 02:31:48 +00:00
|
|
|
connectedComponent(ConnectedAdminRoutes, { mockStore }),
|
2016-09-21 03:07:32 +00:00
|
|
|
);
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(mockStore.getActions()).not.toContainEqual(redirectToHomeAction);
|
2016-09-21 03:07:32 +00:00
|
|
|
});
|
|
|
|
});
|