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';
export default (store) => {
store.subscribe(({ type }) => {
switch (type) {
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_SET_LICENSE_APPROVAL}`:
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`:
store.dispatch(`${LICENSE_LIST}/fetchLicenses`);
break;
......
import { LICENSE_CHECK_NAME } from 'ee/approvals/constants';
import axios from '~/lib/utils/axios_utils';
import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { LICENSE_LIST } from 'ee/license_compliance/store/constants';
import { LICENSE_APPROVAL_STATUS } from '../constants';
import * as types from './mutation_types';
import { convertToOldReportFormat } from './utils';
......@@ -97,7 +98,8 @@ export const fetchParsedLicenseReport = ({ dispatch, state }) => {
};
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
// to the cases that we're viewing the merge request or pipeline pages.
// Otherwise, fetch from the managed licenses endpoint, which corresponds to
......
......@@ -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_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS';
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_PARSED_LICENSE_REPORT = 'REQUEST_PARSED_LICENSE_REPORT';
export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL';
......
......@@ -70,11 +70,6 @@ export default {
currentLicenseInModal: null,
});
},
[types.RECEIVE_SET_LICENSE_APPROVAL](state) {
Object.assign(state, {
currentLicenseInModal: null,
});
},
[types.REQUEST_LICENSE_CHECK_APPROVAL_RULE](state) {
Object.assign(state, {
isLoadingLicenseCheckApprovalRule: true,
......
......@@ -11,13 +11,6 @@ describe('mediator', () => {
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', () => {
store.commit(`${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`);
expect(store.dispatch).toHaveBeenCalledWith(`${LICENSE_LIST}/fetchLicenses`);
......
......@@ -178,13 +178,16 @@ describe('License store actions', () => {
describe('receiveSetLicenseApproval', () => {
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(
actions.receiveSetLicenseApproval,
null,
{ ...state, licensesApiPath },
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'fetchParsedLicenseReport' }],
[{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[
{ type: `licenseList/fetchLicenses`, payload: null },
{ type: 'fetchParsedLicenseReport' },
],
)
.then(done)
.catch(done.fail);
......@@ -192,9 +195,10 @@ describe('License store actions', () => {
});
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(() => {
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('removePendingLicense', licenseId);
});
......
......@@ -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', () => {
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