Chore: Fix presence for current user (#1001)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -34,6 +34,10 @@ export const getters = {
|
||||
return _state.currentUser.id;
|
||||
},
|
||||
|
||||
getCurrentUserAvailabilityStatus(_state) {
|
||||
return _state.currentUser.availability_status;
|
||||
},
|
||||
|
||||
getCurrentAccountId(_state) {
|
||||
return _state.currentAccountId;
|
||||
},
|
||||
@@ -104,10 +108,22 @@ export const actions = {
|
||||
setCurrentAccountId({ commit }, accountId) {
|
||||
commit(types.default.SET_CURRENT_ACCOUNT_ID, accountId);
|
||||
},
|
||||
|
||||
setCurrentUserAvailabilityStatus({ commit, state: $state }, data) {
|
||||
if (data[$state.currentUser.id]) {
|
||||
commit(
|
||||
types.default.SET_CURRENT_USER_AVAILABILITY,
|
||||
data[$state.currentUser.id]
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// mutations
|
||||
const mutations = {
|
||||
[types.default.SET_CURRENT_USER_AVAILABILITY](_state, status) {
|
||||
Vue.set(_state.currentUser, 'availability_status', status);
|
||||
},
|
||||
[types.default.CLEAR_USER](_state) {
|
||||
_state.currentUser.id = null;
|
||||
},
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
/* eslint no-console: 0 */
|
||||
/* eslint no-param-reassign: 0 */
|
||||
|
||||
// const chatType = 'all';
|
||||
// initial state
|
||||
const state = {};
|
||||
|
||||
// actions
|
||||
const actions = {};
|
||||
|
||||
export default {
|
||||
state,
|
||||
actions,
|
||||
};
|
||||
@@ -67,4 +67,30 @@ describe('#actions', () => {
|
||||
expect(dispatch).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setCurrentUserAvailabilityStatus', () => {
|
||||
it('sends correct mutations if user id is available', async () => {
|
||||
actions.setCurrentUserAvailabilityStatus(
|
||||
{
|
||||
commit,
|
||||
state: { currentUser: { id: 1 } },
|
||||
},
|
||||
{ 1: 'online' }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_CURRENT_USER_AVAILABILITY, 'online'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not send correct mutations if user id is not available', async () => {
|
||||
actions.setCurrentUserAvailabilityStatus(
|
||||
{
|
||||
commit,
|
||||
state: { currentUser: { id: 1 } },
|
||||
},
|
||||
{}
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,4 +17,12 @@ describe('#getters', () => {
|
||||
getters.getCurrentUser({ currentUser: { id: 1, name: 'Pranav' } })
|
||||
).toEqual({ id: 1, name: 'Pranav' });
|
||||
});
|
||||
|
||||
it('get', () => {
|
||||
expect(
|
||||
getters.getCurrentUserAvailabilityStatus({
|
||||
currentUser: { id: 1, name: 'Pranav', availability_status: 'busy' },
|
||||
})
|
||||
).toEqual('busy');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user