Commit 527a3ebd authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '207443-remove-unused-state-properties' into 'master'

Remove deprecated state properties from license management's store

See merge request gitlab-org/gitlab!72284
parents e0390691 551a4c8b
...@@ -10,7 +10,6 @@ import { licenseManagementModule } from 'ee/vue_shared/license_compliance/store/ ...@@ -10,7 +10,6 @@ import { licenseManagementModule } from 'ee/vue_shared/license_compliance/store/
import modalModule from '~/vuex_shared/modules/modal'; import modalModule from '~/vuex_shared/modules/modal';
import { LICENSE_LIST } from './constants'; import { LICENSE_LIST } from './constants';
import listModule from './modules/list'; import listModule from './modules/list';
import mediator from './plugins/mediator';
import createState from './state'; import createState from './state';
Vue.use(Vuex); Vue.use(Vuex);
...@@ -24,5 +23,4 @@ export default (settings = {}) => ...@@ -24,5 +23,4 @@ export default (settings = {}) =>
[APPROVALS]: approvalsModule(), [APPROVALS]: approvalsModule(),
[APPROVALS_MODAL]: modalModule(), [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_SET_LICENSE_APPROVAL}`:
case `${LICENSE_MANAGEMENT}/${licenseMangementMutationTypes.RECEIVE_DELETE_LICENSE}`:
store.dispatch(`${LICENSE_LIST}/fetchLicenses`);
break;
default:
}
});
};
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';
...@@ -25,21 +26,18 @@ export const resetLicenseInModal = ({ commit }) => { ...@@ -25,21 +26,18 @@ export const resetLicenseInModal = ({ commit }) => {
commit(types.RESET_LICENSE_IN_MODAL); commit(types.RESET_LICENSE_IN_MODAL);
}; };
export const requestDeleteLicense = ({ commit }) => {
commit(types.REQUEST_DELETE_LICENSE);
};
export const receiveDeleteLicense = ({ commit, dispatch }, id) => { 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(() => { return dispatch('fetchManagedLicenses').then(() => {
dispatch('removePendingLicense', id); dispatch('removePendingLicense', id);
}); });
}; };
export const receiveDeleteLicenseError = ({ commit }, error) => { export const receiveDeleteLicenseError = ({ commit }) => {
commit(types.RECEIVE_DELETE_LICENSE_ERROR, error); commit(types.RESET_LICENSE_IN_MODAL);
}; };
export const deleteLicense = ({ dispatch, state }) => { export const deleteLicense = ({ dispatch, state }) => {
const licenseId = state.currentLicenseInModal.id; const licenseId = state.currentLicenseInModal.id;
dispatch('requestDeleteLicense');
dispatch('addPendingLicense', licenseId); dispatch('addPendingLicense', licenseId);
const endpoint = `${state.apiUrlManageLicenses}/${licenseId}`; const endpoint = `${state.apiUrlManageLicenses}/${licenseId}`;
return axios return axios
...@@ -47,8 +45,8 @@ export const deleteLicense = ({ dispatch, state }) => { ...@@ -47,8 +45,8 @@ export const deleteLicense = ({ dispatch, state }) => {
.then(() => { .then(() => {
dispatch('receiveDeleteLicense', licenseId); dispatch('receiveDeleteLicense', licenseId);
}) })
.catch((error) => { .catch(() => {
dispatch('receiveDeleteLicenseError', error); dispatch('receiveDeleteLicenseError');
dispatch('removePendingLicense', licenseId); dispatch('removePendingLicense', licenseId);
}); });
}; };
...@@ -59,8 +57,8 @@ export const requestManagedLicenses = ({ commit }) => { ...@@ -59,8 +57,8 @@ export const requestManagedLicenses = ({ commit }) => {
export const receiveManagedLicensesSuccess = ({ commit }, licenses) => { export const receiveManagedLicensesSuccess = ({ commit }, licenses) => {
commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, licenses); commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, licenses);
}; };
export const receiveManagedLicensesError = ({ commit }, error) => { export const receiveManagedLicensesError = ({ commit }) => {
commit(types.RECEIVE_MANAGED_LICENSES_ERROR, error); commit(types.RECEIVE_MANAGED_LICENSES_ERROR);
}; };
export const fetchManagedLicenses = ({ dispatch, state }) => { export const fetchManagedLicenses = ({ dispatch, state }) => {
dispatch('requestManagedLicenses'); dispatch('requestManagedLicenses');
...@@ -72,8 +70,8 @@ export const fetchManagedLicenses = ({ dispatch, state }) => { ...@@ -72,8 +70,8 @@ export const fetchManagedLicenses = ({ dispatch, state }) => {
.then(({ data }) => { .then(({ data }) => {
dispatch('receiveManagedLicensesSuccess', data); dispatch('receiveManagedLicensesSuccess', data);
}) })
.catch((error) => { .catch(() => {
dispatch('receiveManagedLicensesError', error); dispatch('receiveManagedLicensesError');
}); });
}; };
...@@ -100,11 +98,9 @@ export const fetchParsedLicenseReport = ({ dispatch, state }) => { ...@@ -100,11 +98,9 @@ export const fetchParsedLicenseReport = ({ dispatch, state }) => {
}); });
}; };
export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL);
};
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
...@@ -117,8 +113,8 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }, id) => { ...@@ -117,8 +113,8 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }, id) => {
dispatch('removePendingLicense', id); dispatch('removePendingLicense', id);
}); });
}; };
export const receiveSetLicenseApprovalError = ({ commit }, error) => { export const receiveSetLicenseApprovalError = ({ commit }) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error); commit(types.RESET_LICENSE_IN_MODAL);
}; };
export const fetchLicenseCheckApprovalRule = ({ dispatch, state }) => { export const fetchLicenseCheckApprovalRule = ({ dispatch, state }) => {
...@@ -177,7 +173,6 @@ export const setLicenseApproval = ({ dispatch, state }, payload) => { ...@@ -177,7 +173,6 @@ export const setLicenseApproval = ({ dispatch, state }, payload) => {
const { license, newStatus } = payload; const { license, newStatus } = payload;
const { id, name } = license; const { id, name } = license;
dispatch('requestSetLicenseApproval');
dispatch('addPendingLicense', id); dispatch('addPendingLicense', id);
let request; let request;
...@@ -196,8 +191,8 @@ export const setLicenseApproval = ({ dispatch, state }, payload) => { ...@@ -196,8 +191,8 @@ export const setLicenseApproval = ({ dispatch, state }, payload) => {
.then(() => { .then(() => {
dispatch('receiveSetLicenseApproval', id); dispatch('receiveSetLicenseApproval', id);
}) })
.catch((error) => { .catch(() => {
dispatch('receiveSetLicenseApprovalError', error); dispatch('receiveSetLicenseApprovalError');
dispatch('removePendingLicense', id); dispatch('removePendingLicense', id);
}); });
}; };
......
export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE';
export const RECEIVE_DELETE_LICENSE_ERROR = 'RECEIVE_DELETE_LICENSE_ERROR';
export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCESS'; export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCESS';
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 RECEIVE_SET_LICENSE_APPROVAL_ERROR = 'RECEIVE_SET_LICENSE_APPROVAL_ERROR';
export const REQUEST_DELETE_LICENSE = 'REQUEST_DELETE_LICENSE';
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 REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL';
export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL'; export const RESET_LICENSE_IN_MODAL = 'RESET_LICENSE_IN_MODAL';
export const SET_API_SETTINGS = 'SET_API_SETTINGS'; export const SET_API_SETTINGS = 'SET_API_SETTINGS';
export const SET_LICENSE_IN_MODAL = 'SET_LICENSE_IN_MODAL'; export const SET_LICENSE_IN_MODAL = 'SET_LICENSE_IN_MODAL';
......
...@@ -31,14 +31,12 @@ export default { ...@@ -31,14 +31,12 @@ export default {
Object.assign(state, { Object.assign(state, {
managedLicenses, managedLicenses,
isLoadingManagedLicenses: false, isLoadingManagedLicenses: false,
loadManagedLicensesError: false,
}); });
}, },
[types.RECEIVE_MANAGED_LICENSES_ERROR](state, error) { [types.RECEIVE_MANAGED_LICENSES_ERROR](state) {
Object.assign(state, { Object.assign(state, {
managedLicenses: [], managedLicenses: [],
isLoadingManagedLicenses: false, isLoadingManagedLicenses: false,
loadManagedLicensesError: error,
}); });
}, },
[types.REQUEST_MANAGED_LICENSES](state) { [types.REQUEST_MANAGED_LICENSES](state) {
...@@ -66,41 +64,6 @@ export default { ...@@ -66,41 +64,6 @@ export default {
isLoadingLicenseReport: true, isLoadingLicenseReport: true,
}); });
}, },
[types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, {
isDeleting: false,
currentLicenseInModal: null,
});
},
[types.RECEIVE_DELETE_LICENSE_ERROR](state) {
Object.assign(state, {
isDeleting: false,
currentLicenseInModal: null,
});
},
[types.REQUEST_DELETE_LICENSE](state) {
Object.assign(state, {
isDeleting: true,
});
},
[types.REQUEST_SET_LICENSE_APPROVAL](state) {
Object.assign(state, {
isSaving: true,
});
},
[types.RECEIVE_SET_LICENSE_APPROVAL](state) {
Object.assign(state, {
isSaving: false,
currentLicenseInModal: null,
});
},
[types.RECEIVE_SET_LICENSE_APPROVAL_ERROR](state) {
Object.assign(state, {
isSaving: false,
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,
......
...@@ -5,13 +5,10 @@ export default () => ({ ...@@ -5,13 +5,10 @@ export default () => ({
canManageLicenses: false, canManageLicenses: false,
currentLicenseInModal: null, currentLicenseInModal: null,
isAdmin: false, isAdmin: false,
isDeleting: false,
isLoadingLicenseReport: false, isLoadingLicenseReport: false,
isLoadingManagedLicenses: false, isLoadingManagedLicenses: false,
pendingLicenses: [], pendingLicenses: [],
isSaving: false,
loadLicenseReportError: false, loadLicenseReportError: false,
loadManagedLicensesError: false,
managedLicenses: [], managedLicenses: [],
newLicenses: [], newLicenses: [],
existingLicenses: [], existingLicenses: [],
......
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 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`);
});
});
...@@ -117,24 +117,11 @@ describe('License store actions', () => { ...@@ -117,24 +117,11 @@ describe('License store actions', () => {
}); });
}); });
describe('requestDeleteLicense', () => {
it('commits REQUEST_DELETE_LICENSE', (done) => {
testAction(
actions.requestDeleteLicense,
null,
state,
[{ type: mutationTypes.REQUEST_DELETE_LICENSE }],
[],
)
.then(done)
.catch(done.fail);
});
});
describe('receiveDeleteLicense', () => { 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(() => { 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('fetchManagedLicenses');
expectDispatched('removePendingLicense', licenseId); expectDispatched('removePendingLicense', licenseId);
}); });
...@@ -142,13 +129,12 @@ describe('License store actions', () => { ...@@ -142,13 +129,12 @@ describe('License store actions', () => {
}); });
describe('receiveDeleteLicenseError', () => { describe('receiveDeleteLicenseError', () => {
it('commits RECEIVE_DELETE_LICENSE_ERROR', (done) => { it('commits RESET_LICENSE_IN_MODAL', (done) => {
const error = new Error('Test');
testAction( testAction(
actions.receiveDeleteLicenseError, actions.receiveDeleteLicenseError,
error, null,
state, state,
[{ type: mutationTypes.RECEIVE_DELETE_LICENSE_ERROR, payload: error }], [{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[], [],
) )
.then(done) .then(done)
...@@ -165,57 +151,44 @@ describe('License store actions', () => { ...@@ -165,57 +151,44 @@ describe('License store actions', () => {
endpointMock = axiosMock.onDelete(deleteUrl); endpointMock = axiosMock.onDelete(deleteUrl);
}); });
it('dispatches requestDeleteLicense, addPendingLicense and receiveDeleteLicense for successful response', () => { it('dispatches addPendingLicense and receiveDeleteLicense for successful response', () => {
endpointMock.replyOnce((req) => { endpointMock.replyOnce((req) => {
expect(req.url).toBe(deleteUrl); expect(req.url).toBe(deleteUrl);
return [200, '']; return [200, ''];
}); });
return actions.deleteLicense(store).then(() => { return actions.deleteLicense(store).then(() => {
expectDispatched('requestDeleteLicense');
expectDispatched('addPendingLicense', licenseId); expectDispatched('addPendingLicense', licenseId);
expectDispatched('receiveDeleteLicense', licenseId); expectDispatched('receiveDeleteLicense', licenseId);
}); });
}); });
it('dispatches requestDeleteLicense, addPendingLicense, receiveDeleteLicenseError and removePendingLicense for error response', () => { it('dispatches addPendingLicense, receiveDeleteLicenseError and removePendingLicense for error response', () => {
endpointMock.replyOnce((req) => { endpointMock.replyOnce((req) => {
expect(req.url).toBe(deleteUrl); expect(req.url).toBe(deleteUrl);
return [500, '']; return [500, ''];
}); });
return actions.deleteLicense(store).then(() => { return actions.deleteLicense(store).then(() => {
expectDispatched('requestDeleteLicense');
expectDispatched('addPendingLicense', licenseId); expectDispatched('addPendingLicense', licenseId);
expectDispatched('receiveDeleteLicenseError', expect.any(Error)); expectDispatched('receiveDeleteLicenseError');
expectDispatched('removePendingLicense', licenseId); expectDispatched('removePendingLicense', licenseId);
}); });
}); });
}); });
describe('requestSetLicenseApproval', () => {
it('commits REQUEST_SET_LICENSE_APPROVAL', (done) => {
testAction(
actions.requestSetLicenseApproval,
null,
state,
[{ type: mutationTypes.REQUEST_SET_LICENSE_APPROVAL }],
[],
)
.then(done)
.catch(done.fail);
});
});
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);
...@@ -223,9 +196,10 @@ describe('License store actions', () => { ...@@ -223,9 +196,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);
}); });
...@@ -234,13 +208,12 @@ describe('License store actions', () => { ...@@ -234,13 +208,12 @@ describe('License store actions', () => {
}); });
describe('receiveSetLicenseApprovalError', () => { describe('receiveSetLicenseApprovalError', () => {
it('commits RECEIVE_SET_LICENSE_APPROVAL_ERROR', (done) => { it('commits RESET_LICENSE_IN_MODAL', (done) => {
const error = new Error('Test');
testAction( testAction(
actions.receiveSetLicenseApprovalError, actions.receiveSetLicenseApprovalError,
error, null,
state, state,
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL_ERROR, payload: error }], [{ type: mutationTypes.RESET_LICENSE_IN_MODAL }],
[], [],
) )
.then(done) .then(done)
...@@ -260,7 +233,7 @@ describe('License store actions', () => { ...@@ -260,7 +233,7 @@ describe('License store actions', () => {
putEndpointMock = axiosMock.onPost(apiUrlManageLicenses); putEndpointMock = axiosMock.onPost(apiUrlManageLicenses);
}); });
it('dispatches requestSetLicenseApproval, addPendingLicense and receiveSetLicenseApproval for successful response', () => { it('dispatches addPendingLicense and receiveSetLicenseApproval for successful response', () => {
putEndpointMock.replyOnce((req) => { putEndpointMock.replyOnce((req) => {
const { approval_status, name } = JSON.parse(req.data); const { approval_status, name } = JSON.parse(req.data);
...@@ -271,22 +244,20 @@ describe('License store actions', () => { ...@@ -271,22 +244,20 @@ describe('License store actions', () => {
}); });
return actions.setLicenseApproval(store, { license: newLicense, newStatus }).then(() => { return actions.setLicenseApproval(store, { license: newLicense, newStatus }).then(() => {
expectDispatched('requestSetLicenseApproval');
expectDispatched('addPendingLicense', undefined); expectDispatched('addPendingLicense', undefined);
expectDispatched('receiveSetLicenseApproval', undefined); expectDispatched('receiveSetLicenseApproval', undefined);
}); });
}); });
it('dispatches requestSetLicenseApproval, addPendingLicense, receiveSetLicenseApprovalError and removePendingLicense for error response', () => { it('dispatches addPendingLicense, receiveSetLicenseApprovalError and removePendingLicense for error response', () => {
putEndpointMock.replyOnce((req) => { putEndpointMock.replyOnce((req) => {
expect(req.url).toBe(apiUrlManageLicenses); expect(req.url).toBe(apiUrlManageLicenses);
return [500, '']; return [500, ''];
}); });
return actions.setLicenseApproval(store, { license: newLicense, newStatus }).then(() => { return actions.setLicenseApproval(store, { license: newLicense, newStatus }).then(() => {
expectDispatched('requestSetLicenseApproval');
expectDispatched('addPendingLicense', undefined); expectDispatched('addPendingLicense', undefined);
expectDispatched('receiveSetLicenseApprovalError', expect.any(Error)); expectDispatched('receiveSetLicenseApprovalError');
expectDispatched('removePendingLicense', undefined); expectDispatched('removePendingLicense', undefined);
}); });
}); });
...@@ -301,7 +272,7 @@ describe('License store actions', () => { ...@@ -301,7 +272,7 @@ describe('License store actions', () => {
patchEndpointMock = axiosMock.onPatch(licenseUrl); patchEndpointMock = axiosMock.onPatch(licenseUrl);
}); });
it('dispatches requestSetLicenseApproval, addPendingLicense and receiveSetLicenseApproval for successful response', () => { it('dispatches addPendingLicense and receiveSetLicenseApproval for successful response', () => {
patchEndpointMock.replyOnce((req) => { patchEndpointMock.replyOnce((req) => {
expect(req.url).toBe(licenseUrl); expect(req.url).toBe(licenseUrl);
const { approval_status, name } = JSON.parse(req.data); const { approval_status, name } = JSON.parse(req.data);
...@@ -314,13 +285,12 @@ describe('License store actions', () => { ...@@ -314,13 +285,12 @@ describe('License store actions', () => {
return actions return actions
.setLicenseApproval(store, { license: approvedLicense, newStatus }) .setLicenseApproval(store, { license: approvedLicense, newStatus })
.then(() => { .then(() => {
expectDispatched('requestSetLicenseApproval');
expectDispatched('addPendingLicense', approvedLicense.id); expectDispatched('addPendingLicense', approvedLicense.id);
expectDispatched('receiveSetLicenseApproval', approvedLicense.id); expectDispatched('receiveSetLicenseApproval', approvedLicense.id);
}); });
}); });
it('dispatches requestSetLicenseApproval, addPendingLicense, receiveSetLicenseApprovalError and removePendingLicense for error response', () => { it('dispatches addPendingLicense, receiveSetLicenseApprovalError and removePendingLicense for error response', () => {
patchEndpointMock.replyOnce((req) => { patchEndpointMock.replyOnce((req) => {
expect(req.url).toBe(licenseUrl); expect(req.url).toBe(licenseUrl);
return [500, '']; return [500, ''];
...@@ -329,9 +299,8 @@ describe('License store actions', () => { ...@@ -329,9 +299,8 @@ describe('License store actions', () => {
return actions return actions
.setLicenseApproval(store, { license: approvedLicense, newStatus }) .setLicenseApproval(store, { license: approvedLicense, newStatus })
.then(() => { .then(() => {
expectDispatched('requestSetLicenseApproval');
expectDispatched('addPendingLicense', approvedLicense.id); expectDispatched('addPendingLicense', approvedLicense.id);
expectDispatched('receiveSetLicenseApprovalError', expect.any(Error)); expectDispatched('receiveSetLicenseApprovalError');
expectDispatched('removePendingLicense', approvedLicense.id); expectDispatched('removePendingLicense', approvedLicense.id);
}); });
}); });
...@@ -448,7 +417,7 @@ describe('License store actions', () => { ...@@ -448,7 +417,7 @@ describe('License store actions', () => {
actions.receiveManagedLicensesError, actions.receiveManagedLicensesError,
error, error,
state, state,
[{ type: mutationTypes.RECEIVE_MANAGED_LICENSES_ERROR, payload: error }], [{ type: mutationTypes.RECEIVE_MANAGED_LICENSES_ERROR }],
[], [],
) )
.then(done) .then(done)
...@@ -486,10 +455,7 @@ describe('License store actions', () => { ...@@ -486,10 +455,7 @@ describe('License store actions', () => {
null, null,
state, state,
[], [],
[ [{ type: 'requestManagedLicenses' }, { type: 'receiveManagedLicensesError' }],
{ type: 'requestManagedLicenses' },
{ type: 'receiveManagedLicensesError', payload: expect.any(Error) },
],
) )
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
...@@ -68,100 +68,6 @@ describe('License store mutations', () => { ...@@ -68,100 +68,6 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_DELETE_LICENSE', () => {
it('sets isDeleting to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isDeleting: true,
},
});
store.commit(`licenseManagement/${types.RECEIVE_DELETE_LICENSE}`);
expect(store.state.licenseManagement.isDeleting).toBe(false);
});
});
describe('RECEIVE_DELETE_LICENSE_ERROR', () => {
it('sets isDeleting to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isDeleting: true,
currentLicenseInModal: approvedLicense,
},
});
store.commit(`licenseManagement/${types.RECEIVE_DELETE_LICENSE_ERROR}`);
expect(store.state.licenseManagement.isDeleting).toBe(false);
expect(store.state.licenseManagement.currentLicenseInModal).toBeNull();
});
});
describe('REQUEST_DELETE_LICENSE', () => {
it('sets isDeleting to true', () => {
store.replaceState({
...store.state,
licenseManagement: {
isDeleting: false,
},
});
store.commit(`licenseManagement/${types.REQUEST_DELETE_LICENSE}`);
expect(store.state.licenseManagement.isDeleting).toBe(true);
});
});
describe('RECEIVE_SET_LICENSE_APPROVAL', () => {
it('sets isSaving to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isSaving: true,
},
});
store.commit(`licenseManagement/${types.RECEIVE_SET_LICENSE_APPROVAL}`);
expect(store.state.licenseManagement.isSaving).toBe(false);
});
});
describe('RECEIVE_SET_LICENSE_APPROVAL_ERROR', () => {
it('sets isSaving to false and closes the modal', () => {
store.replaceState({
...store.state,
licenseManagement: {
isSaving: true,
currentLicenseInModal: approvedLicense,
},
});
store.commit(`licenseManagement/${types.RECEIVE_SET_LICENSE_APPROVAL_ERROR}`);
expect(store.state.licenseManagement.isSaving).toBe(false);
expect(store.state.licenseManagement.currentLicenseInModal).toBeNull();
});
});
describe('REQUEST_SET_LICENSE_APPROVAL', () => {
it('sets isSaving to true', () => {
store.replaceState({
...store.state,
licenseManagement: {
isSaving: false,
},
});
store.commit(`licenseManagement/${types.REQUEST_SET_LICENSE_APPROVAL}`);
expect(store.state.licenseManagement.isSaving).toBe(true);
});
});
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({
...@@ -211,13 +117,12 @@ describe('License store mutations', () => { ...@@ -211,13 +117,12 @@ describe('License store mutations', () => {
}); });
describe('RECEIVE_MANAGED_LICENSES_SUCCESS', () => { describe('RECEIVE_MANAGED_LICENSES_SUCCESS', () => {
it('sets isLoadingManagedLicenses and loadManagedLicensesError to false and saves managed licenses', () => { it('sets isLoadingManagedLicenses to false and saves managed licenses', () => {
store.replaceState({ store.replaceState({
...store.state, ...store.state,
licenseManagement: { licenseManagement: {
managedLicenses: false, managedLicenses: false,
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
loadManagedLicensesError: true,
}, },
}); });
...@@ -230,7 +135,6 @@ describe('License store mutations', () => { ...@@ -230,7 +135,6 @@ describe('License store mutations', () => {
]); ]);
expect(store.state.licenseManagement.isLoadingManagedLicenses).toBe(false); expect(store.state.licenseManagement.isLoadingManagedLicenses).toBe(false);
expect(store.state.licenseManagement.loadManagedLicensesError).toBe(false);
}); });
}); });
...@@ -241,14 +145,12 @@ describe('License store mutations', () => { ...@@ -241,14 +145,12 @@ describe('License store mutations', () => {
...store.state, ...store.state,
licenseManagement: { licenseManagement: {
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
loadManagedLicensesError: false,
}, },
}); });
store.commit(`licenseManagement/${types.RECEIVE_MANAGED_LICENSES_ERROR}`, error); store.commit(`licenseManagement/${types.RECEIVE_MANAGED_LICENSES_ERROR}`, error);
expect(store.state.licenseManagement.isLoadingManagedLicenses).toBe(false); expect(store.state.licenseManagement.isLoadingManagedLicenses).toBe(false);
expect(store.state.licenseManagement.loadManagedLicensesError).toBe(error);
}); });
}); });
......
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