Remove RECEIVE_DELETE_LICENSE mutation

The RECEIVE_DELETE_LICENSE mutation did the same thing as
RESET_LICENSE_IN_MODAL, so this removes it. This also ensures that the
fetchLicenses action is properly dispatched. This was done via a
mediator, but we can simplify this by dispatching from the
receiveDeleteLicense action directly.
parent 629fea7f
......@@ -10,7 +10,6 @@ import { licenseManagementModule } from 'ee/vue_shared/license_compliance/store/
import modalModule from '~/vuex_shared/modules/modal';
import { LICENSE_LIST } from './constants';
import listModule from './modules/list';
import mediator from './plugins/mediator';
import createState from './state';
Vue.use(Vuex);
......@@ -24,5 +23,4 @@ export default (settings = {}) =>
[APPROVALS]: approvalsModule(),
[APPROVALS_MODAL]: modalModule(),
},
plugins: [mediator],
});
import { LICENSE_MANAGEMENT } from 'ee/vue_shared/license_compliance/store/constants';
import * as licenseMangementMutationTypes from 'ee/vue_shared/license_compliance/store/mutation_types';
import { LICENSE_LIST } from '../constants';
export default (store) => {
store.subscribe(({ type }) => {
switch (type) {
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`:
store.dispatch(`${LICENSE_LIST}/fetchLicenses`);
break;
default:
}
});
};
......@@ -27,7 +27,8 @@ export const resetLicenseInModal = ({ commit }) => {
};
export const receiveDeleteLicense = ({ commit, dispatch }, id) => {
commit(types.RECEIVE_DELETE_LICENSE);
commit(types.RESET_LICENSE_IN_MODAL);
dispatch(`${LICENSE_LIST}/fetchLicenses`, null, { root: true });
return dispatch('fetchManagedLicenses').then(() => {
dispatch('removePendingLicense', id);
});
......
export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE';
export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCESS';
export const RECEIVE_MANAGED_LICENSES_ERROR = 'RECEIVE_MANAGED_LICENSES_ERROR';
export const RECEIVE_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS';
......
......@@ -64,12 +64,6 @@ export default {
isLoadingLicenseReport: true,
});
},
[types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, {
currentLicenseInModal: null,
});
},
[types.REQUEST_LICENSE_CHECK_APPROVAL_RULE](state) {
Object.assign(state, {
isLoadingLicenseCheckApprovalRule: true,
......
import { LICENSE_LIST } from 'ee/license_compliance/store/constants';
import createStore from 'ee/license_compliance/store/index';
import { LICENSE_MANAGEMENT } from 'ee/vue_shared/license_compliance/store/constants';
import * as licenseMangementMutationTypes from 'ee/vue_shared/license_compliance/store/mutation_types';
describe('mediator', () => {
let store;
beforeEach(() => {
store = createStore();
jest.spyOn(store, 'dispatch').mockImplementation();
});
it('triggers fetching of detected licenses after a license policy is deleted', () => {
store.commit(`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`);
expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`);
});
});
......@@ -118,9 +118,10 @@ describe('License store actions', () => {
});
describe('receiveDeleteLicense', () => {
it('commits RECEIVE_DELETE_LICENSE and dispatches fetchManagedLicenses and removePendingLicense', () => {
it('commits RESET_LICENSE_IN_MODAL and dispatches licenseList/fetchLicenses, fetchManagedLicenses and removePendingLicense', () => {
return actions.receiveDeleteLicense(store, licenseId).then(() => {
expect(mockCommit).toHaveBeenCalledWith(mutationTypes.RECEIVE_DELETE_LICENSE);
expect(mockCommit).toHaveBeenCalledWith(mutationTypes.RESET_LICENSE_IN_MODAL);
expectDispatched('licenseList/fetchLicenses', null, { root: true });
expectDispatched('fetchManagedLicenses');
expectDispatched('removePendingLicense', licenseId);
});
......
......@@ -68,21 +68,6 @@ describe('License store mutations', () => {
});
});
describe('RECEIVE_DELETE_LICENSE', () => {
it('closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
currentLicenseInModal: approvedLicense,
},
});
store.commit(`licenseManagement/${types.RECEIVE_DELETE_LICENSE}`);
expect(store.state.licenseManagement.currentLicenseInModal).toBeNull();
});
});
describe('REQUEST_LICENSE_CHECK_APPROVAL_RULE', () => {
it('sets isLoadingLicenseCheckApprovalRule to true', () => {
store.replaceState({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment