Commit 146eef9f authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '37271-remove-parsed-license-report-flag-ee' into 'master'

Remove parsed_license_report feature flag code branches

See merge request gitlab-org/gitlab!24007
parents a1c1f4d0 008a46d6
...@@ -106,20 +106,10 @@ export default { ...@@ -106,20 +106,10 @@ export default {
licensesApiPath, licensesApiPath,
}); });
if (gon.features && gon.features.parsedLicenseReport) { this.loadParsedLicenseReport();
this.loadParsedLicenseReport();
} else {
this.loadLicenseReport();
this.loadManagedLicenses();
}
}, },
methods: { methods: {
...mapActions([ ...mapActions(['setAPISettings', 'loadParsedLicenseReport']),
'setAPISettings',
'loadManagedLicenses',
'loadLicenseReport',
'loadParsedLicenseReport',
]),
}, },
}; };
</script> </script>
......
...@@ -86,56 +86,16 @@ export const loadParsedLicenseReport = ({ dispatch, state }) => { ...@@ -86,56 +86,16 @@ export const loadParsedLicenseReport = ({ dispatch, state }) => {
}); });
}; };
export const requestLoadLicenseReport = ({ commit }) => {
commit(types.REQUEST_LOAD_LICENSE_REPORT);
};
export const receiveLoadLicenseReport = ({ commit }, reports) => {
commit(types.RECEIVE_LOAD_LICENSE_REPORT, reports);
};
export const receiveLoadLicenseReportError = ({ commit }, error) => { export const receiveLoadLicenseReportError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_LICENSE_REPORT_ERROR, error); commit(types.RECEIVE_LOAD_LICENSE_REPORT_ERROR, error);
}; };
export const loadLicenseReport = ({ dispatch, state }) => {
dispatch('requestLoadLicenseReport');
const { headPath, basePath } = state;
const promises = [axios.get(headPath).then(({ data }) => data)];
if (basePath) {
promises.push(
axios
.get(basePath)
.then(({ data }) => data)
.catch(e => {
if (e.response.status === 404) {
return {};
}
throw e;
}),
);
}
return Promise.all(promises)
.then(([headReport, baseReport = {}]) => {
dispatch('receiveLoadLicenseReport', { headReport, baseReport });
})
.catch(error => {
dispatch('receiveLoadLicenseReportError', error);
});
};
export const requestSetLicenseApproval = ({ commit }) => { export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL); commit(types.REQUEST_SET_LICENSE_APPROVAL);
}; };
export const receiveSetLicenseApproval = ({ commit, dispatch }) => { export const receiveSetLicenseApproval = ({ commit, dispatch }) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL); commit(types.RECEIVE_SET_LICENSE_APPROVAL);
if (gon.features && gon.features.parsedLicenseReport) { dispatch('loadParsedLicenseReport');
dispatch('loadParsedLicenseReport');
} else {
dispatch('loadManagedLicenses');
}
}; };
export const receiveSetLicenseApprovalError = ({ commit }, error) => { export const receiveSetLicenseApprovalError = ({ commit }, error) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error); commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error);
......
import { n__, s__, sprintf } from '~/locale'; import { n__, s__, sprintf } from '~/locale';
import { parseLicenseReportMetrics } from './utils';
import { LICENSE_APPROVAL_STATUS } from '../constants'; import { LICENSE_APPROVAL_STATUS } from '../constants';
export const isLoading = state => state.isLoadingManagedLicenses || state.isLoadingLicenseReport; export const isLoading = state => state.isLoadingManagedLicenses || state.isLoadingLicenseReport;
export const licenseReport = state => export const licenseReport = state => state.newLicenses;
gon.features && gon.features.parsedLicenseReport
? state.newLicenses
: parseLicenseReportMetrics(state.headReport, state.baseReport, state.managedLicenses);
export const licenseSummaryText = (state, getters) => { export const licenseSummaryText = (state, getters) => {
const hasReportItems = getters.licenseReport && getters.licenseReport.length; const hasReportItems = getters.licenseReport && getters.licenseReport.length;
const baseReportHasLicenses = const baseReportHasLicenses = state.existingLicenses.length;
state.existingLicenses.length ||
(state.baseReport && state.baseReport.licenses && state.baseReport.licenses.length);
if (getters.isLoading) { if (getters.isLoading) {
return sprintf(s__('ciReport|Loading %{reportName} report'), { return sprintf(s__('ciReport|Loading %{reportName} report'), {
......
export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE'; export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE';
export const RECEIVE_DELETE_LICENSE_ERROR = 'RECEIVE_DELETE_LICENSE_ERROR'; export const RECEIVE_DELETE_LICENSE_ERROR = 'RECEIVE_DELETE_LICENSE_ERROR';
export const RECEIVE_LOAD_LICENSE_REPORT = 'RECEIVE_LOAD_LICENSE_REPORT';
export const RECEIVE_LOAD_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_LICENSE_REPORT_ERROR'; export const RECEIVE_LOAD_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_LICENSE_REPORT_ERROR';
export const RECEIVE_LOAD_MANAGED_LICENSES = 'RECEIVE_LOAD_MANAGED_LICENSES'; export const RECEIVE_LOAD_MANAGED_LICENSES = 'RECEIVE_LOAD_MANAGED_LICENSES';
export const RECEIVE_LOAD_MANAGED_LICENSES_ERROR = 'RECEIVE_LOAD_MANAGED_LICENSES_ERROR'; export const RECEIVE_LOAD_MANAGED_LICENSES_ERROR = 'RECEIVE_LOAD_MANAGED_LICENSES_ERROR';
...@@ -9,7 +8,6 @@ export const RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_PARSED_LIC ...@@ -9,7 +8,6 @@ export const RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_PARSED_LIC
export const RECEIVE_SET_LICENSE_APPROVAL = 'RECEIVE_SET_LICENSE_APPROVAL'; export const RECEIVE_SET_LICENSE_APPROVAL = 'RECEIVE_SET_LICENSE_APPROVAL';
export const RECEIVE_SET_LICENSE_APPROVAL_ERROR = 'RECEIVE_SET_LICENSE_APPROVAL_ERROR'; export const RECEIVE_SET_LICENSE_APPROVAL_ERROR = 'RECEIVE_SET_LICENSE_APPROVAL_ERROR';
export const REQUEST_DELETE_LICENSE = 'REQUEST_DELETE_LICENSE'; export const REQUEST_DELETE_LICENSE = 'REQUEST_DELETE_LICENSE';
export const REQUEST_LOAD_LICENSE_REPORT = 'REQUEST_LOAD_LICENSE_REPORT';
export const REQUEST_LOAD_MANAGED_LICENSES = 'REQUEST_LOAD_MANAGED_LICENSES'; export const REQUEST_LOAD_MANAGED_LICENSES = 'REQUEST_LOAD_MANAGED_LICENSES';
export const REQUEST_LOAD_PARSED_LICENSE_REPORT = 'REQUEST_LOAD_PARSED_LICENSE_REPORT'; export const REQUEST_LOAD_PARSED_LICENSE_REPORT = 'REQUEST_LOAD_PARSED_LICENSE_REPORT';
export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL'; export const REQUEST_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL';
......
...@@ -58,16 +58,6 @@ export default { ...@@ -58,16 +58,6 @@ export default {
}); });
}, },
[types.RECEIVE_LOAD_LICENSE_REPORT](state, reports) {
const { headReport, baseReport } = reports;
Object.assign(state, {
headReport,
baseReport,
isLoadingLicenseReport: false,
loadLicenseReportError: false,
});
},
[types.RECEIVE_LOAD_LICENSE_REPORT_ERROR](state, error) { [types.RECEIVE_LOAD_LICENSE_REPORT_ERROR](state, error) {
Object.assign(state, { Object.assign(state, {
managedLicenses: [], managedLicenses: [],
...@@ -75,11 +65,6 @@ export default { ...@@ -75,11 +65,6 @@ export default {
loadLicenseReportError: error, loadLicenseReportError: error,
}); });
}, },
[types.REQUEST_LOAD_LICENSE_REPORT](state) {
Object.assign(state, {
isLoadingLicenseReport: true,
});
},
[types.RECEIVE_DELETE_LICENSE](state) { [types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, { Object.assign(state, {
......
export default () => ({ export default () => ({
apiUrlManageLicenses: null, apiUrlManageLicenses: null,
licensesApiPath: null, licensesApiPath: null,
basePath: null,
baseReport: null,
canManageLicenses: false, canManageLicenses: false,
currentLicenseInModal: null, currentLicenseInModal: null,
headPath: null,
headReport: null,
isDeleting: false, isDeleting: false,
isLoadingLicenseReport: false, isLoadingLicenseReport: false,
isLoadingManagedLicenses: false, isLoadingManagedLicenses: false,
......
...@@ -5,18 +5,11 @@ import createState from 'ee/vue_shared/license_management/store/state'; ...@@ -5,18 +5,11 @@ import createState from 'ee/vue_shared/license_management/store/state';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'spec/helpers/vuex_action_helper';
import { import { approvedLicense, blacklistedLicense } from 'ee_spec/license_management/mock_data';
approvedLicense,
blacklistedLicense,
licenseHeadIssues,
licenseBaseIssues,
} from 'ee_spec/license_management/mock_data';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
describe('License store actions', () => { describe('License store actions', () => {
const apiUrlManageLicenses = `${TEST_HOST}/licenses/management`; const apiUrlManageLicenses = `${TEST_HOST}/licenses/management`;
const headPath = `${TEST_HOST}/licenses/head`;
const basePath = `${TEST_HOST}/licenses/base`;
let axiosMock; let axiosMock;
let licenseId; let licenseId;
...@@ -27,8 +20,6 @@ describe('License store actions', () => { ...@@ -27,8 +20,6 @@ describe('License store actions', () => {
state = { state = {
...createState(), ...createState(),
apiUrlManageLicenses, apiUrlManageLicenses,
headPath,
basePath,
currentLicenseInModal: approvedLicense, currentLicenseInModal: approvedLicense,
}; };
licenseId = approvedLicense.id; licenseId = approvedLicense.id;
...@@ -40,7 +31,7 @@ describe('License store actions', () => { ...@@ -40,7 +31,7 @@ describe('License store actions', () => {
describe('setAPISettings', () => { describe('setAPISettings', () => {
it('commits SET_API_SETTINGS', done => { it('commits SET_API_SETTINGS', done => {
const payload = { headPath, apiUrlManageLicenses }; const payload = { apiUrlManageLicenses };
testAction( testAction(
actions.setAPISettings, actions.setAPISettings,
payload, payload,
...@@ -186,47 +177,16 @@ describe('License store actions', () => { ...@@ -186,47 +177,16 @@ describe('License store actions', () => {
}); });
describe('receiveSetLicenseApproval', () => { describe('receiveSetLicenseApproval', () => {
gon.features = gon.features || {}; it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadParsedLicenseReport', done => {
const { parsedLicenseReport } = gon.features; testAction(
actions.receiveSetLicenseApproval,
afterEach(() => { null,
gon.features.parsedLicenseReport = parsedLicenseReport; state,
}); [{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadParsedLicenseReport' }],
describe('with the parsedLicenseReport feature flag enabled', () => { )
beforeEach(() => { .then(done)
gon.features.parsedLicenseReport = true; .catch(done.fail);
});
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadParsedLicenseReport', done => {
testAction(
actions.receiveSetLicenseApproval,
null,
state,
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadParsedLicenseReport' }],
)
.then(done)
.catch(done.fail);
});
});
describe('with the parsedLicenseReport feature flag disabled', () => {
beforeEach(() => {
gon.features.parsedLicenseReport = false;
});
it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches loadManagedLicenses', done => {
testAction(
actions.receiveSetLicenseApproval,
null,
state,
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadManagedLicenses' }],
)
.then(done)
.catch(done.fail);
});
}); });
}); });
...@@ -511,35 +471,6 @@ describe('License store actions', () => { ...@@ -511,35 +471,6 @@ describe('License store actions', () => {
}); });
}); });
describe('requestLoadLicenseReport', () => {
it('commits REQUEST_LOAD_LICENSE_REPORT', done => {
testAction(
actions.requestLoadLicenseReport,
null,
state,
[{ type: mutationTypes.REQUEST_LOAD_LICENSE_REPORT }],
[],
)
.then(done)
.catch(done.fail);
});
});
describe('receiveLoadLicenseReport', () => {
it('commits RECEIVE_LOAD_LICENSE_REPORT', done => {
const payload = { headReport: licenseHeadIssues, baseReport: licenseBaseIssues };
testAction(
actions.receiveLoadLicenseReport,
payload,
state,
[{ type: mutationTypes.RECEIVE_LOAD_LICENSE_REPORT, payload }],
[],
)
.then(done)
.catch(done.fail);
});
});
describe('receiveLoadLicenseReportError', () => { describe('receiveLoadLicenseReportError', () => {
it('commits RECEIVE_LOAD_LICENSE_REPORT_ERROR', done => { it('commits RECEIVE_LOAD_LICENSE_REPORT_ERROR', done => {
const error = new Error('Test'); const error = new Error('Test');
...@@ -555,84 +486,6 @@ describe('License store actions', () => { ...@@ -555,84 +486,6 @@ describe('License store actions', () => {
}); });
}); });
describe('loadLicenseReport', () => {
let headMock;
let baseMock;
beforeEach(() => {
headMock = axiosMock.onGet(headPath);
baseMock = axiosMock.onGet(basePath);
});
it('dispatches requestLoadLicenseReport and receiveLoadLicenseReport for successful response', done => {
headMock.replyOnce(() => [200, licenseHeadIssues]);
baseMock.replyOnce(() => [200, licenseBaseIssues]);
const payload = { headReport: licenseHeadIssues, baseReport: licenseBaseIssues };
testAction(
actions.loadLicenseReport,
null,
state,
[],
[{ type: 'requestLoadLicenseReport' }, { type: 'receiveLoadLicenseReport', payload }],
)
.then(done)
.catch(done.fail);
});
it('dispatches requestLoadLicenseReport and receiveLoadLicenseReport for 404 on basePath', done => {
headMock.replyOnce(() => [200, licenseHeadIssues]);
baseMock.replyOnce(() => [404, null]);
const payload = { headReport: licenseHeadIssues, baseReport: {} };
testAction(
actions.loadLicenseReport,
null,
state,
[],
[{ type: 'requestLoadLicenseReport' }, { type: 'receiveLoadLicenseReport', payload }],
)
.then(done)
.catch(done.fail);
});
it('dispatches requestLoadLicenseReport and receiveLoadLicenseReportError for error response on head Path', done => {
headMock.replyOnce(() => [500, '']);
baseMock.replyOnce(() => [200, licenseBaseIssues]);
testAction(
actions.loadLicenseReport,
null,
state,
[],
[
{ type: 'requestLoadLicenseReport' },
{ type: 'receiveLoadLicenseReportError', payload: jasmine.any(Error) },
],
)
.then(done)
.catch(done.fail);
});
it('dispatches requestLoadLicenseReport and receiveLoadLicenseReportError for error response on base Path', done => {
headMock.replyOnce(() => [200, licenseHeadIssues]);
baseMock.replyOnce(() => [500, '']);
testAction(
actions.loadLicenseReport,
null,
state,
[],
[
{ type: 'requestLoadLicenseReport' },
{ type: 'receiveLoadLicenseReportError', payload: jasmine.any(Error) },
],
)
.then(done)
.catch(done.fail);
});
});
describe('requestLoadParsedLicenseReport', () => { describe('requestLoadParsedLicenseReport', () => {
it(`should commit ${mutationTypes.REQUEST_LOAD_PARSED_LICENSE_REPORT}`, done => { it(`should commit ${mutationTypes.REQUEST_LOAD_PARSED_LICENSE_REPORT}`, done => {
testAction( testAction(
......
import createState from 'ee/vue_shared/license_management/store/state'; import createState from 'ee/vue_shared/license_management/store/state';
import * as getters from 'ee/vue_shared/license_management/store/getters'; import * as getters from 'ee/vue_shared/license_management/store/getters';
import { parseLicenseReportMetrics } from 'ee/vue_shared/license_management/store/utils';
import { import { licenseReport as licenseReportMock } from 'ee_spec/license_management/mock_data';
licenseHeadIssues,
licenseBaseIssues,
approvedLicense,
licenseReport as licenseReportMock,
} from 'ee_spec/license_management/mock_data';
describe('getters', () => { describe('getters', () => {
let state; let state;
...@@ -35,48 +29,11 @@ describe('getters', () => { ...@@ -35,48 +29,11 @@ describe('getters', () => {
}); });
describe('licenseReport', () => { describe('licenseReport', () => {
describe('with parsedLicenseReport set to false', () => { it('should return the new licenses from the state', () => {
beforeAll(() => { const newLicenses = { test: 'foo' };
gon.features = gon.features || {}; state = { ...createState(), newLicenses };
gon.features.parsedLicenseReport = false;
});
it('returns empty array, if the reports are empty', () => {
state = { ...createState(), headReport: {}, baseReport: {}, managedLicenses: [] };
expect(getters.licenseReport(state)).toEqual([]);
});
it('returns license report, if the license report is not loading', () => {
state = {
...createState(),
headReport: licenseHeadIssues,
baseReport: licenseBaseIssues,
managedLicenses: [approvedLicense],
};
expect(getters.licenseReport(state)).toEqual(
parseLicenseReportMetrics(licenseHeadIssues, licenseBaseIssues, [approvedLicense]),
);
});
});
describe('with parsedLicenseReport set to true', () => {
beforeAll(() => {
gon.features = gon.features || {};
gon.features.parsedLicenseReport = true;
});
afterAll(() => { expect(getters.licenseReport(state)).toBe(newLicenses);
gon.features.parsedLicenseReport = false;
});
it('should return the new licenses from the state', () => {
const newLicenses = { test: 'foo' };
state = { ...createState(), newLicenses };
expect(getters.licenseReport(state)).toBe(newLicenses);
});
}); });
}); });
...@@ -86,8 +43,8 @@ describe('getters', () => { ...@@ -86,8 +43,8 @@ describe('getters', () => {
state = { state = {
...createState(), ...createState(),
loadLicenseReportError: null, loadLicenseReportError: null,
headReport: licenseHeadIssues, newLicenses: ['foo'],
baseReport: licenseBaseIssues, existingLicenses: ['bar'],
}; };
}); });
...@@ -147,7 +104,7 @@ describe('getters', () => { ...@@ -147,7 +104,7 @@ describe('getters', () => {
describe('when there are no licences on the BASE', () => { describe('when there are no licences on the BASE', () => {
beforeEach(() => { beforeEach(() => {
state = { ...createState(), baseReport: {} }; state = createState();
}); });
it('should be `License Compliance detected no licenses for the source branch only` with no new licences', () => { it('should be `License Compliance detected no licenses for the source branch only` with no new licences', () => {
......
...@@ -3,11 +3,7 @@ import * as types from 'ee/vue_shared/license_management/store/mutation_types'; ...@@ -3,11 +3,7 @@ import * as types from 'ee/vue_shared/license_management/store/mutation_types';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants'; import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { import { approvedLicense } from 'ee_spec/license_management/mock_data';
approvedLicense,
licenseBaseIssues,
licenseHeadIssues,
} from 'ee_spec/license_management/mock_data';
describe('License store mutations', () => { describe('License store mutations', () => {
let store; let store;
...@@ -180,27 +176,6 @@ describe('License store mutations', () => { ...@@ -180,27 +176,6 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_LICENSE_REPORT', () => {
it('sets isLoadingLicenseReport and loadLicenseReportError to false and saves report', () => {
store.replaceState({
...store.state,
headReport: false,
baseReport: false,
isLoadingLicenseReport: true,
loadLicenseReportError: true,
});
const payload = { headReport: licenseHeadIssues, baseReport: licenseBaseIssues };
store.commit(types.RECEIVE_LOAD_LICENSE_REPORT, payload);
expect(store.state.headReport).toEqual(licenseHeadIssues);
expect(store.state.baseReport).toEqual(licenseBaseIssues);
expect(store.state.isLoadingLicenseReport).toBe(false);
expect(store.state.loadLicenseReportError).toBe(false);
});
});
describe('RECEIVE_LOAD_LICENSE_REPORT_ERROR', () => { describe('RECEIVE_LOAD_LICENSE_REPORT_ERROR', () => {
it('sets isLoadingLicenseReport to true and saves the error', () => { it('sets isLoadingLicenseReport to true and saves the error', () => {
const error = new Error('test'); const error = new Error('test');
...@@ -217,19 +192,6 @@ describe('License store mutations', () => { ...@@ -217,19 +192,6 @@ describe('License store mutations', () => {
}); });
}); });
describe('REQUEST_LOAD_LICENSE_REPORT', () => {
it('sets isLoadingLicenseReport to true', () => {
store.replaceState({
...store.state,
isLoadingLicenseReport: true,
});
store.commit(types.REQUEST_LOAD_LICENSE_REPORT);
expect(store.state.isLoadingLicenseReport).toBe(true);
});
});
describe('RECEIVE_LOAD_PARSED_LICENSE_REPORT', () => { describe('RECEIVE_LOAD_PARSED_LICENSE_REPORT', () => {
const newLicenses = []; const newLicenses = [];
const existingLicenses = []; const existingLicenses = [];
......
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