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 {
licensesApiPath,
});
if (gon.features && gon.features.parsedLicenseReport) {
this.loadParsedLicenseReport();
} else {
this.loadLicenseReport();
this.loadManagedLicenses();
}
this.loadParsedLicenseReport();
},
methods: {
...mapActions([
'setAPISettings',
'loadManagedLicenses',
'loadLicenseReport',
'loadParsedLicenseReport',
]),
...mapActions(['setAPISettings', 'loadParsedLicenseReport']),
},
};
</script>
......
......@@ -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) => {
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 }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL);
};
export const receiveSetLicenseApproval = ({ commit, dispatch }) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL);
if (gon.features && gon.features.parsedLicenseReport) {
dispatch('loadParsedLicenseReport');
} else {
dispatch('loadManagedLicenses');
}
dispatch('loadParsedLicenseReport');
};
export const receiveSetLicenseApprovalError = ({ commit }, error) => {
commit(types.RECEIVE_SET_LICENSE_APPROVAL_ERROR, error);
......
import { n__, s__, sprintf } from '~/locale';
import { parseLicenseReportMetrics } from './utils';
import { LICENSE_APPROVAL_STATUS } from '../constants';
export const isLoading = state => state.isLoadingManagedLicenses || state.isLoadingLicenseReport;
export const licenseReport = state =>
gon.features && gon.features.parsedLicenseReport
? state.newLicenses
: parseLicenseReportMetrics(state.headReport, state.baseReport, state.managedLicenses);
export const licenseReport = state => state.newLicenses;
export const licenseSummaryText = (state, getters) => {
const hasReportItems = getters.licenseReport && getters.licenseReport.length;
const baseReportHasLicenses =
state.existingLicenses.length ||
(state.baseReport && state.baseReport.licenses && state.baseReport.licenses.length);
const baseReportHasLicenses = state.existingLicenses.length;
if (getters.isLoading) {
return sprintf(s__('ciReport|Loading %{reportName} report'), {
......
export const RECEIVE_DELETE_LICENSE = 'RECEIVE_DELETE_LICENSE';
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_MANAGED_LICENSES = 'RECEIVE_LOAD_MANAGED_LICENSES';
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
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_LOAD_LICENSE_REPORT = 'REQUEST_LOAD_LICENSE_REPORT';
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_SET_LICENSE_APPROVAL = 'REQUEST_SET_LICENSE_APPROVAL';
......
......@@ -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) {
Object.assign(state, {
managedLicenses: [],
......@@ -75,11 +65,6 @@ export default {
loadLicenseReportError: error,
});
},
[types.REQUEST_LOAD_LICENSE_REPORT](state) {
Object.assign(state, {
isLoadingLicenseReport: true,
});
},
[types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, {
......
export default () => ({
apiUrlManageLicenses: null,
licensesApiPath: null,
basePath: null,
baseReport: null,
canManageLicenses: false,
currentLicenseInModal: null,
headPath: null,
headReport: null,
isDeleting: false,
isLoadingLicenseReport: false,
isLoadingManagedLicenses: false,
......
......@@ -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 { TEST_HOST } from 'spec/test_constants';
import testAction from 'spec/helpers/vuex_action_helper';
import {
approvedLicense,
blacklistedLicense,
licenseHeadIssues,
licenseBaseIssues,
} from 'ee_spec/license_management/mock_data';
import { approvedLicense, blacklistedLicense } from 'ee_spec/license_management/mock_data';
import axios from '~/lib/utils/axios_utils';
describe('License store actions', () => {
const apiUrlManageLicenses = `${TEST_HOST}/licenses/management`;
const headPath = `${TEST_HOST}/licenses/head`;
const basePath = `${TEST_HOST}/licenses/base`;
let axiosMock;
let licenseId;
......@@ -27,8 +20,6 @@ describe('License store actions', () => {
state = {
...createState(),
apiUrlManageLicenses,
headPath,
basePath,
currentLicenseInModal: approvedLicense,
};
licenseId = approvedLicense.id;
......@@ -40,7 +31,7 @@ describe('License store actions', () => {
describe('setAPISettings', () => {
it('commits SET_API_SETTINGS', done => {
const payload = { headPath, apiUrlManageLicenses };
const payload = { apiUrlManageLicenses };
testAction(
actions.setAPISettings,
payload,
......@@ -186,47 +177,16 @@ describe('License store actions', () => {
});
describe('receiveSetLicenseApproval', () => {
gon.features = gon.features || {};
const { parsedLicenseReport } = gon.features;
afterEach(() => {
gon.features.parsedLicenseReport = parsedLicenseReport;
});
describe('with the parsedLicenseReport feature flag enabled', () => {
beforeEach(() => {
gon.features.parsedLicenseReport = true;
});
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);
});
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);
});
});
......@@ -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', () => {
it('commits RECEIVE_LOAD_LICENSE_REPORT_ERROR', done => {
const error = new Error('Test');
......@@ -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', () => {
it(`should commit ${mutationTypes.REQUEST_LOAD_PARSED_LICENSE_REPORT}`, done => {
testAction(
......
import createState from 'ee/vue_shared/license_management/store/state';
import * as getters from 'ee/vue_shared/license_management/store/getters';
import { parseLicenseReportMetrics } from 'ee/vue_shared/license_management/store/utils';
import {
licenseHeadIssues,
licenseBaseIssues,
approvedLicense,
licenseReport as licenseReportMock,
} from 'ee_spec/license_management/mock_data';
import { licenseReport as licenseReportMock } from 'ee_spec/license_management/mock_data';
describe('getters', () => {
let state;
......@@ -35,48 +29,11 @@ describe('getters', () => {
});
describe('licenseReport', () => {
describe('with parsedLicenseReport set to false', () => {
beforeAll(() => {
gon.features = gon.features || {};
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;
});
it('should return the new licenses from the state', () => {
const newLicenses = { test: 'foo' };
state = { ...createState(), newLicenses };
afterAll(() => {
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);
});
expect(getters.licenseReport(state)).toBe(newLicenses);
});
});
......@@ -86,8 +43,8 @@ describe('getters', () => {
state = {
...createState(),
loadLicenseReportError: null,
headReport: licenseHeadIssues,
baseReport: licenseBaseIssues,
newLicenses: ['foo'],
existingLicenses: ['bar'],
};
});
......@@ -147,7 +104,7 @@ describe('getters', () => {
describe('when there are no licences on the BASE', () => {
beforeEach(() => {
state = { ...createState(), baseReport: {} };
state = createState();
});
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';
import { LICENSE_APPROVAL_STATUS } from 'ee/vue_shared/license_management/constants';
import { TEST_HOST } from 'spec/test_constants';
import {
approvedLicense,
licenseBaseIssues,
licenseHeadIssues,
} from 'ee_spec/license_management/mock_data';
import { approvedLicense } from 'ee_spec/license_management/mock_data';
describe('License store mutations', () => {
let store;
......@@ -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', () => {
it('sets isLoadingLicenseReport to true and saves the error', () => {
const error = new Error('test');
......@@ -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', () => {
const newLicenses = [];
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