feat: Update the slack integration-flow to allow users to select the channel (#7637)

This commit is contained in:
Pranav Raj S
2023-07-28 14:50:30 -07:00
committed by GitHub
parent 4d8ba0148c
commit 9ddd428935
28 changed files with 593 additions and 131 deletions

View File

@@ -3,6 +3,7 @@ import Vue from 'vue';
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
import * as types from '../mutation-types';
import IntegrationsAPI from '../../api/integrations';
import { throwErrorMessage } from 'dashboard/store/utils/api';
const state = {
records: [],
@@ -13,6 +14,9 @@ const state = {
isUpdating: false,
isCreatingHook: false,
isDeletingHook: false,
isCreatingSlack: false,
isUpdatingSlack: false,
isFetchingSlackChannels: false,
},
};
@@ -52,15 +56,45 @@ export const actions = {
},
connectSlack: async ({ commit }, code) => {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: true });
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isCreatingSlack: true });
try {
const response = await IntegrationsAPI.connectSlack(code);
commit(types.default.ADD_INTEGRATION, response.data);
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: false });
} catch (error) {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdating: false });
throwErrorMessage(error);
} finally {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, {
isCreatingSlack: false,
});
}
},
updateSlack: async ({ commit }, slackObj) => {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isUpdatingSlack: true });
try {
const response = await IntegrationsAPI.updateSlack(slackObj);
commit(types.default.ADD_INTEGRATION, response.data);
} catch (error) {
throwErrorMessage(error);
} finally {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, {
isUpdatingSlack: false,
});
}
},
listAllSlackChannels: async ({ commit }) => {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, {
isFetchingSlackChannels: true,
});
try {
const response = await IntegrationsAPI.listAllSlackChannels();
return response.data;
} catch (error) {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, {
isFetchingSlackChannels: false,
});
}
return null;
},
deleteIntegration: async ({ commit }, integrationId) => {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: true });
@@ -75,6 +109,17 @@ export const actions = {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isDeleting: false });
}
},
showHook: async ({ commit }, hookId) => {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isFetchingItem: true });
try {
const response = await IntegrationsAPI.showHook(hookId);
commit(types.default.ADD_INTEGRATION_HOOKS, response.data);
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isFetchingItem: false });
} catch (error) {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isFetchingItem: false });
throw new Error(error);
}
},
createHook: async ({ commit }, hookData) => {
commit(types.default.SET_INTEGRATIONS_UI_FLAG, { isCreatingHook: true });
try {

View File

@@ -31,21 +31,42 @@ describe('#actions', () => {
describe('#connectSlack:', () => {
it('sends correct actions if API is success', async () => {
let data = { id: 'slack', enabled: true };
let data = { hooks: [{ id: 'slack', enabled: false }] };
axios.post.mockResolvedValue({ data: data });
await actions.connectSlack({ commit });
expect(commit.mock.calls).toEqual([
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdating: true }],
[types.SET_INTEGRATIONS_UI_FLAG, { isCreatingSlack: true }],
[types.ADD_INTEGRATION, data],
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdating: false }],
[types.SET_INTEGRATIONS_UI_FLAG, { isCreatingSlack: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.post.mockRejectedValue(errorMessage);
await actions.connectSlack({ commit });
await expect(actions.connectSlack({ commit })).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdating: true }],
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdating: false }],
[types.SET_INTEGRATIONS_UI_FLAG, { isCreatingSlack: true }],
[types.SET_INTEGRATIONS_UI_FLAG, { isCreatingSlack: false }],
]);
});
});
describe('#updateSlack', () => {
it('sends correct actions if API is success', async () => {
let data = { hooks: [{ id: 'slack', enabled: false }] };
axios.patch.mockResolvedValue({ data: data });
await actions.updateSlack({ commit }, { referenceId: '12345' });
expect(commit.mock.calls).toEqual([
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdatingSlack: true }],
[types.ADD_INTEGRATION, data],
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdatingSlack: false }],
]);
});
it('sends correct actions if API is error', async () => {
axios.patch.mockRejectedValue(errorMessage);
await expect(actions.updateSlack({ commit })).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdatingSlack: true }],
[types.SET_INTEGRATIONS_UI_FLAG, { isUpdatingSlack: false }],
]);
});
});