feat: Allow users to disable marking offline automatically (#6079)

Co-authored-by: Nithin David <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
Pranav Raj S
2022-12-16 11:59:27 -08:00
committed by GitHub
parent 82d3398932
commit aaacf9d4d2
14 changed files with 188 additions and 14 deletions

View File

@@ -48,6 +48,14 @@ export const getters = {
return currentAccount.availability;
},
getCurrentUserAutoOffline($state, $getters) {
const { accounts = [] } = $state.currentUser;
const [currentAccount = {}] = accounts.filter(
account => account.id === $getters.getCurrentAccountId
);
return currentAccount.auto_offline;
},
getCurrentAccountId(_, __, rootState) {
if (rootState.route.params && rootState.route.params.accountId) {
return Number(rootState.route.params.accountId);
@@ -174,6 +182,15 @@ export const actions = {
}
},
updateAutoOffline: async ({ commit }, { accountId, autoOffline }) => {
try {
const response = await authAPI.updateAutoOffline(accountId, autoOffline);
commit(types.SET_CURRENT_USER, response.data);
} catch (error) {
// Ignore error
}
},
setCurrentUserAvailability({ commit, state: $state }, data) {
if (data[$state.currentUser.id]) {
commit(types.SET_CURRENT_USER_AVAILABILITY, data[$state.currentUser.id]);

View File

@@ -88,6 +88,38 @@ describe('#actions', () => {
});
});
describe('#updateAutoOffline', () => {
it('sends correct actions if API is success', async () => {
axios.post.mockResolvedValue({
data: {
id: 1,
name: 'John',
accounts: [
{
account_id: 1,
auto_offline: false,
},
],
},
headers: { expiry: 581842904 },
});
await actions.updateAutoOffline(
{ commit, dispatch },
{ autoOffline: false, accountId: 1 }
);
expect(commit.mock.calls).toEqual([
[
types.default.SET_CURRENT_USER,
{
id: 1,
name: 'John',
accounts: [{ account_id: 1, auto_offline: false }],
},
],
]);
});
});
describe('#updateUISettings', () => {
it('sends correct actions if API is success', async () => {
axios.put.mockResolvedValue({