Feature: Add/Edit conversation labels (#488)
Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
committed by
GitHub
parent
77473dc2aa
commit
e61ba95cf7
@@ -6,6 +6,8 @@ const state = {
|
||||
records: {},
|
||||
uiFlags: {
|
||||
isFetching: false,
|
||||
isUpdating: false,
|
||||
isError: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -38,6 +40,30 @@ export const actions = {
|
||||
});
|
||||
}
|
||||
},
|
||||
update: async ({ commit }, { conversationId, labels }) => {
|
||||
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
||||
isUpdating: true,
|
||||
});
|
||||
try {
|
||||
const response = await ConversationAPI.updateLabels(
|
||||
conversationId,
|
||||
labels
|
||||
);
|
||||
commit(types.default.SET_CONVERSATION_LABELS, {
|
||||
id: conversationId,
|
||||
data: response.data.payload,
|
||||
});
|
||||
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
||||
isUpdating: false,
|
||||
isError: false,
|
||||
});
|
||||
} catch (error) {
|
||||
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
||||
isUpdating: false,
|
||||
isError: true,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
|
||||
@@ -32,4 +32,46 @@ describe('#actions', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
it('updates correct actions if API is success', async () => {
|
||||
axios.post.mockResolvedValue({
|
||||
data: { payload: { conversationId: '1', labels: ['on-hold'] } },
|
||||
});
|
||||
await actions.update(
|
||||
{ commit },
|
||||
{ conversationId: '1', labels: ['on-hold'] }
|
||||
);
|
||||
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_CONVERSATION_LABELS_UI_FLAG, { isUpdating: true }],
|
||||
[
|
||||
types.default.SET_CONVERSATION_LABELS,
|
||||
{
|
||||
id: '1',
|
||||
data: { conversationId: '1', labels: ['on-hold'] },
|
||||
},
|
||||
],
|
||||
[
|
||||
types.default.SET_CONVERSATION_LABELS_UI_FLAG,
|
||||
{ isUpdating: false, isError: false },
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.post.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await actions.update(
|
||||
{ commit },
|
||||
{ conversationId: '1', labels: ['on-hold'] }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_CONVERSATION_LABELS_UI_FLAG, { isUpdating: true }],
|
||||
[
|
||||
types.default.SET_CONVERSATION_LABELS_UI_FLAG,
|
||||
{ isUpdating: false, isError: true },
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user