mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-31 19:17:48 +00:00
Due to the pattern `**/specs/*.spec.js` defined in CircleCI, none of the frontend spec in the folders such as `specs/<domain-name>/getters.spec.js` were not executed in Circle CI. This PR fixes the issue, along with the following changes: - Use vitest instead of jest - Remove jest dependancies - Update tests to work with vitest --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
import { validateAuthenticateRoutePermission } from './index';
|
|
|
|
describe('#validateAuthenticateRoutePermission', () => {
|
|
describe(`when route is protected`, () => {
|
|
describe(`when user not logged in`, () => {
|
|
it(`should redirect to login`, () => {
|
|
const to = { name: 'some-protected-route', params: { accountId: 1 } };
|
|
const next = vi.fn();
|
|
const getters = {
|
|
isLoggedIn: false,
|
|
getCurrentUser: {
|
|
account_id: null,
|
|
id: null,
|
|
accounts: [],
|
|
},
|
|
};
|
|
|
|
expect(validateAuthenticateRoutePermission(to, next, { getters })).toBe(
|
|
'/app/login'
|
|
);
|
|
});
|
|
});
|
|
describe(`when user is logged in`, () => {
|
|
describe(`when route is not accessible to current user`, () => {
|
|
it(`should redirect to dashboard`, () => {
|
|
const to = {
|
|
name: 'general_settings_index',
|
|
params: { accountId: 1 },
|
|
meta: { permissions: ['administrator'] },
|
|
};
|
|
const next = vi.fn();
|
|
const getters = {
|
|
isLoggedIn: true,
|
|
getCurrentUser: {
|
|
account_id: 1,
|
|
id: 1,
|
|
permissions: ['agent'],
|
|
accounts: [{ id: 1, role: 'agent', status: 'active' }],
|
|
},
|
|
};
|
|
validateAuthenticateRoutePermission(to, next, { getters });
|
|
expect(next).toHaveBeenCalledWith('/app/accounts/1/dashboard');
|
|
});
|
|
});
|
|
describe(`when route is accessible to current user`, () => {
|
|
it(`should go there`, () => {
|
|
const to = {
|
|
name: 'general_settings_index',
|
|
params: { accountId: 1 },
|
|
meta: { permissions: ['administrator'] },
|
|
};
|
|
const next = vi.fn();
|
|
const getters = {
|
|
isLoggedIn: true,
|
|
getCurrentUser: {
|
|
account_id: 1,
|
|
id: 1,
|
|
permissions: ['administrator'],
|
|
accounts: [{ id: 1, role: 'administrator', status: 'active' }],
|
|
},
|
|
};
|
|
validateAuthenticateRoutePermission(to, next, { getters });
|
|
expect(next).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|