feat: Clone automation rules (#3893)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
parent
8821106da9
commit
fc1f257793
6 changed files with 70 additions and 26 deletions
|
@ -1,9 +1,14 @@
|
|||
/* global axios */
|
||||
import ApiClient from './ApiClient';
|
||||
|
||||
class AutomationsAPI extends ApiClient {
|
||||
constructor() {
|
||||
super('automation_rules', { accountScoped: true });
|
||||
}
|
||||
|
||||
clone(automationId) {
|
||||
return axios.post(`${this.url}/${automationId}/clone`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new AutomationsAPI();
|
||||
|
|
|
@ -9,6 +9,7 @@ describe('#AutomationsAPI', () => {
|
|||
expect(automations).toHaveProperty('create');
|
||||
expect(automations).toHaveProperty('update');
|
||||
expect(automations).toHaveProperty('delete');
|
||||
expect(automations).toHaveProperty('clone');
|
||||
expect(automations.url).toBe('/api/v1/automation_rules');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -71,6 +71,13 @@
|
|||
"ERROR_MESSAGE": "Could not update automation rule, Please try again later"
|
||||
}
|
||||
},
|
||||
"CLONE": {
|
||||
"TOOLTIP": "Clone",
|
||||
"API": {
|
||||
"SUCCESS_MESSAGE": "Automation cloned successfully",
|
||||
"ERROR_MESSAGE": "Could not clone automation rule, Please try again later"
|
||||
}
|
||||
},
|
||||
"FORM": {
|
||||
"EDIT": "Edit",
|
||||
"CREATE": "Create",
|
||||
|
|
|
@ -54,17 +54,17 @@
|
|||
@click="openEditPopup(automation)"
|
||||
>
|
||||
</woot-button>
|
||||
<!-- <woot-button
|
||||
v-tooltip.top="'Clone'"
|
||||
<woot-button
|
||||
v-tooltip.top="$t('AUTOMATION.CLONE.TOOLTIP')"
|
||||
variant="smooth"
|
||||
size="tiny"
|
||||
color-scheme="primary"
|
||||
class-names="grey-btn"
|
||||
:is-loading="loading[automation.id]"
|
||||
icon="copy"
|
||||
@click="openEditPopup(automation)"
|
||||
@click="cloneAutomation(automation.id)"
|
||||
>
|
||||
</woot-button> -->
|
||||
</woot-button>
|
||||
<woot-button
|
||||
v-tooltip.top="$t('AUTOMATION.FORM.DELETE')"
|
||||
variant="smooth"
|
||||
|
@ -204,6 +204,16 @@ export default {
|
|||
this.showAlert(this.$t('AUTOMATION.DELETE.API.ERROR_MESSAGE'));
|
||||
}
|
||||
},
|
||||
async cloneAutomation(id) {
|
||||
try {
|
||||
await this.$store.dispatch('automations/clone', id);
|
||||
this.showAlert(this.$t('AUTOMATION.CLONE.API.SUCCESS_MESSAGE'));
|
||||
this.$store.dispatch('automations/get');
|
||||
this.loading[this.selectedResponse.id] = false;
|
||||
} catch (error) {
|
||||
this.showAlert(this.$t('AUTOMATION.CLONE.API.ERROR_MESSAGE'));
|
||||
}
|
||||
},
|
||||
async submitAutomation(payload, mode) {
|
||||
try {
|
||||
const action =
|
||||
|
|
|
@ -66,6 +66,16 @@ export const actions = {
|
|||
commit(types.SET_AUTOMATION_UI_FLAG, { isDeleting: false });
|
||||
}
|
||||
},
|
||||
clone: async ({ commit }, id) => {
|
||||
commit(types.SET_AUTOMATION_UI_FLAG, { isCloning: true });
|
||||
try {
|
||||
await AutomationAPI.clone(id);
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
} finally {
|
||||
commit(types.SET_AUTOMATION_UI_FLAG, { isCloning: false });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
|
|
|
@ -47,28 +47,28 @@ describe('#actions', () => {
|
|||
]);
|
||||
});
|
||||
});
|
||||
// API Work in progress
|
||||
// describe('#update', () => {
|
||||
// it('sends correct actions if API is success', async () => {
|
||||
// axios.patch.mockResolvedValue({ data: automationsList[0] });
|
||||
// await actions.update({ commit }, automationsList[0]);
|
||||
// expect(commit.mock.calls).toEqual([
|
||||
// [types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: true }],
|
||||
// [types.default.EDIT_AUTOMATION, automationsList[0]],
|
||||
// [types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: false }],
|
||||
// ]);
|
||||
// });
|
||||
// it('sends correct actions if API is error', async () => {
|
||||
// axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
// await expect(
|
||||
// actions.update({ commit }, automationsList[0])
|
||||
// ).rejects.toThrow(Error);
|
||||
// expect(commit.mock.calls).toEqual([
|
||||
// [types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: true }],
|
||||
// [types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: false }],
|
||||
// ]);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('#update', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.patch.mockResolvedValue({ data: automationsList[0] });
|
||||
await actions.update({ commit }, automationsList[0]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: true }],
|
||||
[types.default.EDIT_AUTOMATION, automationsList[0]],
|
||||
[types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.update({ commit }, automationsList[0])
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: true }],
|
||||
[types.default.SET_AUTOMATION_UI_FLAG, { isUpdating: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
|
@ -91,4 +91,15 @@ describe('#actions', () => {
|
|||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clone', () => {
|
||||
it('clones the automation', async () => {
|
||||
axios.post.mockResolvedValue({ data: automationsList[0] });
|
||||
await actions.clone({ commit }, automationsList[0]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_AUTOMATION_UI_FLAG, { isCloning: true }],
|
||||
[types.default.SET_AUTOMATION_UI_FLAG, { isCloning: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue