fix: Update agent list when the user changes their presence (#1436)
This commit is contained in:
parent
61d26f71c1
commit
be2d3ea124
2 changed files with 23 additions and 2 deletions
|
@ -105,10 +105,13 @@ export const actions = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateAvailability: ({ commit }, { availability }) => {
|
updateAvailability: ({ commit, dispatch }, { availability }) => {
|
||||||
authAPI.updateAvailability({ availability }).then(response => {
|
authAPI.updateAvailability({ availability }).then(response => {
|
||||||
setUser(response.data, getHeaderExpiry(response));
|
const userData = response.data;
|
||||||
|
const { id, availability_status: availabilityStatus } = userData;
|
||||||
|
setUser(userData, getHeaderExpiry(response));
|
||||||
commit(types.default.SET_CURRENT_USER);
|
commit(types.default.SET_CURRENT_USER);
|
||||||
|
dispatch('agents/updatePresence', { [id]: availabilityStatus });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,24 @@ describe('#actions', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#updateAvailability', () => {
|
||||||
|
it('sends correct actions if API is success', async () => {
|
||||||
|
axios.put.mockResolvedValue({
|
||||||
|
data: { id: 1, name: 'John', availability_status: 'offline' },
|
||||||
|
headers: { expiry: 581842904 },
|
||||||
|
});
|
||||||
|
await actions.updateAvailability(
|
||||||
|
{ commit, dispatch },
|
||||||
|
{ availability: 'offline' }
|
||||||
|
);
|
||||||
|
expect(setUser).toHaveBeenCalledTimes(1);
|
||||||
|
expect(commit.mock.calls).toEqual([[types.default.SET_CURRENT_USER]]);
|
||||||
|
expect(dispatch.mock.calls).toEqual([
|
||||||
|
['agents/updatePresence', { 1: 'offline' }],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#setUser', () => {
|
describe('#setUser', () => {
|
||||||
it('sends correct actions if user is logged in', async () => {
|
it('sends correct actions if user is logged in', async () => {
|
||||||
Cookies.getJSON.mockImplementation(() => true);
|
Cookies.getJSON.mockImplementation(() => true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue