fix: Update the relevant agent presence only (#5220)

This commit is contained in:
Pranav Raj S
2022-08-09 12:32:09 +05:30
committed by GitHub
parent cbcee6414c
commit 657bd44418
11 changed files with 100 additions and 62 deletions

View File

@@ -96,13 +96,21 @@ describe('#actions', () => {
});
describe('#updatePresence', () => {
it('sends correct actions if API is success', async () => {
it('sends correct actions', async () => {
const data = { users: { 1: 'online' }, contacts: { 2: 'online' } };
actions.updatePresence({ commit, dispatch }, data);
expect(commit.mock.calls).toEqual([
[types.default.SET_AGENT_UPDATING_STATUS, true],
[types.default.UPDATE_AGENTS_PRESENCE, data],
[types.default.SET_AGENT_UPDATING_STATUS, false],
]);
});
});
describe('#updateSingleAgentPresence', () => {
it('sends correct actions', async () => {
const data = { id: 1, availabilityStatus: 'online' };
actions.updateSingleAgentPresence({ commit, dispatch }, data);
expect(commit.mock.calls).toEqual([
[types.default.UPDATE_SINGLE_AGENT_PRESENCE, data],
]);
});
});

View File

@@ -129,19 +129,4 @@ describe('#getters', () => {
offline: 1,
});
});
it('getAgentStatus', () => {
const state = {
records: [
{
id: 1,
name: 'Agent 1',
email: 'agent1@chatwoot.com',
confirmed: true,
availability_status: 'online',
},
],
};
expect(getters.getAgentsCount(state)).toEqual(1);
});
});

View File

@@ -97,4 +97,44 @@ describe('#mutations', () => {
]);
});
});
describe('#UPDATE_SINGLE_AGENT_PRESENCE', () => {
it('updates single agent presence', () => {
const state = {
records: [
{
id: 1,
name: 'Agent1',
email: 'agent1@chatwoot.com',
availability_status: 'offline',
},
{
id: 2,
name: 'Agent1',
email: 'agent1@chatwoot.com',
availability_status: 'online',
},
],
};
mutations[types.default.UPDATE_SINGLE_AGENT_PRESENCE](state, {
id: 1,
availabilityStatus: 'busy',
});
expect(state.records).toEqual([
{
id: 1,
name: 'Agent1',
email: 'agent1@chatwoot.com',
availability_status: 'busy',
},
{
id: 2,
name: 'Agent1',
email: 'agent1@chatwoot.com',
availability_status: 'online',
},
]);
});
});
});

View File

@@ -80,7 +80,10 @@ describe('#actions', () => {
],
]);
expect(dispatch.mock.calls).toEqual([
['agents/updatePresence', { 1: 'offline' }],
[
'agents/updateSingleAgentPresence',
{ availabilityStatus: 'offline', id: 1 },
],
]);
});
});