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