feat: Clone automation rules (#3893)

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Fayaz Ahmed
2022-02-03 09:14:22 +05:30
committed by GitHub
parent 8821106da9
commit fc1f257793
6 changed files with 70 additions and 26 deletions

View File

@@ -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 = {

View File

@@ -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 }],
]);
});
});
});