fix: Allow users to login even if they have access to more than 15 accounts (#4475)
This commit is contained in:
@@ -29,7 +29,9 @@ describe('#actions', () => {
|
||||
});
|
||||
await actions.validityCheck({ commit });
|
||||
expect(setUser).toHaveBeenCalledTimes(1);
|
||||
expect(commit.mock.calls).toEqual([[types.default.SET_CURRENT_USER]]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_CURRENT_USER, { id: 1, name: 'John' }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({
|
||||
@@ -47,8 +49,9 @@ describe('#actions', () => {
|
||||
headers: { expiry: 581842904 },
|
||||
});
|
||||
await actions.updateProfile({ commit }, { name: 'Pranav' });
|
||||
expect(setUser).toHaveBeenCalledTimes(1);
|
||||
expect(commit.mock.calls).toEqual([[types.default.SET_CURRENT_USER]]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_CURRENT_USER, { id: 1, name: 'John' }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,7 +60,8 @@ describe('#actions', () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: {
|
||||
id: 1,
|
||||
account_users: [{ account_id: 1, availability_status: 'offline' }],
|
||||
name: 'John',
|
||||
accounts: [{ account_id: 1, availability_status: 'offline' }],
|
||||
},
|
||||
headers: { expiry: 581842904 },
|
||||
});
|
||||
@@ -65,8 +69,16 @@ describe('#actions', () => {
|
||||
{ commit, dispatch },
|
||||
{ availability: 'offline', account_id: 1 }
|
||||
);
|
||||
expect(setUser).toHaveBeenCalledTimes(1);
|
||||
expect(commit.mock.calls).toEqual([[types.default.SET_CURRENT_USER]]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.default.SET_CURRENT_USER,
|
||||
{
|
||||
id: 1,
|
||||
name: 'John',
|
||||
accounts: [{ account_id: 1, availability_status: 'offline' }],
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
['agents/updatePresence', { 1: 'offline' }],
|
||||
]);
|
||||
@@ -88,13 +100,20 @@ describe('#actions', () => {
|
||||
{ commit, dispatch },
|
||||
{ uiSettings: { is_contact_sidebar_open: false } }
|
||||
);
|
||||
expect(setUser).toHaveBeenCalledTimes(1);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.default.SET_CURRENT_USER_UI_SETTINGS,
|
||||
{ uiSettings: { is_contact_sidebar_open: false } },
|
||||
],
|
||||
[types.default.SET_CURRENT_USER],
|
||||
[
|
||||
types.default.SET_CURRENT_USER,
|
||||
{
|
||||
id: 1,
|
||||
name: 'John',
|
||||
availability_status: 'offline',
|
||||
ui_settings: { is_contact_sidebar_open: true },
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -103,14 +122,17 @@ describe('#actions', () => {
|
||||
it('sends correct actions if user is logged in', async () => {
|
||||
Cookies.getJSON.mockImplementation(() => true);
|
||||
actions.setUser({ commit, dispatch });
|
||||
expect(commit.mock.calls).toEqual([[types.default.SET_CURRENT_USER]]);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
expect(dispatch.mock.calls).toEqual([['validityCheck']]);
|
||||
});
|
||||
|
||||
it('sends correct actions if user is not logged in', async () => {
|
||||
Cookies.getJSON.mockImplementation(() => false);
|
||||
actions.setUser({ commit, dispatch });
|
||||
expect(commit.mock.calls).toEqual([[types.default.CLEAR_USER]]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.CLEAR_USER],
|
||||
[types.default.SET_CURRENT_USER_UI_FLAGS, { isFetching: false }],
|
||||
]);
|
||||
expect(dispatch).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,39 +4,74 @@ import '../../../../routes';
|
||||
|
||||
jest.mock('../../../../routes', () => {});
|
||||
describe('#getters', () => {
|
||||
it('isLoggedIn', () => {
|
||||
expect(getters.isLoggedIn({ currentUser: { id: null } })).toEqual(false);
|
||||
expect(getters.isLoggedIn({ currentUser: { id: 1 } })).toEqual(true);
|
||||
describe('#isLoggedIn', () => {
|
||||
it('return correct value if user data is available', () => {
|
||||
expect(getters.isLoggedIn({ currentUser: { id: null } })).toEqual(false);
|
||||
expect(getters.isLoggedIn({ currentUser: { id: 1 } })).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('getCurrentUserID', () => {
|
||||
expect(getters.getCurrentUserID({ currentUser: { id: 1 } })).toEqual(1);
|
||||
});
|
||||
it('getCurrentUser', () => {
|
||||
expect(
|
||||
getters.getCurrentUser({ currentUser: { id: 1, name: 'Pranav' } })
|
||||
).toEqual({ id: 1, name: 'Pranav' });
|
||||
describe('#getCurrentUser', () => {
|
||||
it('returns current user id', () => {
|
||||
expect(getters.getCurrentUserID({ currentUser: { id: 1 } })).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('get', () => {
|
||||
expect(
|
||||
getters.getCurrentUserAvailability({
|
||||
currentAccountId: 1,
|
||||
currentUser: {
|
||||
id: 1,
|
||||
accounts: [{ id: 1, availability: 'busy' }],
|
||||
},
|
||||
})
|
||||
).toEqual('busy');
|
||||
describe('#getCurrentUser', () => {
|
||||
it('returns current user object', () => {
|
||||
expect(
|
||||
getters.getCurrentUser({ currentUser: { id: 1, name: 'Pranav' } })
|
||||
).toEqual({ id: 1, name: 'Pranav' });
|
||||
});
|
||||
});
|
||||
|
||||
it('getUISettings', () => {
|
||||
expect(
|
||||
getters.getUISettings({
|
||||
currentUser: { ui_settings: { is_contact_sidebar_open: true } },
|
||||
})
|
||||
).toEqual({ is_contact_sidebar_open: true });
|
||||
describe('#getCurrentRole', () => {
|
||||
it('returns current role if account is available', () => {
|
||||
expect(
|
||||
getters.getCurrentRole(
|
||||
{ currentUser: { accounts: [{ id: 1, role: 'admin' }] } },
|
||||
{ getCurrentAccountId: 1 }
|
||||
)
|
||||
).toEqual('admin');
|
||||
});
|
||||
|
||||
it('returns undefined if account is not available', () => {
|
||||
expect(
|
||||
getters.getCurrentRole(
|
||||
{ currentUser: { accounts: [{ id: 1, role: 'admin' }] } },
|
||||
{ getCurrentAccountId: 2 }
|
||||
)
|
||||
).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCurrentUserAvailability', () => {
|
||||
it('returns correct availability status', () => {
|
||||
expect(
|
||||
getters.getCurrentUserAvailability(
|
||||
{
|
||||
currentAccountId: 1,
|
||||
currentUser: {
|
||||
id: 1,
|
||||
accounts: [{ id: 1, availability: 'busy' }],
|
||||
},
|
||||
},
|
||||
{ getCurrentAccountId: 1 }
|
||||
)
|
||||
).toEqual('busy');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUISettings', () => {
|
||||
it('return correct UI Settings', () => {
|
||||
expect(
|
||||
getters.getUISettings({
|
||||
currentUser: { ui_settings: { is_contact_sidebar_open: true } },
|
||||
})
|
||||
).toEqual({ is_contact_sidebar_open: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMessageSignature', () => {
|
||||
it('Return signature when signature is present', () => {
|
||||
expect(
|
||||
@@ -46,11 +81,7 @@ describe('#getters', () => {
|
||||
).toEqual('Thanks');
|
||||
});
|
||||
it('Return empty string when signature is not present', () => {
|
||||
expect(
|
||||
getters.getMessageSignature({
|
||||
currentUser: {},
|
||||
})
|
||||
).toEqual('');
|
||||
expect(getters.getMessageSignature({ currentUser: {} })).toEqual('');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,22 +90,23 @@ describe('#getters', () => {
|
||||
expect(
|
||||
getters.getCurrentAccount({
|
||||
currentUser: {},
|
||||
currentAccountId: 1,
|
||||
})
|
||||
).toEqual({});
|
||||
|
||||
expect(
|
||||
getters.getCurrentAccount({
|
||||
currentUser: {
|
||||
accounts: [
|
||||
{
|
||||
name: 'Chatwoot',
|
||||
id: 1,
|
||||
},
|
||||
],
|
||||
getters.getCurrentAccount(
|
||||
{
|
||||
currentUser: {
|
||||
accounts: [
|
||||
{
|
||||
name: 'Chatwoot',
|
||||
id: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
currentAccountId: 1,
|
||||
},
|
||||
currentAccountId: 1,
|
||||
})
|
||||
{ getCurrentAccountId: 1 }
|
||||
)
|
||||
).toEqual({
|
||||
name: 'Chatwoot',
|
||||
id: 1,
|
||||
@@ -89,7 +121,6 @@ describe('#getters', () => {
|
||||
currentUser: {},
|
||||
})
|
||||
).toEqual([]);
|
||||
|
||||
expect(
|
||||
getters.getUserAccounts({
|
||||
currentUser: {
|
||||
|
||||
@@ -18,4 +18,28 @@ describe('#mutations', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('#SET_CURRENT_USER_UI_FLAGS', () => {
|
||||
it('set auth ui flags', () => {
|
||||
const state = {
|
||||
uiFlags: { isFetching: false },
|
||||
};
|
||||
mutations[types.SET_CURRENT_USER_UI_FLAGS](state, { isFetching: true });
|
||||
expect(state.uiFlags.isFetching).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('#CLEAR_USER', () => {
|
||||
it('set auth ui flags', () => {
|
||||
const state = {
|
||||
currentUser: { id: 1 },
|
||||
};
|
||||
mutations[types.CLEAR_USER](state);
|
||||
expect(state.currentUser).toEqual({
|
||||
id: null,
|
||||
account_id: null,
|
||||
accounts: [],
|
||||
email: null,
|
||||
name: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user