Commit e238ceee authored by Fernando's avatar Fernando

Rework call to fetchLicenseCheckApprovalRule action

* Always call whe component mounted
* When approvalsApiPath not provided dispatch error from within action
parent 9d6f4599
......@@ -109,14 +109,7 @@ export default {
});
this.fetchParsedLicenseReport();
/*
If we render this widget from the "License" tab in the pipeline view,
then we don't fetch the approvals since we aren't in the Merge request context.
*/
if (approvalsApiPath) {
this.fetchLicenseCheckApprovalRule();
}
},
methods: {
...mapActions(LICENSE_MANAGEMENT, [
......
......@@ -115,6 +115,15 @@ export const receiveSetLicenseApprovalError = ({ commit }, error) => {
export const fetchLicenseCheckApprovalRule = ({ dispatch, state }) => {
dispatch('requestLicenseCheckApprovalRule');
/*
If we call this action from the "License" tab in the pipeline view,
then we don't fetch the approvals since we aren't in the Merge request context.
Pipelines cannot have approval rules.
*/
if (!state.approvalsApiPath) {
return dispatch('receiveLicenseCheckApprovalRuleError');
}
return axios
.get(state.approvalsApiPath)
.then(({ data }) => {
......
......@@ -339,11 +339,10 @@ describe('License Report MR Widget', () => {
expect(wrapper.find('#modal-set-license-approval')).not.toBeNull();
});
describe('with approvalsApiPath prop set', () => {
it('should init store after mount calling fetchLicenseCheckApprovalRule', () => {
it('should init store after mount', () => {
const actions = {
...defaultActions,
setAPISettings: jest.fn(),
fetchParsedLicenseReport: jest.fn(),
fetchLicenseCheckApprovalRule: jest.fn(),
};
mountComponent({ actions });
......@@ -359,63 +358,13 @@ describe('License Report MR Widget', () => {
undefined,
);
expect(actions.fetchLicenseCheckApprovalRule).toHaveBeenCalledWith(
expect.any(Object),
undefined,
undefined,
);
});
});
describe('with approvalsApiPath prop unset', () => {
it('should init store after mount without calling fetchLicenseCheckApprovalRule', () => {
const props = {
...defaultProps,
approvalsApiPath: '',
};
const actions = {
...defaultActions,
setAPISettings: jest.fn(),
fetchLicenseCheckApprovalRule: jest.fn(),
};
mountComponent({ actions, props });
expect(actions.setAPISettings).toHaveBeenCalledWith(
expect(actions.fetchParsedLicenseReport).toHaveBeenCalledWith(
expect.any(Object),
{
apiUrlManageLicenses: apiUrl,
licensesApiPath: defaultProps.licensesApiPath,
canManageLicenses: true,
approvalsApiPath: '',
},
undefined,
);
expect(actions.fetchLicenseCheckApprovalRule).not.toHaveBeenCalled();
});
});
it('should init store after mount', () => {
const actions = {
setAPISettings: jest.fn(),
fetchParsedLicenseReport: jest.fn(),
fetchLicenseCheckApprovalRule: jest.fn(),
};
mountComponent({ actions });
expect(actions.setAPISettings).toHaveBeenCalledWith(
expect.any(Object),
{
apiUrlManageLicenses: apiUrl,
licensesApiPath: defaultProps.licensesApiPath,
approvalsApiPath: defaultProps.approvalsApiPath,
canManageLicenses: true,
},
undefined,
);
expect(actions.fetchParsedLicenseReport).toHaveBeenCalledWith(
expect(actions.fetchLicenseCheckApprovalRule).toHaveBeenCalledWith(
expect.any(Object),
undefined,
undefined,
......
......@@ -534,6 +534,23 @@ describe('License store actions', () => {
const error = new Error('Request failed with status code 500');
axiosMock.onGet(approvalsApiPath).replyOnce(500);
testAction(
actions.fetchLicenseCheckApprovalRule,
null,
{ ...state, approvalsApiPath: '' },
[],
[
{ type: 'requestLicenseCheckApprovalRule' },
{ type: 'receiveLicenseCheckApprovalRuleError', payload: error },
],
done,
);
});
it('dispatches request/receive error when no approvalsAPiPath is provided', done => {
const error = new Error('Request failed with status code 500');
axiosMock.onGet(approvalsApiPath).replyOnce(500);
testAction(
actions.fetchLicenseCheckApprovalRule,
null,
......
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