fix: Update agent list when the user changes their presence (#1436)

This commit is contained in:
Pranav Raj S 2020-11-21 22:43:27 +05:30 committed by GitHub
parent 61d26f71c1
commit be2d3ea124
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -105,10 +105,13 @@ export const actions = {
}
},
updateAvailability: ({ commit }, { availability }) => {
updateAvailability: ({ commit, dispatch }, { availability }) => {
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);
dispatch('agents/updatePresence', { [id]: availabilityStatus });
});
},

View file

@ -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', () => {
it('sends correct actions if user is logged in', async () => {
Cookies.getJSON.mockImplementation(() => true);