feat: Set up store for teams (#1689)
This commit is contained in:
committed by
GitHub
parent
cadb246eaa
commit
941d4219f0
@@ -56,4 +56,27 @@ describe('#actions', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.patch.mockResolvedValue({ data: teamMembers });
|
||||
await actions.update({ commit }, { agentsList: teamMembers, teamId: 1 });
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[SET_TEAM_MEMBERS_UI_FLAG, { isUpdating: true }],
|
||||
[ADD_AGENTS_TO_TEAM, { data: teamMembers }],
|
||||
[SET_TEAM_MEMBERS_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.update({ commit }, { agentsList: teamMembers, teamId: 1 })
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[SET_TEAM_MEMBERS_UI_FLAG, { isUpdating: true }],
|
||||
[SET_TEAM_MEMBERS_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ describe('#actions', () => {
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.patch.mockResolvedValue({ data: { payload: teamsList[1] } });
|
||||
axios.patch.mockResolvedValue({ data: teamsList[1] });
|
||||
await actions.update({ commit }, teamsList[1]);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
|
||||
@@ -46,6 +46,20 @@ export const actions = {
|
||||
commit(SET_TEAM_MEMBERS_UI_FLAG, { isCreating: false });
|
||||
}
|
||||
},
|
||||
update: async ({ commit }, { agentsList, teamId }) => {
|
||||
commit(SET_TEAM_MEMBERS_UI_FLAG, { isUpdating: true });
|
||||
try {
|
||||
const response = await TeamsAPI.updateAgents({
|
||||
agentsList,
|
||||
teamId,
|
||||
});
|
||||
commit(ADD_AGENTS_TO_TEAM, response);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
} finally {
|
||||
commit(SET_TEAM_MEMBERS_UI_FLAG, { isUpdating: false });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
|
||||
@@ -56,7 +56,7 @@ export const actions = {
|
||||
commit(SET_TEAM_UI_FLAG, { isUpdating: true });
|
||||
try {
|
||||
const response = await TeamsAPI.update(id, updateObj);
|
||||
commit(EDIT_TEAM, response.data.payload);
|
||||
commit(EDIT_TEAM, response.data);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user