feat: Add actions and API for deleting message via API (#2519)
This commit is contained in:
parent
b705eb39e2
commit
044b6872a4
4 changed files with 38 additions and 0 deletions
|
@ -30,6 +30,10 @@ class MessageApi extends ApiClient {
|
|||
});
|
||||
}
|
||||
|
||||
delete(conversationID, messageId) {
|
||||
return axios.delete(`${this.url}/${conversationID}/messages/${messageId}`);
|
||||
}
|
||||
|
||||
getPreviousMessages({ conversationId, before }) {
|
||||
return axios.get(`${this.url}/${conversationId}/messages`, {
|
||||
params: { before },
|
||||
|
|
|
@ -178,6 +178,20 @@ const actions = {
|
|||
commit(types.default.ADD_MESSAGE, message);
|
||||
},
|
||||
|
||||
deleteMessage: async function deleteLabels(
|
||||
{ commit },
|
||||
{ conversationId, messageId }
|
||||
) {
|
||||
try {
|
||||
const response = await MessageApi.delete(conversationId, messageId);
|
||||
const { data } = response;
|
||||
// The delete message is actually deleting the content.
|
||||
commit(types.default.ADD_MESSAGE, data);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
|
||||
addConversation({ commit, state, dispatch }, conversation) {
|
||||
const { currentInbox } = state;
|
||||
const {
|
||||
|
|
|
@ -238,3 +238,22 @@ describe('#actions', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#deleteMessage', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const [conversationId, messageId] = [1, 1];
|
||||
axios.delete.mockResolvedValue({ data: { id: 1, content: 'deleted' } });
|
||||
await actions.deleteMessage({ commit }, { conversationId, messageId });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.ADD_MESSAGE, { id: 1, content: 'deleted' }],
|
||||
]);
|
||||
});
|
||||
it('sends no actions if API is error', async () => {
|
||||
const [conversationId, messageId] = [1, 1];
|
||||
axios.delete.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.deleteMessage({ commit }, { conversationId, messageId })
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -31,6 +31,7 @@ export default {
|
|||
ASSIGN_TEAM: 'ASSIGN_TEAM',
|
||||
SET_CHAT_META: 'SET_CHAT_META',
|
||||
ADD_MESSAGE: 'ADD_MESSAGE',
|
||||
DELETE_MESSAGE: 'DELETE_MESSAGE',
|
||||
ADD_PENDING_MESSAGE: 'ADD_PENDING_MESSAGE',
|
||||
MARK_MESSAGE_READ: 'MARK_MESSAGE_READ',
|
||||
SET_PREVIOUS_CONVERSATIONS: 'SET_PREVIOUS_CONVERSATIONS',
|
||||
|
|
Loading…
Reference in a new issue