Commit 8686325f authored by Phil Hughes's avatar Phil Hughes

Merge branch '37271-normalize-vuex-actions-mutations-ee' into 'master'

Normalize Vuex actions/mutations in License Management

See merge request gitlab-org/gitlab!24471
parents d15aa586 9e7d2ed9
...@@ -37,10 +37,10 @@ export default { ...@@ -37,10 +37,10 @@ export default {
this.setAPISettings({ this.setAPISettings({
apiUrlManageLicenses: this.apiUrl, apiUrlManageLicenses: this.apiUrl,
}); });
this.loadManagedLicenses(); this.fetchManagedLicenses();
}, },
methods: { methods: {
...mapActions(['loadManagedLicenses', 'setAPISettings', 'setLicenseApproval']), ...mapActions(['fetchManagedLicenses', 'setAPISettings', 'setLicenseApproval']),
openAddLicenseForm() { openAddLicenseForm() {
this.formIsOpen = true; this.formIsOpen = true;
}, },
......
...@@ -95,10 +95,10 @@ export default { ...@@ -95,10 +95,10 @@ export default {
licensesApiPath, licensesApiPath,
}); });
this.loadParsedLicenseReport(); this.fetchParsedLicenseReport();
}, },
methods: { methods: {
...mapActions(['setAPISettings', 'loadParsedLicenseReport']), ...mapActions(['setAPISettings', 'fetchParsedLicenseReport']),
}, },
}; };
</script> </script>
......
...@@ -20,7 +20,7 @@ export const requestDeleteLicense = ({ commit }) => { ...@@ -20,7 +20,7 @@ export const requestDeleteLicense = ({ commit }) => {
}; };
export const receiveDeleteLicense = ({ commit, dispatch }) => { export const receiveDeleteLicense = ({ commit, dispatch }) => {
commit(types.RECEIVE_DELETE_LICENSE); commit(types.RECEIVE_DELETE_LICENSE);
dispatch('loadManagedLicenses'); dispatch('fetchManagedLicenses');
}; };
export const receiveDeleteLicenseError = ({ commit }, error) => { export const receiveDeleteLicenseError = ({ commit }, error) => {
commit(types.RECEIVE_DELETE_LICENSE_ERROR, error); commit(types.RECEIVE_DELETE_LICENSE_ERROR, error);
...@@ -39,57 +39,53 @@ export const deleteLicense = ({ dispatch, state }) => { ...@@ -39,57 +39,53 @@ export const deleteLicense = ({ dispatch, state }) => {
}); });
}; };
export const requestLoadManagedLicenses = ({ commit }) => { export const requestManagedLicenses = ({ commit }) => {
commit(types.REQUEST_LOAD_MANAGED_LICENSES); commit(types.REQUEST_MANAGED_LICENSES);
}; };
export const receiveLoadManagedLicenses = ({ commit }, licenses) => { export const receiveManagedLicensesSuccess = ({ commit }, licenses) => {
commit(types.RECEIVE_LOAD_MANAGED_LICENSES, licenses); commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, licenses);
}; };
export const receiveLoadManagedLicensesError = ({ commit }, error) => { export const receiveManagedLicensesError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_MANAGED_LICENSES_ERROR, error); commit(types.RECEIVE_MANAGED_LICENSES_ERROR, error);
}; };
export const loadManagedLicenses = ({ dispatch, state }) => { export const fetchManagedLicenses = ({ dispatch, state }) => {
dispatch('requestLoadManagedLicenses'); dispatch('requestManagedLicenses');
const { apiUrlManageLicenses } = state; const { apiUrlManageLicenses } = state;
return axios return axios
.get(apiUrlManageLicenses, { params: { per_page: 100 } }) .get(apiUrlManageLicenses, { params: { per_page: 100 } })
.then(({ data }) => { .then(({ data }) => {
dispatch('receiveLoadManagedLicenses', data); dispatch('receiveManagedLicensesSuccess', data);
}) })
.catch(error => { .catch(error => {
dispatch('receiveLoadManagedLicensesError', error); dispatch('receiveManagedLicensesError', error);
}); });
}; };
export const requestLoadParsedLicenseReport = ({ commit }) => { export const requestParsedLicenseReport = ({ commit }) => {
commit(types.REQUEST_LOAD_PARSED_LICENSE_REPORT); commit(types.REQUEST_PARSED_LICENSE_REPORT);
}; };
export const receiveLoadParsedLicenseReport = ({ commit }, reports) => { export const receiveParsedLicenseReportSuccess = ({ commit }, reports) => {
commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT, reports); commit(types.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS, reports);
}; };
export const receiveLoadParsedLicenseReportError = ({ commit }, error) => { export const receiveParsedLicenseReportError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR, error); commit(types.RECEIVE_PARSED_LICENSE_REPORT_ERROR, error);
}; };
export const loadParsedLicenseReport = ({ dispatch, state }) => { export const fetchParsedLicenseReport = ({ dispatch, state }) => {
dispatch('requestLoadParsedLicenseReport'); dispatch('requestParsedLicenseReport');
pollUntilComplete(state.licensesApiPath) pollUntilComplete(state.licensesApiPath)
.then(({ data }) => { .then(({ data }) => {
const newLicenses = (data.new_licenses || data).map(convertToOldReportFormat); const newLicenses = (data.new_licenses || data).map(convertToOldReportFormat);
const existingLicenses = (data.existing_licenses || []).map(convertToOldReportFormat); const existingLicenses = (data.existing_licenses || []).map(convertToOldReportFormat);
dispatch('receiveLoadParsedLicenseReport', { newLicenses, existingLicenses }); dispatch('receiveParsedLicenseReportSuccess', { newLicenses, existingLicenses });
}) })
.catch(error => { .catch(error => {
dispatch('receiveLoadLicenseReportError', error); dispatch('receiveParsedLicenseReportError', error);
}); });
}; };
export const receiveLoadLicenseReportError = ({ commit }, error) => {
commit(types.RECEIVE_LOAD_LICENSE_REPORT_ERROR, error);
};
export const requestSetLicenseApproval = ({ commit }) => { export const requestSetLicenseApproval = ({ commit }) => {
commit(types.REQUEST_SET_LICENSE_APPROVAL); commit(types.REQUEST_SET_LICENSE_APPROVAL);
}; };
...@@ -101,9 +97,9 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }) => { ...@@ -101,9 +97,9 @@ export const receiveSetLicenseApproval = ({ commit, dispatch, state }) => {
// the project settings page. // the project settings page.
// https://gitlab.com/gitlab-org/gitlab/issues/201867 // https://gitlab.com/gitlab-org/gitlab/issues/201867
if (state.licensesApiPath) { if (state.licensesApiPath) {
dispatch('loadParsedLicenseReport'); dispatch('fetchParsedLicenseReport');
} else { } else {
dispatch('loadManagedLicenses'); dispatch('fetchManagedLicenses');
} }
}; };
export const receiveSetLicenseApprovalError = ({ commit }, error) => { export const receiveSetLicenseApprovalError = ({ commit }, error) => {
......
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_ERROR = 'RECEIVE_LOAD_LICENSE_REPORT_ERROR'; export const RECEIVE_MANAGED_LICENSES_SUCCESS = 'RECEIVE_MANAGED_LICENSES_SUCCESS';
export const RECEIVE_LOAD_MANAGED_LICENSES = 'RECEIVE_LOAD_MANAGED_LICENSES'; export const RECEIVE_MANAGED_LICENSES_ERROR = 'RECEIVE_MANAGED_LICENSES_ERROR';
export const RECEIVE_LOAD_MANAGED_LICENSES_ERROR = 'RECEIVE_LOAD_MANAGED_LICENSES_ERROR'; export const RECEIVE_PARSED_LICENSE_REPORT_SUCCESS = 'RECEIVE_PARSED_LICENSE_REPORT_SUCCESS';
export const RECEIVE_LOAD_PARSED_LICENSE_REPORT = 'RECEIVE_LOAD_PARSED_LICENSE_REPORT'; export const RECEIVE_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_PARSED_LICENSE_REPORT_ERROR';
export const RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR = 'RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR';
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_MANAGED_LICENSES = 'REQUEST_LOAD_MANAGED_LICENSES'; export const REQUEST_MANAGED_LICENSES = 'REQUEST_MANAGED_LICENSES';
export const REQUEST_LOAD_PARSED_LICENSE_REPORT = 'REQUEST_LOAD_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 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';
......
...@@ -16,7 +16,7 @@ export default { ...@@ -16,7 +16,7 @@ export default {
Object.assign(state, data); Object.assign(state, data);
}, },
[types.RECEIVE_LOAD_MANAGED_LICENSES](state, licenses = []) { [types.RECEIVE_MANAGED_LICENSES_SUCCESS](state, licenses = []) {
const managedLicenses = licenses.map(normalizeLicense).reverse(); const managedLicenses = licenses.map(normalizeLicense).reverse();
Object.assign(state, { Object.assign(state, {
...@@ -25,20 +25,20 @@ export default { ...@@ -25,20 +25,20 @@ export default {
loadManagedLicensesError: false, loadManagedLicensesError: false,
}); });
}, },
[types.RECEIVE_LOAD_MANAGED_LICENSES_ERROR](state, error) { [types.RECEIVE_MANAGED_LICENSES_ERROR](state, error) {
Object.assign(state, { Object.assign(state, {
managedLicenses: [], managedLicenses: [],
isLoadingManagedLicenses: false, isLoadingManagedLicenses: false,
loadManagedLicensesError: error, loadManagedLicensesError: error,
}); });
}, },
[types.REQUEST_LOAD_MANAGED_LICENSES](state) { [types.REQUEST_MANAGED_LICENSES](state) {
Object.assign(state, { Object.assign(state, {
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
}); });
}, },
[types.RECEIVE_LOAD_PARSED_LICENSE_REPORT](state, { newLicenses, existingLicenses }) { [types.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS](state, { newLicenses, existingLicenses }) {
Object.assign(state, { Object.assign(state, {
newLicenses, newLicenses,
existingLicenses, existingLicenses,
...@@ -46,26 +46,18 @@ export default { ...@@ -46,26 +46,18 @@ export default {
loadLicenseReportError: false, loadLicenseReportError: false,
}); });
}, },
[types.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR](state, error) { [types.RECEIVE_PARSED_LICENSE_REPORT_ERROR](state, error) {
Object.assign(state, { Object.assign(state, {
isLoadingLicenseReport: false, isLoadingLicenseReport: false,
loadLicenseReportError: error, loadLicenseReportError: error,
}); });
}, },
[types.REQUEST_LOAD_PARSED_LICENSE_REPORT](state) { [types.REQUEST_PARSED_LICENSE_REPORT](state) {
Object.assign(state, { Object.assign(state, {
isLoadingLicenseReport: true, isLoadingLicenseReport: true,
}); });
}, },
[types.RECEIVE_LOAD_LICENSE_REPORT_ERROR](state, error) {
Object.assign(state, {
managedLicenses: [],
isLoadingLicenseReport: false,
loadLicenseReportError: error,
});
},
[types.RECEIVE_DELETE_LICENSE](state) { [types.RECEIVE_DELETE_LICENSE](state) {
Object.assign(state, { Object.assign(state, {
isDeleting: false, isDeleting: false,
......
...@@ -37,7 +37,7 @@ describe('LicenseManagement', () => { ...@@ -37,7 +37,7 @@ describe('LicenseManagement', () => {
...state, ...state,
}, },
actions: { actions: {
loadManagedLicenses: noop, fetchManagedLicenses: noop,
setAPISettings: noop, setAPISettings: noop,
setLicenseApproval: noop, setLicenseApproval: noop,
...actionMocks, ...actionMocks,
...@@ -111,13 +111,13 @@ describe('LicenseManagement', () => { ...@@ -111,13 +111,13 @@ describe('LicenseManagement', () => {
it('should set api settings after mount and init API calls', () => { it('should set api settings after mount and init API calls', () => {
const setAPISettingsMock = jest.fn(); const setAPISettingsMock = jest.fn();
const loadManagedLicensesMock = jest.fn(); const fetchManagedLicensesMock = jest.fn();
createComponent({ createComponent({
state: { isLoadingManagedLicenses: false }, state: { isLoadingManagedLicenses: false },
actionMocks: { actionMocks: {
setAPISettings: setAPISettingsMock, setAPISettings: setAPISettingsMock,
loadManagedLicenses: loadManagedLicensesMock, fetchManagedLicenses: fetchManagedLicensesMock,
}, },
}); });
...@@ -129,6 +129,6 @@ describe('LicenseManagement', () => { ...@@ -129,6 +129,6 @@ describe('LicenseManagement', () => {
undefined, undefined,
); );
expect(loadManagedLicensesMock).toHaveBeenCalledWith(expect.any(Object), undefined, undefined); expect(fetchManagedLicensesMock).toHaveBeenCalledWith(expect.any(Object), undefined, undefined);
}); });
}); });
...@@ -51,8 +51,8 @@ describe('License Report MR Widget', () => { ...@@ -51,8 +51,8 @@ describe('License Report MR Widget', () => {
const defaultActions = { const defaultActions = {
setAPISettings: () => {}, setAPISettings: () => {},
loadManagedLicenses: () => {}, fetchManagedLicenses: () => {},
loadParsedLicenseReport: () => {}, fetchParsedLicenseReport: () => {},
}; };
const mountComponent = ({ const mountComponent = ({
...@@ -219,7 +219,9 @@ describe('License Report MR Widget', () => { ...@@ -219,7 +219,9 @@ describe('License Report MR Widget', () => {
it('should init store after mount', () => { it('should init store after mount', () => {
const actions = { const actions = {
setAPISettings: jasmine.createSpy('setAPISettings').and.callFake(() => {}), setAPISettings: jasmine.createSpy('setAPISettings').and.callFake(() => {}),
loadParsedLicenseReport: jasmine.createSpy('loadParsedLicenseReport').and.callFake(() => {}), fetchParsedLicenseReport: jasmine
.createSpy('fetchParsedLicenseReport')
.and.callFake(() => {}),
}; };
vm = mountComponent({ actions }); vm = mountComponent({ actions });
...@@ -233,7 +235,7 @@ describe('License Report MR Widget', () => { ...@@ -233,7 +235,7 @@ describe('License Report MR Widget', () => {
undefined, undefined,
); );
expect(actions.loadParsedLicenseReport).toHaveBeenCalledWith( expect(actions.fetchParsedLicenseReport).toHaveBeenCalledWith(
jasmine.any(Object), jasmine.any(Object),
undefined, undefined,
undefined, undefined,
......
...@@ -88,13 +88,13 @@ describe('License store actions', () => { ...@@ -88,13 +88,13 @@ describe('License store actions', () => {
}); });
describe('receiveDeleteLicense', () => { describe('receiveDeleteLicense', () => {
it('commits RECEIVE_DELETE_LICENSE and dispatches loadManagedLicenses', done => { it('commits RECEIVE_DELETE_LICENSE and dispatches fetchManagedLicenses', done => {
testAction( testAction(
actions.receiveDeleteLicense, actions.receiveDeleteLicense,
null, null,
state, state,
[{ type: mutationTypes.RECEIVE_DELETE_LICENSE }], [{ type: mutationTypes.RECEIVE_DELETE_LICENSE }],
[{ type: 'loadManagedLicenses' }], [{ type: 'fetchManagedLicenses' }],
) )
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -179,13 +179,13 @@ describe('License store actions', () => { ...@@ -179,13 +179,13 @@ 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 loadParsedLicenseReport', done => { it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches fetchParsedLicenseReport', done => {
testAction( testAction(
actions.receiveSetLicenseApproval, actions.receiveSetLicenseApproval,
null, null,
{ ...state, licensesApiPath }, { ...state, licensesApiPath },
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }], [{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadParsedLicenseReport' }], [{ type: 'fetchParsedLicenseReport' }],
) )
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -193,13 +193,13 @@ describe('License store actions', () => { ...@@ -193,13 +193,13 @@ 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 loadManagedLicenses', done => { it('commits RECEIVE_SET_LICENSE_APPROVAL and dispatches fetchManagedLicenses', done => {
testAction( testAction(
actions.receiveSetLicenseApproval, actions.receiveSetLicenseApproval,
null, null,
state, state,
[{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }], [{ type: mutationTypes.RECEIVE_SET_LICENSE_APPROVAL }],
[{ type: 'loadManagedLicenses' }], [{ type: 'fetchManagedLicenses' }],
) )
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -404,13 +404,13 @@ describe('License store actions', () => { ...@@ -404,13 +404,13 @@ describe('License store actions', () => {
}); });
}); });
describe('requestLoadManagedLicenses', () => { describe('requestManagedLicenses', () => {
it('commits REQUEST_LOAD_MANAGED_LICENSES', done => { it('commits REQUEST_MANAGED_LICENSES', done => {
testAction( testAction(
actions.requestLoadManagedLicenses, actions.requestManagedLicenses,
null, null,
state, state,
[{ type: mutationTypes.REQUEST_LOAD_MANAGED_LICENSES }], [{ type: mutationTypes.REQUEST_MANAGED_LICENSES }],
[], [],
) )
.then(done) .then(done)
...@@ -418,14 +418,14 @@ describe('License store actions', () => { ...@@ -418,14 +418,14 @@ describe('License store actions', () => {
}); });
}); });
describe('receiveLoadManagedLicenses', () => { describe('receiveManagedLicensesSuccess', () => {
it('commits RECEIVE_LOAD_MANAGED_LICENSES', done => { it('commits RECEIVE_MANAGED_LICENSES_SUCCESS', done => {
const payload = [approvedLicense]; const payload = [approvedLicense];
testAction( testAction(
actions.receiveLoadManagedLicenses, actions.receiveManagedLicensesSuccess,
payload, payload,
state, state,
[{ type: mutationTypes.RECEIVE_LOAD_MANAGED_LICENSES, payload }], [{ type: mutationTypes.RECEIVE_MANAGED_LICENSES_SUCCESS, payload }],
[], [],
) )
.then(done) .then(done)
...@@ -433,14 +433,14 @@ describe('License store actions', () => { ...@@ -433,14 +433,14 @@ describe('License store actions', () => {
}); });
}); });
describe('receiveLoadManagedLicensesError', () => { describe('receiveManagedLicensesError', () => {
it('commits RECEIVE_LOAD_MANAGED_LICENSES_ERROR', done => { it('commits RECEIVE_MANAGED_LICENSES_ERROR', done => {
const error = new Error('Test'); const error = new Error('Test');
testAction( testAction(
actions.receiveLoadManagedLicensesError, actions.receiveManagedLicensesError,
error, error,
state, state,
[{ type: mutationTypes.RECEIVE_LOAD_MANAGED_LICENSES_ERROR, payload: error }], [{ type: mutationTypes.RECEIVE_MANAGED_LICENSES_ERROR, payload: error }],
[], [],
) )
.then(done) .then(done)
...@@ -448,39 +448,39 @@ describe('License store actions', () => { ...@@ -448,39 +448,39 @@ describe('License store actions', () => {
}); });
}); });
describe('loadManagedLicenses', () => { describe('fetchManagedLicenses', () => {
let endpointMock; let endpointMock;
beforeEach(() => { beforeEach(() => {
endpointMock = axiosMock.onGet(apiUrlManageLicenses, { params: { per_page: 100 } }); endpointMock = axiosMock.onGet(apiUrlManageLicenses, { params: { per_page: 100 } });
}); });
it('dispatches requestLoadManagedLicenses and receiveLoadManagedLicenses for successful response', done => { it('dispatches requestManagedLicenses and receiveManagedLicensesSuccess for successful response', done => {
const payload = [{ name: 'foo', approval_status: LICENSE_APPROVAL_STATUS.BLACKLISTED }]; const payload = [{ name: 'foo', approval_status: LICENSE_APPROVAL_STATUS.BLACKLISTED }];
endpointMock.replyOnce(() => [200, payload]); endpointMock.replyOnce(() => [200, payload]);
testAction( testAction(
actions.loadManagedLicenses, actions.fetchManagedLicenses,
null, null,
state, state,
[], [],
[{ type: 'requestLoadManagedLicenses' }, { type: 'receiveLoadManagedLicenses', payload }], [{ type: 'requestManagedLicenses' }, { type: 'receiveManagedLicensesSuccess', payload }],
) )
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
it('dispatches requestLoadManagedLicenses and receiveLoadManagedLicensesError for error response', done => { it('dispatches requestManagedLicenses and receiveManagedLicensesError for error response', done => {
endpointMock.replyOnce(() => [500, '']); endpointMock.replyOnce(() => [500, '']);
testAction( testAction(
actions.loadManagedLicenses, actions.fetchManagedLicenses,
null, null,
state, state,
[], [],
[ [
{ type: 'requestLoadManagedLicenses' }, { type: 'requestManagedLicenses' },
{ type: 'receiveLoadManagedLicensesError', payload: jasmine.any(Error) }, { type: 'receiveManagedLicensesError', payload: jasmine.any(Error) },
], ],
) )
.then(done) .then(done)
...@@ -488,28 +488,13 @@ describe('License store actions', () => { ...@@ -488,28 +488,13 @@ describe('License store actions', () => {
}); });
}); });
describe('receiveLoadLicenseReportError', () => { describe('requestParsedLicenseReport', () => {
it('commits RECEIVE_LOAD_LICENSE_REPORT_ERROR', done => { it(`should commit ${mutationTypes.REQUEST_PARSED_LICENSE_REPORT}`, done => {
const error = new Error('Test');
testAction(
actions.receiveLoadLicenseReportError,
error,
state,
[{ type: mutationTypes.RECEIVE_LOAD_LICENSE_REPORT_ERROR, payload: error }],
[],
)
.then(done)
.catch(done.fail);
});
});
describe('requestLoadParsedLicenseReport', () => {
it(`should commit ${mutationTypes.REQUEST_LOAD_PARSED_LICENSE_REPORT}`, done => {
testAction( testAction(
actions.requestLoadParsedLicenseReport, actions.requestParsedLicenseReport,
null, null,
state, state,
[{ type: mutationTypes.REQUEST_LOAD_PARSED_LICENSE_REPORT }], [{ type: mutationTypes.REQUEST_PARSED_LICENSE_REPORT }],
[], [],
) )
.then(done) .then(done)
...@@ -517,15 +502,15 @@ describe('License store actions', () => { ...@@ -517,15 +502,15 @@ describe('License store actions', () => {
}); });
}); });
describe('receiveLoadParsedLicenseReport', () => { describe('receiveParsedLicenseReportSuccess', () => {
it(`should commit ${mutationTypes.RECEIVE_LOAD_PARSED_LICENSE_REPORT} with the correct payload`, done => { it(`should commit ${mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS} with the correct payload`, done => {
const payload = { newLicenses: [{ name: 'foo' }] }; const payload = { newLicenses: [{ name: 'foo' }] };
testAction( testAction(
actions.receiveLoadParsedLicenseReport, actions.receiveParsedLicenseReportSuccess,
payload, payload,
state, state,
[{ type: mutationTypes.RECEIVE_LOAD_PARSED_LICENSE_REPORT, payload }], [{ type: mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS, payload }],
[], [],
) )
.then(done) .then(done)
...@@ -533,15 +518,15 @@ describe('License store actions', () => { ...@@ -533,15 +518,15 @@ describe('License store actions', () => {
}); });
}); });
describe('receiveLoadParsedLicenseReportError', () => { describe('receiveParsedLicenseReportError', () => {
it(`should commit ${mutationTypes.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR}`, done => { it(`should commit ${mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_ERROR}`, done => {
const payload = new Error('Test'); const payload = new Error('Test');
testAction( testAction(
actions.receiveLoadParsedLicenseReportError, actions.receiveParsedLicenseReportError,
payload, payload,
state, state,
[{ type: mutationTypes.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR, payload }], [{ type: mutationTypes.RECEIVE_PARSED_LICENSE_REPORT_ERROR, payload }],
[], [],
) )
.then(done) .then(done)
...@@ -549,7 +534,7 @@ describe('License store actions', () => { ...@@ -549,7 +534,7 @@ describe('License store actions', () => {
}); });
}); });
describe('loadParsedLicenseReport', () => { describe('fetchParsedLicenseReport', () => {
let licensesApiMock; let licensesApiMock;
let rawLicenseReport; let rawLicenseReport;
...@@ -591,13 +576,13 @@ describe('License store actions', () => { ...@@ -591,13 +576,13 @@ describe('License store actions', () => {
}; };
testAction( testAction(
actions.loadParsedLicenseReport, actions.fetchParsedLicenseReport,
null, null,
state, state,
[], [],
[ [
{ type: 'requestLoadParsedLicenseReport' }, { type: 'requestParsedLicenseReport' },
{ type: 'receiveLoadParsedLicenseReport', payload: parsedLicenses }, { type: 'receiveParsedLicenseReportSuccess', payload: parsedLicenses },
], ],
) )
.then(done) .then(done)
...@@ -608,13 +593,13 @@ describe('License store actions', () => { ...@@ -608,13 +593,13 @@ describe('License store actions', () => {
licensesApiMock.replyOnce(400); licensesApiMock.replyOnce(400);
testAction( testAction(
actions.loadParsedLicenseReport, actions.fetchParsedLicenseReport,
null, null,
state, state,
[], [],
[ [
{ type: 'requestLoadParsedLicenseReport' }, { type: 'requestParsedLicenseReport' },
{ type: 'receiveLoadLicenseReportError', payload: jasmine.any(Error) }, { type: 'receiveParsedLicenseReportError', payload: jasmine.any(Error) },
], ],
) )
.then(done) .then(done)
...@@ -686,13 +671,13 @@ describe('License store actions', () => { ...@@ -686,13 +671,13 @@ describe('License store actions', () => {
}; };
testAction( testAction(
actions.loadParsedLicenseReport, actions.fetchParsedLicenseReport,
null, null,
state, state,
[], [],
[ [
{ type: 'requestLoadParsedLicenseReport' }, { type: 'requestParsedLicenseReport' },
{ type: 'receiveLoadParsedLicenseReport', payload: parsedLicenses }, { type: 'receiveParsedLicenseReportSuccess', payload: parsedLicenses },
], ],
) )
.then(done) .then(done)
......
...@@ -125,7 +125,7 @@ describe('License store mutations', () => { ...@@ -125,7 +125,7 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_MANAGED_LICENSES', () => { describe('RECEIVE_MANAGED_LICENSES_SUCCESS', () => {
it('sets isLoadingManagedLicenses and loadManagedLicensesError to false and saves managed licenses', () => { it('sets isLoadingManagedLicenses and loadManagedLicensesError to false and saves managed licenses', () => {
store.replaceState({ store.replaceState({
...store.state, ...store.state,
...@@ -134,7 +134,7 @@ describe('License store mutations', () => { ...@@ -134,7 +134,7 @@ describe('License store mutations', () => {
loadManagedLicensesError: true, loadManagedLicensesError: true,
}); });
store.commit(types.RECEIVE_LOAD_MANAGED_LICENSES, [ store.commit(types.RECEIVE_MANAGED_LICENSES_SUCCESS, [
{ name: 'Foo', approval_status: LICENSE_APPROVAL_STATUS.approved }, { name: 'Foo', approval_status: LICENSE_APPROVAL_STATUS.approved },
]); ]);
...@@ -147,7 +147,7 @@ describe('License store mutations', () => { ...@@ -147,7 +147,7 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_MANAGED_LICENSES_ERROR', () => { describe('RECEIVE_MANAGED_LICENSES_ERROR', () => {
it('sets isLoadingManagedLicenses to true and saves the error', () => { it('sets isLoadingManagedLicenses to true and saves the error', () => {
const error = new Error('test'); const error = new Error('test');
store.replaceState({ store.replaceState({
...@@ -156,50 +156,34 @@ describe('License store mutations', () => { ...@@ -156,50 +156,34 @@ describe('License store mutations', () => {
loadManagedLicensesError: false, loadManagedLicensesError: false,
}); });
store.commit(types.RECEIVE_LOAD_MANAGED_LICENSES_ERROR, error); store.commit(types.RECEIVE_MANAGED_LICENSES_ERROR, error);
expect(store.state.isLoadingManagedLicenses).toBe(false); expect(store.state.isLoadingManagedLicenses).toBe(false);
expect(store.state.loadManagedLicensesError).toBe(error); expect(store.state.loadManagedLicensesError).toBe(error);
}); });
}); });
describe('REQUEST_LOAD_MANAGED_LICENSES', () => { describe('REQUEST_MANAGED_LICENSES', () => {
it('sets isLoadingManagedLicenses to true', () => { it('sets isLoadingManagedLicenses to true', () => {
store.replaceState({ store.replaceState({
...store.state, ...store.state,
isLoadingManagedLicenses: true, isLoadingManagedLicenses: true,
}); });
store.commit(types.REQUEST_LOAD_MANAGED_LICENSES); store.commit(types.REQUEST_MANAGED_LICENSES);
expect(store.state.isLoadingManagedLicenses).toBe(true); expect(store.state.isLoadingManagedLicenses).toBe(true);
}); });
}); });
describe('RECEIVE_LOAD_LICENSE_REPORT_ERROR', () => { describe('RECEIVE_PARSED_LICENSE_REPORT_SUCCESS', () => {
it('sets isLoadingLicenseReport to true and saves the error', () => {
const error = new Error('test');
store.replaceState({
...store.state,
isLoadingLicenseReport: true,
loadLicenseReportError: false,
});
store.commit(types.RECEIVE_LOAD_LICENSE_REPORT_ERROR, error);
expect(store.state.isLoadingLicenseReport).toBe(false);
expect(store.state.loadLicenseReportError).toBe(error);
});
});
describe('RECEIVE_LOAD_PARSED_LICENSE_REPORT', () => {
const newLicenses = []; const newLicenses = [];
const existingLicenses = []; const existingLicenses = [];
beforeEach(() => { beforeEach(() => {
store.state.isLoadingLicenseReport = true; store.state.isLoadingLicenseReport = true;
store.state.loadLicenseReportError = new Error('test'); store.state.loadLicenseReportError = new Error('test');
store.commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT, { newLicenses, existingLicenses }); store.commit(types.RECEIVE_PARSED_LICENSE_REPORT_SUCCESS, { newLicenses, existingLicenses });
}); });
it('should set the new and existing reports', () => { it('should set the new and existing reports', () => {
...@@ -213,12 +197,12 @@ describe('License store mutations', () => { ...@@ -213,12 +197,12 @@ describe('License store mutations', () => {
}); });
}); });
describe('RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR', () => { describe('RECEIVE_PARSED_LICENSE_REPORT_ERROR', () => {
const error = new Error('test'); const error = new Error('test');
beforeEach(() => { beforeEach(() => {
store.state.isLoadingLicenseReport = true; store.state.isLoadingLicenseReport = true;
store.state.loadLicenseReportError = false; store.state.loadLicenseReportError = false;
store.commit(types.RECEIVE_LOAD_PARSED_LICENSE_REPORT_ERROR, error); store.commit(types.RECEIVE_PARSED_LICENSE_REPORT_ERROR, error);
}); });
it('should set the error on the state', () => { it('should set the error on the state', () => {
...@@ -230,10 +214,10 @@ describe('License store mutations', () => { ...@@ -230,10 +214,10 @@ describe('License store mutations', () => {
}); });
}); });
describe('REQUEST_LOAD_PARSED_LICENSE_REPORT', () => { describe('REQUEST_PARSED_LICENSE_REPORT', () => {
beforeEach(() => { beforeEach(() => {
store.state.isLoadingLicenseReport = false; store.state.isLoadingLicenseReport = false;
store.commit(types.REQUEST_LOAD_PARSED_LICENSE_REPORT); store.commit(types.REQUEST_PARSED_LICENSE_REPORT);
}); });
it('should initiate loading', () => { it('should initiate loading', () => {
......
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