Files
chatwoot/app/javascript/dashboard/routes/index.spec.js
Pranav 9de8c27368 feat: Use vitest instead of jest, run all the specs anywhere in app/ folder in the CI (#9722)
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>
2024-07-10 08:32:16 -07:00

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