feat: Add an option to edit webhook URL (#2316)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -52,6 +52,30 @@ describe('#actions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.patch.mockResolvedValue({
|
||||
data: { payload: { webhook: webhooks[1] } },
|
||||
});
|
||||
await actions.update({ commit }, webhooks[1]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_WEBHOOK_UI_FLAG, { updatingItem: true }],
|
||||
[types.default.UPDATE_WEBHOOK, webhooks[1]],
|
||||
[types.default.SET_WEBHOOK_UI_FLAG, { updatingItem: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.put.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(actions.update({ commit }, webhooks[0])).rejects.toThrow(
|
||||
Error
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_WEBHOOK_UI_FLAG, { updatingItem: true }],
|
||||
[types.default.SET_WEBHOOK_UI_FLAG, { updatingItem: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.delete.mockResolvedValue({ data: webhooks[0] });
|
||||
|
||||
@@ -30,4 +30,14 @@ describe('#mutations', () => {
|
||||
expect(state.records).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#UPDATE_WEBHOOK', () => {
|
||||
it('update webhook ', () => {
|
||||
const state = {
|
||||
records: [webhooks[0]],
|
||||
};
|
||||
mutations[types.default.UPDATE_WEBHOOK](state, webhooks[0]);
|
||||
expect(state.records[0].url).toEqual('https://1.chatwoot.com');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ const state = {
|
||||
fetchingList: false,
|
||||
creatingItem: false,
|
||||
deletingItem: false,
|
||||
updatingItem: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -36,7 +37,10 @@ export const actions = {
|
||||
commit(types.default.SET_WEBHOOK_UI_FLAG, { creatingItem: true });
|
||||
try {
|
||||
const response = await webHookAPI.create(params);
|
||||
commit(types.default.ADD_WEBHOOK, response.data.payload.webhook);
|
||||
const {
|
||||
payload: { webhook },
|
||||
} = response.data;
|
||||
commit(types.default.ADD_WEBHOOK, webhook);
|
||||
commit(types.default.SET_WEBHOOK_UI_FLAG, { creatingItem: false });
|
||||
} catch (error) {
|
||||
commit(types.default.SET_WEBHOOK_UI_FLAG, { creatingItem: false });
|
||||
@@ -44,6 +48,18 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
update: async ({ commit }, { id, ...updateObj }) => {
|
||||
commit(types.default.SET_WEBHOOK_UI_FLAG, { updatingItem: true });
|
||||
try {
|
||||
const response = await webHookAPI.update(id, updateObj);
|
||||
commit(types.default.UPDATE_WEBHOOK, response.data.payload.webhook);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
} finally {
|
||||
commit(types.default.SET_WEBHOOK_UI_FLAG, { updatingItem: false });
|
||||
}
|
||||
},
|
||||
|
||||
async delete({ commit }, id) {
|
||||
commit(types.default.SET_WEBHOOK_UI_FLAG, { deletingItem: true });
|
||||
try {
|
||||
@@ -64,10 +80,10 @@ export const mutations = {
|
||||
...data,
|
||||
};
|
||||
},
|
||||
|
||||
[types.default.SET_WEBHOOK]: MutationHelpers.set,
|
||||
[types.default.ADD_WEBHOOK]: MutationHelpers.create,
|
||||
[types.default.DELETE_WEBHOOK]: MutationHelpers.destroy,
|
||||
[types.default.UPDATE_WEBHOOK]: MutationHelpers.update,
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -91,6 +91,7 @@ export default {
|
||||
SET_WEBHOOK: 'SET_WEBHOOK',
|
||||
ADD_WEBHOOK: 'ADD_WEBHOOK',
|
||||
DELETE_WEBHOOK: 'DELETE_WEBHOOK',
|
||||
UPDATE_WEBHOOK: 'UPDATE_WEBHOOK',
|
||||
|
||||
// Contacts
|
||||
SET_CONTACT_META: 'SET_CONTACT_META',
|
||||
|
||||
Reference in New Issue
Block a user