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 { ...@@ -109,14 +109,7 @@ export default {
}); });
this.fetchParsedLicenseReport(); this.fetchParsedLicenseReport();
this.fetchLicenseCheckApprovalRule();
/*
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: { methods: {
...mapActions(LICENSE_MANAGEMENT, [ ...mapActions(LICENSE_MANAGEMENT, [
......
...@@ -115,6 +115,15 @@ export const receiveSetLicenseApprovalError = ({ commit }, error) => { ...@@ -115,6 +115,15 @@ export const receiveSetLicenseApprovalError = ({ commit }, error) => {
export const fetchLicenseCheckApprovalRule = ({ dispatch, state }) => { export const fetchLicenseCheckApprovalRule = ({ dispatch, state }) => {
dispatch('requestLicenseCheckApprovalRule'); 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 return axios
.get(state.approvalsApiPath) .get(state.approvalsApiPath)
.then(({ data }) => { .then(({ data }) => {
......
...@@ -339,63 +339,6 @@ describe('License Report MR Widget', () => { ...@@ -339,63 +339,6 @@ describe('License Report MR Widget', () => {
expect(wrapper.find('#modal-set-license-approval')).not.toBeNull(); expect(wrapper.find('#modal-set-license-approval')).not.toBeNull();
}); });
describe('with approvalsApiPath prop set', () => {
it('should init store after mount calling fetchLicenseCheckApprovalRule', () => {
const actions = {
...defaultActions,
setAPISettings: 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.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.any(Object),
{
apiUrlManageLicenses: apiUrl,
licensesApiPath: defaultProps.licensesApiPath,
canManageLicenses: true,
approvalsApiPath: '',
},
undefined,
);
expect(actions.fetchLicenseCheckApprovalRule).not.toHaveBeenCalled();
});
});
it('should init store after mount', () => { it('should init store after mount', () => {
const actions = { const actions = {
setAPISettings: jest.fn(), setAPISettings: jest.fn(),
...@@ -420,6 +363,12 @@ describe('License Report MR Widget', () => { ...@@ -420,6 +363,12 @@ describe('License Report MR Widget', () => {
undefined, undefined,
undefined, undefined,
); );
expect(actions.fetchLicenseCheckApprovalRule).toHaveBeenCalledWith(
expect.any(Object),
undefined,
undefined,
);
}); });
describe('approval status', () => { describe('approval status', () => {
......
...@@ -534,6 +534,23 @@ describe('License store actions', () => { ...@@ -534,6 +534,23 @@ describe('License store actions', () => {
const error = new Error('Request failed with status code 500'); const error = new Error('Request failed with status code 500');
axiosMock.onGet(approvalsApiPath).replyOnce(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( testAction(
actions.fetchLicenseCheckApprovalRule, actions.fetchLicenseCheckApprovalRule,
null, 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