Remove RECEIVE_SET_LICENSE_APPROVAL mutation

The RECEIVE_SET_LICENSE_APPROVAL 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
receiveSetLicenseApproval action directly.
parent 23ded7ae
...@@ -5,7 +5,6 @@ import { LICENSE_LIST } from '../constants'; ...@@ -5,7 +5,6 @@ import { LICENSE_LIST } from '../constants';
export default (store) => { export default (store) => {
store.subscribe(({ type }) => { store.subscribe(({ type }) => {
switch (type) { switch (type) {
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_SET_LICENSE_APPROVAL}`:
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`: case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`:
store.dispatch(`${LICENSE_LIST}/fetchLicenses`); store.dispatch(`${LICENSE_LIST}/fetchLicenses`);
break; break;
......
import { LICENSE_CHECK_NAME } from 'ee/approvals/constants'; import { LICENSE_CHECK_NAME } from 'ee/approvals/constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import pollUntilComplete from '~/lib/utils/poll_until_complete'; import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { LICENSE_LIST } from 'ee/license_compliance/store/constants';
import { LICENSE_APPROVAL_STATUS } from '../constants'; import { LICENSE_APPROVAL_STATUS } from '../constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
import { convertToOldReportFormat } from './utils'; import { convertToOldReportFormat } from './utils';
...@@ -97,7 +98,8 @@ export const fetchParsedLicenseReport = ({ dispatch, state }) => { ...@@ -97,7 +98,8 @@ export const fetchParsedLicenseReport = ({ dispatch, state }) => {
}; };
export const receiveSetLicenseApproval = ({ commit, dispatch, state }, id) => { export const receiveSetLicenseApproval = ({ commit, dispatch, state }, id) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL); commit(types.RESET_LICENSE_IN_MODAL);
dispatch(`${LICENSE_LIST}/fetchLicenses`, null, { root: true });
// If we have the licenses API endpoint, fetch from there. This corresponds // If we have the licenses API endpoint, fetch from there. This corresponds
// to the cases that we're viewing the merge request or pipeline pages. // to the cases that we're viewing the merge request or pipeline pages.
// Otherwise, fetch from the managed licenses endpoint, which corresponds to // Otherwise, fetch from the managed licenses endpoint, which corresponds to
......
...@@ -3,7 +3,6 @@ export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCES ...@@ -3,7 +3,6 @@ export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCES
export const RECEIVE_MANAGED_LICENSES_ERROR = 'RECEIVE_MANAGED_LICENSES_ERROR'; export const RECEIVE_MANAGED_LICENSES_ERROR = 'RECEIVE_MANAGED_LICENSES_ERROR';
export const RECEIVE_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS'; export const RECEIVE_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS';
export const RECEIVE_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_PARSED_LICENSE_REPORT_ERROR'; export const RECEIVE_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_PARSED_LICENSE_REPORT_ERROR';
export const RECEIVE_SET_LICENSE_APPROVAL = 'RECEIVE_SET_LICENSE_APPROVAL';
export const REQUEST_MANAGED_LICENSES = 'REQUEST_MANAGED_LICENSES'; export const REQUEST_MANAGED_LICENSES = 'REQUEST_MANAGED_LICENSES';
export const REQUEST_PARSED_LICENSE_REPORT = 'REQUEST_PARSED_LICENSE_REPORT'; export const REQUEST_PARSED_LICENSE_REPORT = 'REQUEST_PARSED_LICENSE_REPORT';
export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL'; export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL';
......
...@@ -70,11 +70,6 @@ export default { ...@@ -70,11 +70,6 @@ export default {
currentLicenseInModal: null, currentLicenseInModal: null,
}); });
}, },
[types.RECEIVE_SET_LICENSE_APPROVAL](state) {
Object.assign(state, {
currentLicenseInModal: null,
});
},
[types.REQUEST_LICENSE_CHECK_APPROVAL_RULE](state) { [types.REQUEST_LICENSE_CHECK_APPROVAL_RULE](state) {
Object.assign(state, { Object.assign(state, {
isLoadingLicenseCheckApprovalRule: true, isLoadingLicenseCheckApprovalRule: true,
......
...@@ -11,13 +11,6 @@ describe('mediator', () => { ...@@ -11,13 +11,6 @@ describe('mediator', () => {
jest.spyOn(store, 'dispatch').mockImplementation(); jest.spyOn(store, 'dispatch').mockImplementation();
}); });
it('triggers fetching of detected licenses after a license policy is added or edited', () => {
store.commit(
`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_SET_LICENSE_APPROVAL}`,
);
expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`);
});
it('triggers fetching of detected licenses after a license policy is deleted', () => { it('triggers fetching of detected licenses after a license policy is deleted', () => {
store.commit(`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`); store.commit(`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`);
expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`); expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`);
......
...@@ -178,13 +178,16 @@ describe('License store actions', () => { ...@@ -178,13 +178,16 @@ describe('License store actions', () => {
describe('receiveSetLicenseApproval', () => { describe('receiveSetLicenseApproval', () => {
describe('given the licensesApiPath is provided', () => { describe('given the licensesApiPath is provided', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches fetchParsedLicenseReport', (done) => { it('commits RESET_LICENSE_IN_MODAL and dispatches licenseList/fetchLicenses and fetchParsedLicenseReport', (done) => {
testAction( testAction(
actions.receiveSetLicenseApproval, actions.receiveSetLicenseApproval,
null, null,
{ ...state, licensesApiPath }, { ...state, licensesApiPath },
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }], [{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[{ type: 'fetchParsedLicenseReport' }], [
{ type: `licenseList/fetchLicenses`, payload: null },
{ type: 'fetchParsedLicenseReport' },
],
) )
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -192,9 +195,10 @@ describe('License store actions', () => { ...@@ -192,9 +195,10 @@ describe('License store actions', () => {
}); });
describe('given the licensesApiPath is not provided', () => { describe('given the licensesApiPath is not provided', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches fetchManagedLicenses and removePendingLicense', () => { it('commits RESET_LICENSE_IN_MODAL and dispatches licenseList/fetchLicenses, fetchManagedLicenses and removePendingLicense', () => {
return actions.receiveSetLicenseApproval(store, licenseId).then(() => { return actions.receiveSetLicenseApproval(store, licenseId).then(() => {
expect(mockCommit).toHaveBeenCalledWith(mutationTypes.RECEIVE_SET_LICENSE_APPROVAL); expect(mockCommit).toHaveBeenCalledWith(mutationTypes.RESET_LICENSE_IN_MODAL);
expectDispatched('licenseList/fetchLicenses', null, { root: true });
expectDispatched('fetchManagedLicenses'); expectDispatched('fetchManagedLicenses');
expectDispatched('removePendingLicense', licenseId); expectDispatched('removePendingLicense', licenseId);
}); });
......
...@@ -83,21 +83,6 @@ describe('License store mutations', () => { ...@@ -83,21 +83,6 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_SET_LICENSE_APPROVAL', () => {
it('closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
currentLicenseInModal: approvedLicense,
},
});
store.commit(`licenseManagement/${types.RECEIVE_SET_LICENSE_APPROVAL}`);
expect(store.state.licenseManagement.currentLicenseInModal).toBeNull();
});
});
describe('REQUEST_LICENSE_CHECK_APPROVAL_RULE', () => { describe('REQUEST_LICENSE_CHECK_APPROVAL_RULE', () => {
it('sets isLoadingLicenseCheckApprovalRule to true', () => { it('sets isLoadingLicenseCheckApprovalRule to true', () => {
store.replaceState({ 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