Merge branch 'develop' into fix/hc-editor
This commit is contained in:
@@ -28,12 +28,16 @@ export const getters = {
|
||||
getUIFlags($state) {
|
||||
return $state.uiFlags;
|
||||
},
|
||||
isRTL: ($state, _, rootState) => {
|
||||
const accountId = rootState.route?.params?.accountId;
|
||||
if (!accountId) return false;
|
||||
isRTL: ($state, _getters, rootState, rootGetters) => {
|
||||
const accountId = Number(rootState.route?.params?.accountId);
|
||||
const userLocale = rootGetters?.getUISettings?.locale;
|
||||
const accountLocale =
|
||||
accountId && findRecordById($state, accountId)?.locale;
|
||||
|
||||
const { locale } = findRecordById($state, Number(accountId));
|
||||
return locale ? getLanguageDirection(locale) : false;
|
||||
// Prefer user locale; fallback to account locale
|
||||
const effectiveLocale = userLocale ?? accountLocale;
|
||||
|
||||
return effectiveLocale ? getLanguageDirection(effectiveLocale) : false;
|
||||
},
|
||||
isTrialAccount: $state => id => {
|
||||
const account = findRecordById($state, id);
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
||||
import types from '../mutation-types';
|
||||
import AgentCapacityPoliciesAPI from '../../api/agentCapacityPolicies';
|
||||
import { throwErrorMessage } from '../utils/api';
|
||||
import camelcaseKeys from 'camelcase-keys';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
|
||||
export const state = {
|
||||
records: [],
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
usersUiFlags: {
|
||||
isFetching: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
getAgentCapacityPolicies(_state) {
|
||||
return _state.records;
|
||||
},
|
||||
getUIFlags(_state) {
|
||||
return _state.uiFlags;
|
||||
},
|
||||
getUsersUIFlags(_state) {
|
||||
return _state.usersUiFlags;
|
||||
},
|
||||
getAgentCapacityPolicyById: _state => id => {
|
||||
return _state.records.find(record => record.id === Number(id)) || {};
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
get: async function get({ commit }) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.get();
|
||||
commit(
|
||||
types.SET_AGENT_CAPACITY_POLICIES,
|
||||
camelcaseKeys(response.data, { deep: true })
|
||||
);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
|
||||
show: async function show({ commit }, policyId) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetchingItem: true });
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.show(policyId);
|
||||
const policy = camelcaseKeys(response.data, { deep: true });
|
||||
commit(types.SET_AGENT_CAPACITY_POLICY, policy);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, {
|
||||
isFetchingItem: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
create: async function create({ commit }, policyObj) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.create(
|
||||
snakecaseKeys(policyObj)
|
||||
);
|
||||
commit(
|
||||
types.ADD_AGENT_CAPACITY_POLICY,
|
||||
camelcaseKeys(response.data, { deep: true })
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isCreating: false });
|
||||
}
|
||||
},
|
||||
|
||||
update: async function update({ commit }, { id, ...policyParams }) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isUpdating: true });
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.update(
|
||||
id,
|
||||
snakecaseKeys(policyParams)
|
||||
);
|
||||
commit(
|
||||
types.EDIT_AGENT_CAPACITY_POLICY,
|
||||
camelcaseKeys(response.data, { deep: true })
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isUpdating: false });
|
||||
}
|
||||
},
|
||||
|
||||
delete: async function deletePolicy({ commit }, policyId) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isDeleting: true });
|
||||
try {
|
||||
await AgentCapacityPoliciesAPI.delete(policyId);
|
||||
commit(types.DELETE_AGENT_CAPACITY_POLICY, policyId);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isDeleting: false });
|
||||
}
|
||||
},
|
||||
|
||||
getUsers: async function getUsers({ commit }, policyId) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, {
|
||||
isFetching: true,
|
||||
});
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.getUsers(policyId);
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_USERS, {
|
||||
policyId,
|
||||
users: camelcaseKeys(response.data),
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, {
|
||||
isFetching: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
addUser: async function addUser({ commit }, { policyId, userData }) {
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.addUser(
|
||||
policyId,
|
||||
userData
|
||||
);
|
||||
commit(types.ADD_AGENT_CAPACITY_POLICIES_USERS, {
|
||||
policyId,
|
||||
user: camelcaseKeys(response.data),
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
removeUser: async function removeUser({ commit }, { policyId, userId }) {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, {
|
||||
isDeleting: true,
|
||||
});
|
||||
try {
|
||||
await AgentCapacityPoliciesAPI.removeUser(policyId, userId);
|
||||
commit(types.DELETE_AGENT_CAPACITY_POLICIES_USERS, { policyId, userId });
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, {
|
||||
isDeleting: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
createInboxLimit: async function createInboxLimit(
|
||||
{ commit },
|
||||
{ policyId, limitData }
|
||||
) {
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.createInboxLimit(
|
||||
policyId,
|
||||
limitData
|
||||
);
|
||||
commit(
|
||||
types.SET_AGENT_CAPACITY_POLICIES_INBOXES,
|
||||
camelcaseKeys(response.data)
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
updateInboxLimit: async function updateInboxLimit(
|
||||
{ commit },
|
||||
{ policyId, limitId, limitData }
|
||||
) {
|
||||
try {
|
||||
const response = await AgentCapacityPoliciesAPI.updateInboxLimit(
|
||||
policyId,
|
||||
limitId,
|
||||
limitData
|
||||
);
|
||||
commit(
|
||||
types.EDIT_AGENT_CAPACITY_POLICIES_INBOXES,
|
||||
camelcaseKeys(response.data)
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
deleteInboxLimit: async function deleteInboxLimit(
|
||||
{ commit },
|
||||
{ policyId, limitId }
|
||||
) {
|
||||
try {
|
||||
await AgentCapacityPoliciesAPI.deleteInboxLimit(policyId, limitId);
|
||||
commit(types.DELETE_AGENT_CAPACITY_POLICIES_INBOXES, {
|
||||
policyId,
|
||||
limitId,
|
||||
});
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG](_state, data) {
|
||||
_state.uiFlags = {
|
||||
..._state.uiFlags,
|
||||
...data,
|
||||
};
|
||||
},
|
||||
|
||||
[types.SET_AGENT_CAPACITY_POLICIES]: MutationHelpers.set,
|
||||
[types.SET_AGENT_CAPACITY_POLICY]: MutationHelpers.setSingleRecord,
|
||||
[types.ADD_AGENT_CAPACITY_POLICY]: MutationHelpers.create,
|
||||
[types.EDIT_AGENT_CAPACITY_POLICY]: MutationHelpers.updateAttributes,
|
||||
[types.DELETE_AGENT_CAPACITY_POLICY]: MutationHelpers.destroy,
|
||||
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG](_state, data) {
|
||||
_state.usersUiFlags = {
|
||||
..._state.usersUiFlags,
|
||||
...data,
|
||||
};
|
||||
},
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_USERS](_state, { policyId, users }) {
|
||||
const policy = _state.records.find(p => p.id === policyId);
|
||||
if (policy) {
|
||||
policy.users = users;
|
||||
}
|
||||
},
|
||||
[types.ADD_AGENT_CAPACITY_POLICIES_USERS](_state, { policyId, user }) {
|
||||
const policy = _state.records.find(p => p.id === policyId);
|
||||
if (policy) {
|
||||
policy.users = policy.users || [];
|
||||
policy.users.push(user);
|
||||
policy.assignedAgentCount = policy.users.length;
|
||||
}
|
||||
},
|
||||
[types.DELETE_AGENT_CAPACITY_POLICIES_USERS](_state, { policyId, userId }) {
|
||||
const policy = _state.records.find(p => p.id === policyId);
|
||||
if (policy) {
|
||||
policy.users = (policy.users || []).filter(user => user.id !== userId);
|
||||
policy.assignedAgentCount = policy.users.length;
|
||||
}
|
||||
},
|
||||
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_INBOXES](_state, data) {
|
||||
const policy = _state.records.find(
|
||||
p => p.id === data.agentCapacityPolicyId
|
||||
);
|
||||
policy?.inboxCapacityLimits.push({
|
||||
id: data.id,
|
||||
inboxId: data.inboxId,
|
||||
conversationLimit: data.conversationLimit,
|
||||
});
|
||||
},
|
||||
[types.EDIT_AGENT_CAPACITY_POLICIES_INBOXES](_state, data) {
|
||||
const policy = _state.records.find(
|
||||
p => p.id === data.agentCapacityPolicyId
|
||||
);
|
||||
const limit = policy?.inboxCapacityLimits.find(l => l.id === data.id);
|
||||
if (limit) {
|
||||
Object.assign(limit, {
|
||||
conversationLimit: data.conversationLimit,
|
||||
});
|
||||
}
|
||||
},
|
||||
[types.DELETE_AGENT_CAPACITY_POLICIES_INBOXES](
|
||||
_state,
|
||||
{ policyId, limitId }
|
||||
) {
|
||||
const policy = _state.records.find(p => p.id === policyId);
|
||||
if (policy) {
|
||||
policy.inboxCapacityLimits = policy.inboxCapacityLimits.filter(
|
||||
limit => limit.id !== limitId
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
};
|
||||
@@ -0,0 +1,232 @@
|
||||
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
||||
import types from '../mutation-types';
|
||||
import AssignmentPoliciesAPI from '../../api/assignmentPolicies';
|
||||
import { throwErrorMessage } from '../utils/api';
|
||||
import camelcaseKeys from 'camelcase-keys';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
|
||||
export const state = {
|
||||
records: [],
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
inboxUiFlags: {
|
||||
isFetching: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
getAssignmentPolicies(_state) {
|
||||
return _state.records;
|
||||
},
|
||||
getUIFlags(_state) {
|
||||
return _state.uiFlags;
|
||||
},
|
||||
getInboxUiFlags(_state) {
|
||||
return _state.inboxUiFlags;
|
||||
},
|
||||
getAssignmentPolicyById: _state => id => {
|
||||
return _state.records.find(record => record.id === Number(id)) || {};
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
get: async function get({ commit }) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.get();
|
||||
commit(types.SET_ASSIGNMENT_POLICIES, camelcaseKeys(response.data));
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
|
||||
show: async function show({ commit }, policyId) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: true });
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.show(policyId);
|
||||
const policy = camelcaseKeys(response.data);
|
||||
commit(types.SET_ASSIGNMENT_POLICY, policy);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: false });
|
||||
}
|
||||
},
|
||||
|
||||
create: async function create({ commit }, policyObj) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.create(
|
||||
snakecaseKeys(policyObj)
|
||||
);
|
||||
commit(types.ADD_ASSIGNMENT_POLICY, camelcaseKeys(response.data));
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: false });
|
||||
}
|
||||
},
|
||||
|
||||
update: async function update({ commit }, { id, ...policyParams }) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: true });
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.update(
|
||||
id,
|
||||
snakecaseKeys(policyParams)
|
||||
);
|
||||
commit(types.EDIT_ASSIGNMENT_POLICY, camelcaseKeys(response.data));
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: false });
|
||||
}
|
||||
},
|
||||
|
||||
delete: async function deletePolicy({ commit }, policyId) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: true });
|
||||
try {
|
||||
await AssignmentPoliciesAPI.delete(policyId);
|
||||
commit(types.DELETE_ASSIGNMENT_POLICY, policyId);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: false });
|
||||
}
|
||||
},
|
||||
|
||||
getInboxes: async function getInboxes({ commit }, policyId) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isFetching: true });
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.getInboxes(policyId);
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES, {
|
||||
policyId,
|
||||
inboxes: camelcaseKeys(response.data.inboxes),
|
||||
});
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, {
|
||||
isFetching: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
setInboxPolicy: async function setInboxPolicy(
|
||||
{ commit },
|
||||
{ inboxId, policyId }
|
||||
) {
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.setInboxPolicy(
|
||||
inboxId,
|
||||
policyId
|
||||
);
|
||||
commit(
|
||||
types.ADD_ASSIGNMENT_POLICIES_INBOXES,
|
||||
camelcaseKeys(response.data)
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getInboxPolicy: async function getInboxPolicy(_, { inboxId }) {
|
||||
try {
|
||||
const response = await AssignmentPoliciesAPI.getInboxPolicy(inboxId);
|
||||
return camelcaseKeys(response.data);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
updateInboxPolicy: async function updateInboxPolicy({ commit }, { policy }) {
|
||||
try {
|
||||
commit(types.EDIT_ASSIGNMENT_POLICY, policy);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
removeInboxPolicy: async function removeInboxPolicy(
|
||||
{ commit },
|
||||
{ policyId, inboxId }
|
||||
) {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, {
|
||||
isDeleting: true,
|
||||
});
|
||||
try {
|
||||
await AssignmentPoliciesAPI.removeInboxPolicy(inboxId);
|
||||
commit(types.DELETE_ASSIGNMENT_POLICIES_INBOXES, {
|
||||
policyId,
|
||||
inboxId,
|
||||
});
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, {
|
||||
isDeleting: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG](_state, data) {
|
||||
_state.uiFlags = {
|
||||
..._state.uiFlags,
|
||||
...data,
|
||||
};
|
||||
},
|
||||
|
||||
[types.SET_ASSIGNMENT_POLICIES]: MutationHelpers.set,
|
||||
[types.SET_ASSIGNMENT_POLICY]: MutationHelpers.setSingleRecord,
|
||||
[types.ADD_ASSIGNMENT_POLICY]: MutationHelpers.create,
|
||||
[types.EDIT_ASSIGNMENT_POLICY]: MutationHelpers.updateAttributes,
|
||||
[types.DELETE_ASSIGNMENT_POLICY]: MutationHelpers.destroy,
|
||||
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG](_state, data) {
|
||||
_state.inboxUiFlags = {
|
||||
..._state.inboxUiFlags,
|
||||
...data,
|
||||
};
|
||||
},
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES](_state, { policyId, inboxes }) {
|
||||
const policy = _state.records.find(p => p.id === policyId);
|
||||
if (policy) {
|
||||
policy.inboxes = inboxes;
|
||||
}
|
||||
},
|
||||
[types.DELETE_ASSIGNMENT_POLICIES_INBOXES](_state, { policyId, inboxId }) {
|
||||
const policy = _state.records.find(p => p.id === policyId);
|
||||
if (policy) {
|
||||
policy.inboxes = policy?.inboxes?.filter(inbox => inbox.id !== inboxId);
|
||||
}
|
||||
},
|
||||
[types.ADD_ASSIGNMENT_POLICIES_INBOXES]: MutationHelpers.updateAttributes,
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
};
|
||||
@@ -64,11 +64,13 @@ const getValueFromConversation = (conversation, attributeKey) => {
|
||||
switch (attributeKey) {
|
||||
case 'status':
|
||||
case 'priority':
|
||||
case 'display_id':
|
||||
case 'labels':
|
||||
case 'created_at':
|
||||
case 'last_activity_at':
|
||||
return conversation[attributeKey];
|
||||
case 'display_id':
|
||||
// Frontend uses 'id' but backend expects 'display_id'
|
||||
return conversation.display_id || conversation.id;
|
||||
case 'assignee_id':
|
||||
return conversation.meta?.assignee?.id;
|
||||
case 'inbox_id':
|
||||
|
||||
+5
-5
@@ -247,7 +247,7 @@ describe('filterHelpers', () => {
|
||||
|
||||
// Text search tests - display_id
|
||||
it('should match conversation with equal_to operator for display_id', () => {
|
||||
const conversation = { display_id: '12345' };
|
||||
const conversation = { id: '12345' };
|
||||
const filters = [
|
||||
{
|
||||
attribute_key: 'display_id',
|
||||
@@ -260,7 +260,7 @@ describe('filterHelpers', () => {
|
||||
});
|
||||
|
||||
it('should match conversation with contains operator for display_id', () => {
|
||||
const conversation = { display_id: '12345' };
|
||||
const conversation = { id: '12345' };
|
||||
const filters = [
|
||||
{
|
||||
attribute_key: 'display_id',
|
||||
@@ -273,7 +273,7 @@ describe('filterHelpers', () => {
|
||||
});
|
||||
|
||||
it('should not match conversation with does_not_contain operator for display_id', () => {
|
||||
const conversation = { display_id: '12345' };
|
||||
const conversation = { id: '12345' };
|
||||
const filters = [
|
||||
{
|
||||
attribute_key: 'display_id',
|
||||
@@ -286,7 +286,7 @@ describe('filterHelpers', () => {
|
||||
});
|
||||
|
||||
it('should match conversation with does_not_contain operator when value is not present', () => {
|
||||
const conversation = { display_id: '12345' };
|
||||
const conversation = { id: '12345' };
|
||||
const filters = [
|
||||
{
|
||||
attribute_key: 'display_id',
|
||||
@@ -989,7 +989,7 @@ describe('filterHelpers', () => {
|
||||
|
||||
it('should handle empty string values in conversation', () => {
|
||||
const conversation = {
|
||||
display_id: '',
|
||||
id: '',
|
||||
};
|
||||
const filters = [
|
||||
{
|
||||
|
||||
@@ -29,6 +29,9 @@ export const getters = {
|
||||
getInboxes($state) {
|
||||
return $state.records;
|
||||
},
|
||||
getAllInboxes($state) {
|
||||
return camelcaseKeys($state.records, { deep: true });
|
||||
},
|
||||
getWhatsAppTemplates: $state => inboxId => {
|
||||
const [inbox] = $state.records.filter(
|
||||
record => record.id === Number(inboxId)
|
||||
|
||||
@@ -38,4 +38,7 @@ export const getters = {
|
||||
getHasUnreadNotifications: $state => {
|
||||
return $state.meta.unreadCount > 0;
|
||||
},
|
||||
getUnreadCount: $state => {
|
||||
return $state.meta.unreadCount;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -49,35 +49,74 @@ describe('#getters', () => {
|
||||
});
|
||||
|
||||
describe('isRTL', () => {
|
||||
it('returns false when accountId is not present', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('returns false when accountId is not present and userLocale is not set', () => {
|
||||
const state = { records: [accountData] };
|
||||
const rootState = { route: { params: {} } };
|
||||
expect(getters.isRTL({}, null, rootState)).toBe(false);
|
||||
const rootGetters = {};
|
||||
|
||||
expect(getters.isRTL(state, null, rootState, rootGetters)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for RTL language', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, locale: 'ar' }],
|
||||
};
|
||||
const rootState = { route: { params: { accountId: '1' } } };
|
||||
vi.spyOn(languageHelpers, 'getLanguageDirection').mockReturnValue(true);
|
||||
expect(getters.isRTL(state, null, rootState)).toBe(true);
|
||||
it('uses userLocale when present (no accountId)', () => {
|
||||
const state = { records: [accountData] };
|
||||
const rootState = { route: { params: {} } };
|
||||
const rootGetters = { getUISettings: { locale: 'ar' } };
|
||||
const spy = vi
|
||||
.spyOn(languageHelpers, 'getLanguageDirection')
|
||||
.mockReturnValue(true);
|
||||
|
||||
expect(getters.isRTL(state, null, rootState, rootGetters)).toBe(true);
|
||||
expect(spy).toHaveBeenCalledWith('ar');
|
||||
});
|
||||
|
||||
it('returns false for LTR language', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, locale: 'en' }],
|
||||
};
|
||||
it('prefers userLocale over account locale when both are present', () => {
|
||||
const state = { records: [{ id: 1, locale: 'en' }] };
|
||||
const rootState = { route: { params: { accountId: '1' } } };
|
||||
vi.spyOn(languageHelpers, 'getLanguageDirection').mockReturnValue(false);
|
||||
expect(getters.isRTL(state, null, rootState)).toBe(false);
|
||||
const rootGetters = { getUISettings: { locale: 'ar' } };
|
||||
const spy = vi
|
||||
.spyOn(languageHelpers, 'getLanguageDirection')
|
||||
.mockReturnValue(true);
|
||||
|
||||
expect(getters.isRTL(state, null, rootState, rootGetters)).toBe(true);
|
||||
expect(spy).toHaveBeenCalledWith('ar');
|
||||
});
|
||||
|
||||
it('returns false when account is not found', () => {
|
||||
const state = {
|
||||
records: [],
|
||||
};
|
||||
it('falls back to account locale when userLocale is not provided', () => {
|
||||
const state = { records: [{ id: 1, locale: 'ar' }] };
|
||||
const rootState = { route: { params: { accountId: '1' } } };
|
||||
expect(getters.isRTL(state, null, rootState)).toBe(false);
|
||||
const rootGetters = {};
|
||||
const spy = vi
|
||||
.spyOn(languageHelpers, 'getLanguageDirection')
|
||||
.mockReturnValue(true);
|
||||
|
||||
expect(getters.isRTL(state, null, rootState, rootGetters)).toBe(true);
|
||||
expect(spy).toHaveBeenCalledWith('ar');
|
||||
});
|
||||
|
||||
it('returns false for LTR language when userLocale is provided', () => {
|
||||
const state = { records: [{ id: 1, locale: 'en' }] };
|
||||
const rootState = { route: { params: { accountId: '1' } } };
|
||||
const rootGetters = { getUISettings: { locale: 'en' } };
|
||||
const spy = vi
|
||||
.spyOn(languageHelpers, 'getLanguageDirection')
|
||||
.mockReturnValue(false);
|
||||
|
||||
expect(getters.isRTL(state, null, rootState, rootGetters)).toBe(false);
|
||||
expect(spy).toHaveBeenCalledWith('en');
|
||||
});
|
||||
|
||||
it('returns false when accountId present but user locale is null', () => {
|
||||
const state = { records: [{ id: 1, locale: 'en' }] };
|
||||
const rootState = { route: { params: { accountId: '1' } } };
|
||||
const rootGetters = { getUISettings: { locale: null } };
|
||||
const spy = vi.spyOn(languageHelpers, 'getLanguageDirection');
|
||||
|
||||
expect(getters.isRTL(state, null, rootState, rootGetters)).toBe(false);
|
||||
expect(spy).toHaveBeenCalledWith('en');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,408 @@
|
||||
import axios from 'axios';
|
||||
import { actions } from '../../agentCapacityPolicies';
|
||||
import types from '../../../mutation-types';
|
||||
import agentCapacityPoliciesList, {
|
||||
camelCaseFixtures,
|
||||
mockUsers,
|
||||
mockInboxLimits,
|
||||
camelCaseMockInboxLimits,
|
||||
} from './fixtures';
|
||||
import camelcaseKeys from 'camelcase-keys';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
|
||||
const commit = vi.fn();
|
||||
|
||||
global.axios = axios;
|
||||
vi.mock('axios');
|
||||
vi.mock('camelcase-keys');
|
||||
vi.mock('snakecase-keys');
|
||||
vi.mock('../../../utils/api');
|
||||
|
||||
describe('#actions', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('#get', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({ data: agentCapacityPoliciesList });
|
||||
camelcaseKeys.mockReturnValue(camelCaseFixtures);
|
||||
|
||||
await actions.get({ commit });
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(agentCapacityPoliciesList, {
|
||||
deep: true,
|
||||
});
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES, camelCaseFixtures],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
|
||||
await actions.get({ commit });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#show', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyData = agentCapacityPoliciesList[0];
|
||||
const camelCasedPolicy = camelCaseFixtures[0];
|
||||
|
||||
axios.get.mockResolvedValue({ data: policyData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedPolicy);
|
||||
|
||||
await actions.show({ commit }, 1);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(policyData, {
|
||||
deep: true,
|
||||
});
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetchingItem: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICY, camelCasedPolicy],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetchingItem: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Not found' });
|
||||
|
||||
await actions.show({ commit }, 1);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetchingItem: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isFetchingItem: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#create', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const newPolicy = agentCapacityPoliciesList[0];
|
||||
const camelCasedData = camelCaseFixtures[0];
|
||||
const snakeCasedPolicy = { default_capacity: 10 };
|
||||
|
||||
axios.post.mockResolvedValue({ data: newPolicy });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
snakecaseKeys.mockReturnValue(snakeCasedPolicy);
|
||||
|
||||
const result = await actions.create({ commit }, newPolicy);
|
||||
|
||||
expect(snakecaseKeys).toHaveBeenCalledWith(newPolicy);
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(newPolicy, {
|
||||
deep: true,
|
||||
});
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isCreating: true }],
|
||||
[types.ADD_AGENT_CAPACITY_POLICY, camelCasedData],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
expect(result).toEqual(newPolicy);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(actions.create({ commit }, {})).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isCreating: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const updateParams = { id: 1, name: 'Updated Policy' };
|
||||
const responseData = {
|
||||
...agentCapacityPoliciesList[0],
|
||||
name: 'Updated Policy',
|
||||
};
|
||||
const camelCasedData = {
|
||||
...camelCaseFixtures[0],
|
||||
name: 'Updated Policy',
|
||||
};
|
||||
const snakeCasedParams = { name: 'Updated Policy' };
|
||||
|
||||
axios.patch.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
snakecaseKeys.mockReturnValue(snakeCasedParams);
|
||||
|
||||
const result = await actions.update({ commit }, updateParams);
|
||||
|
||||
expect(snakecaseKeys).toHaveBeenCalledWith({ name: 'Updated Policy' });
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData, {
|
||||
deep: true,
|
||||
});
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isUpdating: true }],
|
||||
[types.EDIT_AGENT_CAPACITY_POLICY, camelCasedData],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
expect(result).toEqual(responseData);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(
|
||||
actions.update({ commit }, { id: 1, name: 'Test' })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isUpdating: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
axios.delete.mockResolvedValue({});
|
||||
|
||||
await actions.delete({ commit }, policyId);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isDeleting: true }],
|
||||
[types.DELETE_AGENT_CAPACITY_POLICY, policyId],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue(new Error('Not found'));
|
||||
|
||||
await expect(actions.delete({ commit }, 1)).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isDeleting: true }],
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUsers', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const userData = [
|
||||
{ id: 1, name: 'Agent 1', email: 'agent1@example.com', capacity: 15 },
|
||||
{ id: 2, name: 'Agent 2', email: 'agent2@example.com', capacity: 20 },
|
||||
];
|
||||
const camelCasedUsers = [
|
||||
{ id: 1, name: 'Agent 1', email: 'agent1@example.com', capacity: 15 },
|
||||
{ id: 2, name: 'Agent 2', email: 'agent2@example.com', capacity: 20 },
|
||||
];
|
||||
|
||||
axios.get.mockResolvedValue({ data: userData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedUsers);
|
||||
|
||||
const result = await actions.getUsers({ commit }, policyId);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(userData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, { isFetching: true }],
|
||||
[
|
||||
types.SET_AGENT_CAPACITY_POLICIES_USERS,
|
||||
{ policyId, users: camelCasedUsers },
|
||||
],
|
||||
[
|
||||
types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG,
|
||||
{ isFetching: false },
|
||||
],
|
||||
]);
|
||||
expect(result).toEqual(userData);
|
||||
});
|
||||
|
||||
it('sends correct actions if API fails', async () => {
|
||||
axios.get.mockRejectedValue(new Error('API Error'));
|
||||
|
||||
await expect(actions.getUsers({ commit }, 1)).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, { isFetching: true }],
|
||||
[
|
||||
types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG,
|
||||
{ isFetching: false },
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addUser', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const userData = { user_id: 3, capacity: 12 };
|
||||
const responseData = mockUsers[2];
|
||||
const camelCasedUser = mockUsers[2];
|
||||
|
||||
axios.post.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedUser);
|
||||
|
||||
const result = await actions.addUser({ commit }, { policyId, userData });
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[
|
||||
types.ADD_AGENT_CAPACITY_POLICIES_USERS,
|
||||
{ policyId, user: camelCasedUser },
|
||||
],
|
||||
]);
|
||||
expect(result).toEqual(responseData);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(
|
||||
actions.addUser({ commit }, { policyId: 1, userData: {} })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeUser', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const userId = 2;
|
||||
axios.delete.mockResolvedValue({});
|
||||
|
||||
await actions.removeUser({ commit }, { policyId, userId });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, { isDeleting: true }],
|
||||
[types.DELETE_AGENT_CAPACITY_POLICIES_USERS, { policyId, userId }],
|
||||
[
|
||||
types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG,
|
||||
{ isDeleting: false },
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue(new Error('Not found'));
|
||||
|
||||
await expect(
|
||||
actions.removeUser({ commit }, { policyId: 1, userId: 2 })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG, { isDeleting: true }],
|
||||
[
|
||||
types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG,
|
||||
{ isDeleting: false },
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#createInboxLimit', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const limitData = { inbox_id: 3, conversation_limit: 20 };
|
||||
const responseData = mockInboxLimits[2];
|
||||
const camelCasedData = camelCaseMockInboxLimits[2];
|
||||
|
||||
axios.post.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
|
||||
const result = await actions.createInboxLimit(
|
||||
{ commit },
|
||||
{ policyId, limitData }
|
||||
);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_AGENT_CAPACITY_POLICIES_INBOXES, camelCasedData],
|
||||
]);
|
||||
expect(result).toEqual(responseData);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(
|
||||
actions.createInboxLimit({ commit }, { policyId: 1, limitData: {} })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateInboxLimit', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const limitId = 1;
|
||||
const limitData = { conversation_limit: 25 };
|
||||
const responseData = {
|
||||
...mockInboxLimits[0],
|
||||
conversation_limit: 25,
|
||||
};
|
||||
const camelCasedData = {
|
||||
...camelCaseMockInboxLimits[0],
|
||||
conversationLimit: 25,
|
||||
};
|
||||
|
||||
axios.put.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
|
||||
const result = await actions.updateInboxLimit(
|
||||
{ commit },
|
||||
{ policyId, limitId, limitData }
|
||||
);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.EDIT_AGENT_CAPACITY_POLICIES_INBOXES, camelCasedData],
|
||||
]);
|
||||
expect(result).toEqual(responseData);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.put.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(
|
||||
actions.updateInboxLimit(
|
||||
{ commit },
|
||||
{ policyId: 1, limitId: 1, limitData: {} }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deleteInboxLimit', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const limitId = 1;
|
||||
axios.delete.mockResolvedValue({});
|
||||
|
||||
await actions.deleteInboxLimit({ commit }, { policyId, limitId });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.DELETE_AGENT_CAPACITY_POLICIES_INBOXES, { policyId, limitId }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue(new Error('Not found'));
|
||||
|
||||
await expect(
|
||||
actions.deleteInboxLimit({ commit }, { policyId: 1, limitId: 1 })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,199 @@
|
||||
export default [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Standard Capacity Policy',
|
||||
description: 'Default capacity policy for agents',
|
||||
default_capacity: 10,
|
||||
enabled: true,
|
||||
account_id: 1,
|
||||
assigned_agent_count: 3,
|
||||
created_at: '2024-01-01T10:00:00.000Z',
|
||||
updated_at: '2024-01-01T10:00:00.000Z',
|
||||
users: [],
|
||||
inbox_capacity_limits: [
|
||||
{
|
||||
id: 1,
|
||||
inbox_id: 1,
|
||||
conversation_limit: 15,
|
||||
agent_capacity_policy_id: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
inbox_id: 2,
|
||||
conversation_limit: 8,
|
||||
agent_capacity_policy_id: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'High Capacity Policy',
|
||||
description: 'High capacity policy for senior agents',
|
||||
default_capacity: 20,
|
||||
enabled: true,
|
||||
account_id: 1,
|
||||
assigned_agent_count: 5,
|
||||
created_at: '2024-01-01T11:00:00.000Z',
|
||||
updated_at: '2024-01-01T11:00:00.000Z',
|
||||
users: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent Smith',
|
||||
email: 'agent.smith@example.com',
|
||||
capacity: 25,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Agent Johnson',
|
||||
email: 'agent.johnson@example.com',
|
||||
capacity: 18,
|
||||
},
|
||||
],
|
||||
inbox_capacity_limits: [],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Disabled Policy',
|
||||
description: 'Disabled capacity policy',
|
||||
default_capacity: 5,
|
||||
enabled: false,
|
||||
account_id: 1,
|
||||
assigned_agent_count: 0,
|
||||
created_at: '2024-01-01T12:00:00.000Z',
|
||||
updated_at: '2024-01-01T12:00:00.000Z',
|
||||
users: [],
|
||||
inbox_capacity_limits: [],
|
||||
},
|
||||
];
|
||||
|
||||
export const camelCaseFixtures = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Standard Capacity Policy',
|
||||
description: 'Default capacity policy for agents',
|
||||
defaultCapacity: 10,
|
||||
enabled: true,
|
||||
accountId: 1,
|
||||
assignedAgentCount: 3,
|
||||
createdAt: '2024-01-01T10:00:00.000Z',
|
||||
updatedAt: '2024-01-01T10:00:00.000Z',
|
||||
users: [],
|
||||
inboxCapacityLimits: [
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
agentCapacityPolicyId: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
inboxId: 2,
|
||||
conversationLimit: 8,
|
||||
agentCapacityPolicyId: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'High Capacity Policy',
|
||||
description: 'High capacity policy for senior agents',
|
||||
defaultCapacity: 20,
|
||||
enabled: true,
|
||||
accountId: 1,
|
||||
assignedAgentCount: 5,
|
||||
createdAt: '2024-01-01T11:00:00.000Z',
|
||||
updatedAt: '2024-01-01T11:00:00.000Z',
|
||||
users: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent Smith',
|
||||
email: 'agent.smith@example.com',
|
||||
capacity: 25,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Agent Johnson',
|
||||
email: 'agent.johnson@example.com',
|
||||
capacity: 18,
|
||||
},
|
||||
],
|
||||
inboxCapacityLimits: [],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Disabled Policy',
|
||||
description: 'Disabled capacity policy',
|
||||
defaultCapacity: 5,
|
||||
enabled: false,
|
||||
accountId: 1,
|
||||
assignedAgentCount: 0,
|
||||
createdAt: '2024-01-01T12:00:00.000Z',
|
||||
updatedAt: '2024-01-01T12:00:00.000Z',
|
||||
users: [],
|
||||
inboxCapacityLimits: [],
|
||||
},
|
||||
];
|
||||
|
||||
// Additional test data for user and inbox limit operations
|
||||
export const mockUsers = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Agent Smith',
|
||||
email: 'agent.smith@example.com',
|
||||
capacity: 25,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Agent Johnson',
|
||||
email: 'agent.johnson@example.com',
|
||||
capacity: 18,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Agent Brown',
|
||||
email: 'agent.brown@example.com',
|
||||
capacity: 12,
|
||||
},
|
||||
];
|
||||
|
||||
export const mockInboxLimits = [
|
||||
{
|
||||
id: 1,
|
||||
inbox_id: 1,
|
||||
conversation_limit: 15,
|
||||
agent_capacity_policy_id: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
inbox_id: 2,
|
||||
conversation_limit: 8,
|
||||
agent_capacity_policy_id: 1,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
inbox_id: 3,
|
||||
conversation_limit: 20,
|
||||
agent_capacity_policy_id: 2,
|
||||
},
|
||||
];
|
||||
|
||||
export const camelCaseMockInboxLimits = [
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
agentCapacityPolicyId: 1,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
inboxId: 2,
|
||||
conversationLimit: 8,
|
||||
agentCapacityPolicyId: 1,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
inboxId: 3,
|
||||
conversationLimit: 20,
|
||||
agentCapacityPolicyId: 2,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,51 @@
|
||||
import { getters } from '../../agentCapacityPolicies';
|
||||
import agentCapacityPoliciesList from './fixtures';
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getAgentCapacityPolicies', () => {
|
||||
const state = { records: agentCapacityPoliciesList };
|
||||
expect(getters.getAgentCapacityPolicies(state)).toEqual(
|
||||
agentCapacityPoliciesList
|
||||
);
|
||||
});
|
||||
|
||||
it('getUIFlags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getUIFlags(state)).toEqual({
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('getUsersUIFlags', () => {
|
||||
const state = {
|
||||
usersUiFlags: {
|
||||
isFetching: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getUsersUIFlags(state)).toEqual({
|
||||
isFetching: false,
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('getAgentCapacityPolicyById', () => {
|
||||
const state = { records: agentCapacityPoliciesList };
|
||||
expect(getters.getAgentCapacityPolicyById(state)(1)).toEqual(
|
||||
agentCapacityPoliciesList[0]
|
||||
);
|
||||
expect(getters.getAgentCapacityPolicyById(state)(4)).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,619 @@
|
||||
import { mutations } from '../../agentCapacityPolicies';
|
||||
import types from '../../../mutation-types';
|
||||
import agentCapacityPoliciesList, { mockUsers } from './fixtures';
|
||||
|
||||
describe('#mutations', () => {
|
||||
describe('#SET_AGENT_CAPACITY_POLICIES_UI_FLAG', () => {
|
||||
it('sets single ui flag', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isCreating: false,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
});
|
||||
|
||||
expect(state.uiFlags).toEqual({
|
||||
isFetching: true,
|
||||
isCreating: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('sets multiple ui flags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
isCreating: true,
|
||||
});
|
||||
|
||||
expect(state.uiFlags).toEqual({
|
||||
isFetching: true,
|
||||
isCreating: true,
|
||||
isUpdating: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_AGENT_CAPACITY_POLICIES', () => {
|
||||
it('sets agent capacity policies records', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES](
|
||||
state,
|
||||
agentCapacityPoliciesList
|
||||
);
|
||||
|
||||
expect(state.records).toEqual(agentCapacityPoliciesList);
|
||||
});
|
||||
|
||||
it('replaces existing records', () => {
|
||||
const state = { records: [{ id: 999, name: 'Old Policy' }] };
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES](
|
||||
state,
|
||||
agentCapacityPoliciesList
|
||||
);
|
||||
|
||||
expect(state.records).toEqual(agentCapacityPoliciesList);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_AGENT_CAPACITY_POLICY', () => {
|
||||
it('sets single agent capacity policy record', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICY](
|
||||
state,
|
||||
agentCapacityPoliciesList[0]
|
||||
);
|
||||
|
||||
expect(state.records).toEqual([agentCapacityPoliciesList[0]]);
|
||||
});
|
||||
|
||||
it('replaces existing record', () => {
|
||||
const state = { records: [{ id: 1, name: 'Old Policy' }] };
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICY](
|
||||
state,
|
||||
agentCapacityPoliciesList[0]
|
||||
);
|
||||
|
||||
expect(state.records).toEqual([agentCapacityPoliciesList[0]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_AGENT_CAPACITY_POLICY', () => {
|
||||
it('adds new policy to empty records', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.ADD_AGENT_CAPACITY_POLICY](
|
||||
state,
|
||||
agentCapacityPoliciesList[0]
|
||||
);
|
||||
|
||||
expect(state.records).toEqual([agentCapacityPoliciesList[0]]);
|
||||
});
|
||||
|
||||
it('adds new policy to existing records', () => {
|
||||
const state = { records: [agentCapacityPoliciesList[0]] };
|
||||
|
||||
mutations[types.ADD_AGENT_CAPACITY_POLICY](
|
||||
state,
|
||||
agentCapacityPoliciesList[1]
|
||||
);
|
||||
|
||||
expect(state.records).toEqual([
|
||||
agentCapacityPoliciesList[0],
|
||||
agentCapacityPoliciesList[1],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#EDIT_AGENT_CAPACITY_POLICY', () => {
|
||||
it('updates existing policy by id', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{ ...agentCapacityPoliciesList[0] },
|
||||
{ ...agentCapacityPoliciesList[1] },
|
||||
],
|
||||
};
|
||||
|
||||
const updatedPolicy = {
|
||||
...agentCapacityPoliciesList[0],
|
||||
name: 'Updated Policy Name',
|
||||
description: 'Updated Description',
|
||||
};
|
||||
|
||||
mutations[types.EDIT_AGENT_CAPACITY_POLICY](state, updatedPolicy);
|
||||
|
||||
expect(state.records[0]).toEqual(updatedPolicy);
|
||||
expect(state.records[1]).toEqual(agentCapacityPoliciesList[1]);
|
||||
});
|
||||
|
||||
it('updates policy with camelCase properties', () => {
|
||||
const camelCasePolicy = {
|
||||
id: 1,
|
||||
name: 'Camel Case Policy',
|
||||
defaultCapacity: 15,
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
const state = {
|
||||
records: [camelCasePolicy],
|
||||
};
|
||||
|
||||
const updatedPolicy = {
|
||||
...camelCasePolicy,
|
||||
name: 'Updated Camel Case',
|
||||
defaultCapacity: 25,
|
||||
};
|
||||
|
||||
mutations[types.EDIT_AGENT_CAPACITY_POLICY](state, updatedPolicy);
|
||||
|
||||
expect(state.records[0]).toEqual(updatedPolicy);
|
||||
});
|
||||
|
||||
it('does nothing if policy id not found', () => {
|
||||
const state = {
|
||||
records: [agentCapacityPoliciesList[0]],
|
||||
};
|
||||
|
||||
const nonExistentPolicy = {
|
||||
id: 999,
|
||||
name: 'Non-existent',
|
||||
};
|
||||
|
||||
const originalRecords = [...state.records];
|
||||
mutations[types.EDIT_AGENT_CAPACITY_POLICY](state, nonExistentPolicy);
|
||||
|
||||
expect(state.records).toEqual(originalRecords);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_AGENT_CAPACITY_POLICY', () => {
|
||||
it('deletes policy by id', () => {
|
||||
const state = {
|
||||
records: [agentCapacityPoliciesList[0], agentCapacityPoliciesList[1]],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICY](state, 1);
|
||||
|
||||
expect(state.records).toEqual([agentCapacityPoliciesList[1]]);
|
||||
});
|
||||
|
||||
it('does nothing if id not found', () => {
|
||||
const state = {
|
||||
records: [agentCapacityPoliciesList[0]],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICY](state, 999);
|
||||
|
||||
expect(state.records).toEqual([agentCapacityPoliciesList[0]]);
|
||||
});
|
||||
|
||||
it('handles empty records', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICY](state, 1);
|
||||
|
||||
expect(state.records).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG', () => {
|
||||
it('sets users ui flags', () => {
|
||||
const state = {
|
||||
usersUiFlags: {
|
||||
isFetching: false,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
});
|
||||
|
||||
expect(state.usersUiFlags).toEqual({
|
||||
isFetching: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('merges with existing flags', () => {
|
||||
const state = {
|
||||
usersUiFlags: {
|
||||
isFetching: false,
|
||||
isDeleting: true,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_USERS_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
});
|
||||
|
||||
expect(state.usersUiFlags).toEqual({
|
||||
isFetching: true,
|
||||
isDeleting: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_AGENT_CAPACITY_POLICIES_USERS', () => {
|
||||
it('sets users for existing policy', () => {
|
||||
const testUsers = [
|
||||
{ id: 1, name: 'Agent 1', email: 'agent1@example.com', capacity: 15 },
|
||||
{ id: 2, name: 'Agent 2', email: 'agent2@example.com', capacity: 20 },
|
||||
];
|
||||
|
||||
const state = {
|
||||
records: [
|
||||
{ id: 1, name: 'Policy 1', users: [] },
|
||||
{ id: 2, name: 'Policy 2', users: [] },
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
users: testUsers,
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual(testUsers);
|
||||
expect(state.records[1].users).toEqual([]);
|
||||
});
|
||||
|
||||
it('replaces existing users', () => {
|
||||
const oldUsers = [{ id: 99, name: 'Old Agent', capacity: 5 }];
|
||||
const newUsers = [{ id: 1, name: 'New Agent', capacity: 15 }];
|
||||
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', users: oldUsers }],
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
users: newUsers,
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual(newUsers);
|
||||
});
|
||||
|
||||
it('does nothing if policy not found', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', users: [] }],
|
||||
};
|
||||
|
||||
const originalState = JSON.parse(JSON.stringify(state));
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 999,
|
||||
users: [{ id: 1, name: 'Test' }],
|
||||
});
|
||||
|
||||
expect(state).toEqual(originalState);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_AGENT_CAPACITY_POLICIES_USERS', () => {
|
||||
it('adds user to existing policy', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{ id: 1, name: 'Policy 1', users: [] },
|
||||
{ id: 2, name: 'Policy 2', users: [] },
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.ADD_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
user: mockUsers[0],
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual([mockUsers[0]]);
|
||||
expect(state.records[1].users).toEqual([]);
|
||||
});
|
||||
|
||||
it('adds user to policy with existing users', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', users: [mockUsers[0]] }],
|
||||
};
|
||||
|
||||
mutations[types.ADD_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
user: mockUsers[1],
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual([mockUsers[0], mockUsers[1]]);
|
||||
});
|
||||
|
||||
it('initializes users array if undefined', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1' }],
|
||||
};
|
||||
|
||||
mutations[types.ADD_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
user: mockUsers[0],
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual([mockUsers[0]]);
|
||||
});
|
||||
|
||||
it('updates assigned agent count', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', users: [] }],
|
||||
};
|
||||
|
||||
mutations[types.ADD_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
user: mockUsers[0],
|
||||
});
|
||||
|
||||
expect(state.records[0].assignedAgentCount).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_AGENT_CAPACITY_POLICIES_USERS', () => {
|
||||
it('removes user from policy', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
users: [mockUsers[0], mockUsers[1], mockUsers[2]],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
userId: 2,
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual([mockUsers[0], mockUsers[2]]);
|
||||
});
|
||||
|
||||
it('handles removing non-existent user', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
users: [mockUsers[0]],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
userId: 999,
|
||||
});
|
||||
|
||||
expect(state.records[0].users).toEqual([mockUsers[0]]);
|
||||
});
|
||||
|
||||
it('updates assigned agent count', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', users: [mockUsers[0]] }],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICIES_USERS](state, {
|
||||
policyId: 1,
|
||||
userId: 1,
|
||||
});
|
||||
|
||||
expect(state.records[0].assignedAgentCount).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_AGENT_CAPACITY_POLICIES_INBOXES', () => {
|
||||
it('adds inbox limit to policy', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
inboxCapacityLimits: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const inboxLimitData = {
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
agentCapacityPolicyId: 1,
|
||||
};
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_INBOXES](
|
||||
state,
|
||||
inboxLimitData
|
||||
);
|
||||
|
||||
expect(state.records[0].inboxCapacityLimits).toEqual([
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('does nothing if policy not found', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', inboxCapacityLimits: [] }],
|
||||
};
|
||||
|
||||
const originalState = JSON.parse(JSON.stringify(state));
|
||||
|
||||
mutations[types.SET_AGENT_CAPACITY_POLICIES_INBOXES](state, {
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
agentCapacityPolicyId: 999,
|
||||
});
|
||||
|
||||
expect(state).toEqual(originalState);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#EDIT_AGENT_CAPACITY_POLICIES_INBOXES', () => {
|
||||
it('updates existing inbox limit', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
inboxCapacityLimits: [
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
inboxId: 2,
|
||||
conversationLimit: 8,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.EDIT_AGENT_CAPACITY_POLICIES_INBOXES](state, {
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 25,
|
||||
agentCapacityPolicyId: 1,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxCapacityLimits[0]).toEqual({
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 25,
|
||||
});
|
||||
expect(state.records[0].inboxCapacityLimits[1]).toEqual({
|
||||
id: 2,
|
||||
inboxId: 2,
|
||||
conversationLimit: 8,
|
||||
});
|
||||
});
|
||||
|
||||
it('does nothing if limit not found', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
inboxCapacityLimits: [
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const originalLimits = [...state.records[0].inboxCapacityLimits];
|
||||
|
||||
mutations[types.EDIT_AGENT_CAPACITY_POLICIES_INBOXES](state, {
|
||||
id: 999,
|
||||
inboxId: 1,
|
||||
conversationLimit: 25,
|
||||
agentCapacityPolicyId: 1,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxCapacityLimits).toEqual(originalLimits);
|
||||
});
|
||||
|
||||
it('does nothing if policy not found', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', inboxCapacityLimits: [] }],
|
||||
};
|
||||
|
||||
const originalState = JSON.parse(JSON.stringify(state));
|
||||
|
||||
mutations[types.EDIT_AGENT_CAPACITY_POLICIES_INBOXES](state, {
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 25,
|
||||
agentCapacityPolicyId: 999,
|
||||
});
|
||||
|
||||
expect(state).toEqual(originalState);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_AGENT_CAPACITY_POLICIES_INBOXES', () => {
|
||||
it('removes inbox limit from policy', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
inboxCapacityLimits: [
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
inboxId: 2,
|
||||
conversationLimit: 8,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
limitId: 1,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxCapacityLimits).toEqual([
|
||||
{
|
||||
id: 2,
|
||||
inboxId: 2,
|
||||
conversationLimit: 8,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles removing non-existent limit', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
inboxCapacityLimits: [
|
||||
{
|
||||
id: 1,
|
||||
inboxId: 1,
|
||||
conversationLimit: 15,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const originalLimits = [...state.records[0].inboxCapacityLimits];
|
||||
|
||||
mutations[types.DELETE_AGENT_CAPACITY_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
limitId: 999,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxCapacityLimits).toEqual(originalLimits);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,326 @@
|
||||
import axios from 'axios';
|
||||
import { actions } from '../../assignmentPolicies';
|
||||
import types from '../../../mutation-types';
|
||||
import assignmentPoliciesList, { camelCaseFixtures } from './fixtures';
|
||||
import camelcaseKeys from 'camelcase-keys';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
|
||||
const commit = vi.fn();
|
||||
|
||||
global.axios = axios;
|
||||
vi.mock('axios');
|
||||
vi.mock('camelcase-keys');
|
||||
vi.mock('snakecase-keys');
|
||||
vi.mock('../../../utils/api');
|
||||
|
||||
describe('#actions', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('#get', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.get.mockResolvedValue({ data: assignmentPoliciesList });
|
||||
camelcaseKeys.mockReturnValue(camelCaseFixtures);
|
||||
|
||||
await actions.get({ commit });
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(assignmentPoliciesList);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES, camelCaseFixtures],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Incorrect header' });
|
||||
|
||||
await actions.get({ commit });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#show', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyData = assignmentPoliciesList[0];
|
||||
const camelCasedPolicy = camelCaseFixtures[0];
|
||||
|
||||
axios.get.mockResolvedValue({ data: policyData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedPolicy);
|
||||
|
||||
await actions.show({ commit }, 1);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(policyData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: true }],
|
||||
[types.SET_ASSIGNMENT_POLICY, camelCasedPolicy],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.get.mockRejectedValue({ message: 'Not found' });
|
||||
|
||||
await actions.show({ commit }, 1);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#create', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const newPolicy = assignmentPoliciesList[0];
|
||||
const camelCasedData = camelCaseFixtures[0];
|
||||
const snakeCasedPolicy = { assignment_order: 'round_robin' };
|
||||
|
||||
axios.post.mockResolvedValue({ data: newPolicy });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
snakecaseKeys.mockReturnValue(snakeCasedPolicy);
|
||||
|
||||
const result = await actions.create({ commit }, newPolicy);
|
||||
|
||||
expect(snakecaseKeys).toHaveBeenCalledWith(newPolicy);
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(newPolicy);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: true }],
|
||||
[types.ADD_ASSIGNMENT_POLICY, camelCasedData],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
expect(result).toEqual(newPolicy);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(actions.create({ commit }, {})).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const updateParams = { id: 1, name: 'Updated Policy' };
|
||||
const responseData = {
|
||||
...assignmentPoliciesList[0],
|
||||
name: 'Updated Policy',
|
||||
};
|
||||
const camelCasedData = {
|
||||
...camelCaseFixtures[0],
|
||||
name: 'Updated Policy',
|
||||
};
|
||||
const snakeCasedParams = { name: 'Updated Policy' };
|
||||
|
||||
axios.patch.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
snakecaseKeys.mockReturnValue(snakeCasedParams);
|
||||
|
||||
const result = await actions.update({ commit }, updateParams);
|
||||
|
||||
expect(snakecaseKeys).toHaveBeenCalledWith({ name: 'Updated Policy' });
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: true }],
|
||||
[types.EDIT_ASSIGNMENT_POLICY, camelCasedData],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
expect(result).toEqual(responseData);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue(new Error('Validation error'));
|
||||
|
||||
await expect(
|
||||
actions.update({ commit }, { id: 1, name: 'Test' })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
axios.delete.mockResolvedValue({});
|
||||
|
||||
await actions.delete({ commit }, policyId);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: true }],
|
||||
[types.DELETE_ASSIGNMENT_POLICY, policyId],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.delete.mockRejectedValue(new Error('Not found'));
|
||||
|
||||
await expect(actions.delete({ commit }, 1)).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getInboxes', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const inboxData = {
|
||||
inboxes: [
|
||||
{ id: 1, name: 'Support' },
|
||||
{ id: 2, name: 'Sales' },
|
||||
],
|
||||
};
|
||||
const camelCasedInboxes = [
|
||||
{ id: 1, name: 'Support' },
|
||||
{ id: 2, name: 'Sales' },
|
||||
];
|
||||
|
||||
axios.get.mockResolvedValue({ data: inboxData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedInboxes);
|
||||
|
||||
await actions.getInboxes({ commit }, policyId);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(inboxData.inboxes);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isFetching: true }],
|
||||
[
|
||||
types.SET_ASSIGNMENT_POLICIES_INBOXES,
|
||||
{ policyId, inboxes: camelCasedInboxes },
|
||||
],
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API fails', async () => {
|
||||
axios.get.mockRejectedValue(new Error('API Error'));
|
||||
|
||||
await expect(actions.getInboxes({ commit }, 1)).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isFetching: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isFetching: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setInboxPolicy', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const responseData = { success: true, policy_id: 2 };
|
||||
const camelCasedData = { success: true, policyId: 2 };
|
||||
|
||||
axios.post.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
|
||||
const result = await actions.setInboxPolicy(
|
||||
{ commit },
|
||||
{ inboxId: 1, policyId: 2 }
|
||||
);
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.ADD_ASSIGNMENT_POLICIES_INBOXES, camelCasedData],
|
||||
]);
|
||||
expect(result).toEqual(responseData);
|
||||
});
|
||||
|
||||
it('throws error if API fails', async () => {
|
||||
axios.post.mockRejectedValue(new Error('API Error'));
|
||||
|
||||
await expect(
|
||||
actions.setInboxPolicy({ commit }, { inboxId: 1, policyId: 2 })
|
||||
).rejects.toThrow(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getInboxPolicy', () => {
|
||||
it('returns camelCased response data if API is success', async () => {
|
||||
const responseData = { policy_id: 1, name: 'Round Robin' };
|
||||
const camelCasedData = { policyId: 1, name: 'Round Robin' };
|
||||
|
||||
axios.get.mockResolvedValue({ data: responseData });
|
||||
camelcaseKeys.mockReturnValue(camelCasedData);
|
||||
|
||||
const result = await actions.getInboxPolicy({}, { inboxId: 1 });
|
||||
|
||||
expect(camelcaseKeys).toHaveBeenCalledWith(responseData);
|
||||
expect(result).toEqual(camelCasedData);
|
||||
});
|
||||
|
||||
it('throws error if API fails', async () => {
|
||||
axios.get.mockRejectedValue(new Error('Not found'));
|
||||
|
||||
await expect(
|
||||
actions.getInboxPolicy({}, { inboxId: 999 })
|
||||
).rejects.toThrow(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateInboxPolicy', () => {
|
||||
it('commits EDIT_ASSIGNMENT_POLICY mutation', async () => {
|
||||
const policy = { id: 1, name: 'Updated Policy' };
|
||||
|
||||
await actions.updateInboxPolicy({ commit }, { policy });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.EDIT_ASSIGNMENT_POLICY, policy],
|
||||
]);
|
||||
});
|
||||
|
||||
it('throws error if commit fails', async () => {
|
||||
commit.mockImplementation(() => {
|
||||
throw new Error('Commit failed');
|
||||
});
|
||||
|
||||
await expect(
|
||||
actions.updateInboxPolicy({ commit }, { policy: {} })
|
||||
).rejects.toThrow(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeInboxPolicy', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const policyId = 1;
|
||||
const inboxId = 2;
|
||||
|
||||
axios.delete.mockResolvedValue({});
|
||||
|
||||
await actions.removeInboxPolicy({ commit }, { policyId, inboxId });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isDeleting: true }],
|
||||
[types.DELETE_ASSIGNMENT_POLICIES_INBOXES, { policyId, inboxId }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API fails', async () => {
|
||||
axios.delete.mockRejectedValue(new Error('Not found'));
|
||||
|
||||
await expect(
|
||||
actions.removeInboxPolicy({ commit }, { policyId: 1, inboxId: 999 })
|
||||
).rejects.toThrow(Error);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isDeleting: true }],
|
||||
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isDeleting: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
export default [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Round Robin Policy',
|
||||
description: 'Distributes conversations evenly among agents',
|
||||
assignment_order: 'round_robin',
|
||||
conversation_priority: 'earliest_created',
|
||||
fair_distribution_limit: 100,
|
||||
fair_distribution_window: 3600,
|
||||
enabled: true,
|
||||
assigned_inbox_count: 3,
|
||||
created_at: 1704110400,
|
||||
updated_at: 1704110400,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Balanced Policy',
|
||||
description: 'Assigns conversations based on agent capacity',
|
||||
assignment_order: 'balanced',
|
||||
conversation_priority: 'longest_waiting',
|
||||
fair_distribution_limit: 50,
|
||||
fair_distribution_window: 1800,
|
||||
enabled: false,
|
||||
assigned_inbox_count: 1,
|
||||
created_at: 1704114000,
|
||||
updated_at: 1704114000,
|
||||
},
|
||||
];
|
||||
|
||||
export const camelCaseFixtures = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Round Robin Policy',
|
||||
description: 'Distributes conversations evenly among agents',
|
||||
assignmentOrder: 'round_robin',
|
||||
conversationPriority: 'earliest_created',
|
||||
fairDistributionLimit: 100,
|
||||
fairDistributionWindow: 3600,
|
||||
enabled: true,
|
||||
assignedInboxCount: 3,
|
||||
createdAt: 1704110400,
|
||||
updatedAt: 1704110400,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Balanced Policy',
|
||||
description: 'Assigns conversations based on agent capacity',
|
||||
assignmentOrder: 'balanced',
|
||||
conversationPriority: 'longest_waiting',
|
||||
fairDistributionLimit: 50,
|
||||
fairDistributionWindow: 1800,
|
||||
enabled: false,
|
||||
assignedInboxCount: 1,
|
||||
createdAt: 1704114000,
|
||||
updatedAt: 1704114000,
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,51 @@
|
||||
import { getters } from '../../assignmentPolicies';
|
||||
import assignmentPoliciesList from './fixtures';
|
||||
|
||||
describe('#getters', () => {
|
||||
it('getAssignmentPolicies', () => {
|
||||
const state = { records: assignmentPoliciesList };
|
||||
expect(getters.getAssignmentPolicies(state)).toEqual(
|
||||
assignmentPoliciesList
|
||||
);
|
||||
});
|
||||
|
||||
it('getUIFlags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getUIFlags(state)).toEqual({
|
||||
isFetching: true,
|
||||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('getInboxUiFlags', () => {
|
||||
const state = {
|
||||
inboxUiFlags: {
|
||||
isFetching: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
expect(getters.getInboxUiFlags(state)).toEqual({
|
||||
isFetching: false,
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('getAssignmentPolicyById', () => {
|
||||
const state = { records: assignmentPoliciesList };
|
||||
expect(getters.getAssignmentPolicyById(state)(1)).toEqual(
|
||||
assignmentPoliciesList[0]
|
||||
);
|
||||
expect(getters.getAssignmentPolicyById(state)(3)).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,385 @@
|
||||
import { mutations } from '../../assignmentPolicies';
|
||||
import types from '../../../mutation-types';
|
||||
import assignmentPoliciesList from './fixtures';
|
||||
|
||||
describe('#mutations', () => {
|
||||
describe('#SET_ASSIGNMENT_POLICIES_UI_FLAG', () => {
|
||||
it('sets single ui flag', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isCreating: false,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
});
|
||||
|
||||
expect(state.uiFlags).toEqual({
|
||||
isFetching: true,
|
||||
isCreating: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('sets multiple ui flags', () => {
|
||||
const state = {
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
isCreating: true,
|
||||
});
|
||||
|
||||
expect(state.uiFlags).toEqual({
|
||||
isFetching: true,
|
||||
isCreating: true,
|
||||
isUpdating: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_ASSIGNMENT_POLICIES', () => {
|
||||
it('sets assignment policies records', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES](state, assignmentPoliciesList);
|
||||
|
||||
expect(state.records).toEqual(assignmentPoliciesList);
|
||||
});
|
||||
|
||||
it('replaces existing records', () => {
|
||||
const state = { records: [{ id: 999, name: 'Old Policy' }] };
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES](state, assignmentPoliciesList);
|
||||
|
||||
expect(state.records).toEqual(assignmentPoliciesList);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_ASSIGNMENT_POLICY', () => {
|
||||
it('sets single assignment policy record', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICY](state, assignmentPoliciesList[0]);
|
||||
|
||||
expect(state.records).toEqual([assignmentPoliciesList[0]]);
|
||||
});
|
||||
|
||||
it('replaces existing record', () => {
|
||||
const state = { records: [{ id: 1, name: 'Old Policy' }] };
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICY](state, assignmentPoliciesList[0]);
|
||||
|
||||
expect(state.records).toEqual([assignmentPoliciesList[0]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_ASSIGNMENT_POLICY', () => {
|
||||
it('adds new policy to empty records', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.ADD_ASSIGNMENT_POLICY](state, assignmentPoliciesList[0]);
|
||||
|
||||
expect(state.records).toEqual([assignmentPoliciesList[0]]);
|
||||
});
|
||||
|
||||
it('adds new policy to existing records', () => {
|
||||
const state = { records: [assignmentPoliciesList[0]] };
|
||||
|
||||
mutations[types.ADD_ASSIGNMENT_POLICY](state, assignmentPoliciesList[1]);
|
||||
|
||||
expect(state.records).toEqual([
|
||||
assignmentPoliciesList[0],
|
||||
assignmentPoliciesList[1],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#EDIT_ASSIGNMENT_POLICY', () => {
|
||||
it('updates existing policy by id', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{ ...assignmentPoliciesList[0] },
|
||||
{ ...assignmentPoliciesList[1] },
|
||||
],
|
||||
};
|
||||
|
||||
const updatedPolicy = {
|
||||
...assignmentPoliciesList[0],
|
||||
name: 'Updated Policy Name',
|
||||
description: 'Updated Description',
|
||||
};
|
||||
|
||||
mutations[types.EDIT_ASSIGNMENT_POLICY](state, updatedPolicy);
|
||||
|
||||
expect(state.records[0]).toEqual(updatedPolicy);
|
||||
expect(state.records[1]).toEqual(assignmentPoliciesList[1]);
|
||||
});
|
||||
|
||||
it('updates policy with camelCase properties', () => {
|
||||
const camelCasePolicy = {
|
||||
id: 1,
|
||||
name: 'Camel Case Policy',
|
||||
assignmentOrder: 'round_robin',
|
||||
conversationPriority: 'earliest_created',
|
||||
};
|
||||
|
||||
const state = {
|
||||
records: [camelCasePolicy],
|
||||
};
|
||||
|
||||
const updatedPolicy = {
|
||||
...camelCasePolicy,
|
||||
name: 'Updated Camel Case',
|
||||
assignmentOrder: 'balanced',
|
||||
};
|
||||
|
||||
mutations[types.EDIT_ASSIGNMENT_POLICY](state, updatedPolicy);
|
||||
|
||||
expect(state.records[0]).toEqual(updatedPolicy);
|
||||
});
|
||||
|
||||
it('does nothing if policy id not found', () => {
|
||||
const state = {
|
||||
records: [assignmentPoliciesList[0]],
|
||||
};
|
||||
|
||||
const nonExistentPolicy = {
|
||||
id: 999,
|
||||
name: 'Non-existent',
|
||||
};
|
||||
|
||||
const originalRecords = [...state.records];
|
||||
mutations[types.EDIT_ASSIGNMENT_POLICY](state, nonExistentPolicy);
|
||||
|
||||
expect(state.records).toEqual(originalRecords);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_ASSIGNMENT_POLICY', () => {
|
||||
it('deletes policy by id', () => {
|
||||
const state = {
|
||||
records: [assignmentPoliciesList[0], assignmentPoliciesList[1]],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICY](state, 1);
|
||||
|
||||
expect(state.records).toEqual([assignmentPoliciesList[1]]);
|
||||
});
|
||||
|
||||
it('does nothing if id not found', () => {
|
||||
const state = {
|
||||
records: [assignmentPoliciesList[0]],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICY](state, 999);
|
||||
|
||||
expect(state.records).toEqual([assignmentPoliciesList[0]]);
|
||||
});
|
||||
|
||||
it('handles empty records', () => {
|
||||
const state = { records: [] };
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICY](state, 1);
|
||||
|
||||
expect(state.records).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG', () => {
|
||||
it('sets inbox ui flags', () => {
|
||||
const state = {
|
||||
inboxUiFlags: {
|
||||
isFetching: false,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
});
|
||||
|
||||
expect(state.inboxUiFlags).toEqual({
|
||||
isFetching: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('merges with existing flags', () => {
|
||||
const state = {
|
||||
inboxUiFlags: {
|
||||
isFetching: false,
|
||||
isLoading: true,
|
||||
},
|
||||
};
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG](state, {
|
||||
isFetching: true,
|
||||
});
|
||||
|
||||
expect(state.inboxUiFlags).toEqual({
|
||||
isFetching: true,
|
||||
isLoading: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_ASSIGNMENT_POLICIES_INBOXES', () => {
|
||||
it('sets inboxes for existing policy', () => {
|
||||
const mockInboxes = [
|
||||
{ id: 1, name: 'Support Inbox' },
|
||||
{ id: 2, name: 'Sales Inbox' },
|
||||
];
|
||||
|
||||
const state = {
|
||||
records: [
|
||||
{ id: 1, name: 'Policy 1', inboxes: [] },
|
||||
{ id: 2, name: 'Policy 2', inboxes: [] },
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
inboxes: mockInboxes,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxes).toEqual(mockInboxes);
|
||||
expect(state.records[1].inboxes).toEqual([]);
|
||||
});
|
||||
|
||||
it('replaces existing inboxes', () => {
|
||||
const oldInboxes = [{ id: 99, name: 'Old Inbox' }];
|
||||
const newInboxes = [{ id: 1, name: 'New Inbox' }];
|
||||
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', inboxes: oldInboxes }],
|
||||
};
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
inboxes: newInboxes,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxes).toEqual(newInboxes);
|
||||
});
|
||||
|
||||
it('does nothing if policy not found', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', inboxes: [] }],
|
||||
};
|
||||
|
||||
const originalState = JSON.parse(JSON.stringify(state));
|
||||
|
||||
mutations[types.SET_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 999,
|
||||
inboxes: [{ id: 1, name: 'Test' }],
|
||||
});
|
||||
|
||||
expect(state).toEqual(originalState);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#DELETE_ASSIGNMENT_POLICIES_INBOXES', () => {
|
||||
it('removes inbox from policy', () => {
|
||||
const mockInboxes = [
|
||||
{ id: 1, name: 'Support Inbox' },
|
||||
{ id: 2, name: 'Sales Inbox' },
|
||||
{ id: 3, name: 'Marketing Inbox' },
|
||||
];
|
||||
|
||||
const state = {
|
||||
records: [
|
||||
{ id: 1, name: 'Policy 1', inboxes: mockInboxes },
|
||||
{ id: 2, name: 'Policy 2', inboxes: [] },
|
||||
],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
inboxId: 2,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxes).toEqual([
|
||||
{ id: 1, name: 'Support Inbox' },
|
||||
{ id: 3, name: 'Marketing Inbox' },
|
||||
]);
|
||||
expect(state.records[1].inboxes).toEqual([]);
|
||||
});
|
||||
|
||||
it('does nothing if policy not found', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{ id: 1, name: 'Policy 1', inboxes: [{ id: 1, name: 'Test' }] },
|
||||
],
|
||||
};
|
||||
|
||||
const originalState = JSON.parse(JSON.stringify(state));
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 999,
|
||||
inboxId: 1,
|
||||
});
|
||||
|
||||
expect(state).toEqual(originalState);
|
||||
});
|
||||
|
||||
it('does nothing if inbox not found in policy', () => {
|
||||
const mockInboxes = [{ id: 1, name: 'Support Inbox' }];
|
||||
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1', inboxes: mockInboxes }],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
inboxId: 999,
|
||||
});
|
||||
|
||||
expect(state.records[0].inboxes).toEqual(mockInboxes);
|
||||
});
|
||||
|
||||
it('handles policy with no inboxes', () => {
|
||||
const state = {
|
||||
records: [{ id: 1, name: 'Policy 1' }],
|
||||
};
|
||||
|
||||
mutations[types.DELETE_ASSIGNMENT_POLICIES_INBOXES](state, {
|
||||
policyId: 1,
|
||||
inboxId: 1,
|
||||
});
|
||||
|
||||
expect(state.records[0]).toEqual({ id: 1, name: 'Policy 1' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ADD_ASSIGNMENT_POLICIES_INBOXES', () => {
|
||||
it('updates policy attributes using MutationHelpers.updateAttributes', () => {
|
||||
const state = {
|
||||
records: [
|
||||
{ id: 1, name: 'Policy 1', assignedInboxCount: 2 },
|
||||
{ id: 2, name: 'Policy 2', assignedInboxCount: 1 },
|
||||
],
|
||||
};
|
||||
|
||||
const updatedPolicy = {
|
||||
id: 1,
|
||||
name: 'Policy 1',
|
||||
assignedInboxCount: 3,
|
||||
inboxes: [{ id: 1, name: 'New Inbox' }],
|
||||
};
|
||||
|
||||
mutations[types.ADD_ASSIGNMENT_POLICIES_INBOXES](state, updatedPolicy);
|
||||
|
||||
expect(state.records[0]).toEqual(updatedPolicy);
|
||||
expect(state.records[1]).toEqual({
|
||||
id: 2,
|
||||
name: 'Policy 2',
|
||||
assignedInboxCount: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user