Commit 07322e7e authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '32644-insights-config-error-null' into 'master'

Display error for invalid insights config

Closes #32644

See merge request gitlab-org/gitlab!17589
parents 519e04ee 7a2f4346
...@@ -6,20 +6,27 @@ import { __ } from '~/locale'; ...@@ -6,20 +6,27 @@ import { __ } from '~/locale';
export const requestConfig = ({ commit }) => commit(types.REQUEST_CONFIG); export const requestConfig = ({ commit }) => commit(types.REQUEST_CONFIG);
export const receiveConfigSuccess = ({ commit }, data) => export const receiveConfigSuccess = ({ commit }, data) =>
commit(types.RECEIVE_CONFIG_SUCCESS, data); commit(types.RECEIVE_CONFIG_SUCCESS, data);
export const receiveConfigError = ({ commit }) => commit(types.RECEIVE_CONFIG_ERROR); export const receiveConfigError = ({ commit }, errorMessage) => {
const error = errorMessage || __('Unknown Error');
const message = `${__('There was an error fetching configuration for charts')}: ${error}`;
createFlash(message);
commit(types.RECEIVE_CONFIG_ERROR);
};
export const fetchConfigData = ({ dispatch }, endpoint) => { export const fetchConfigData = ({ dispatch }, endpoint) => {
dispatch('requestConfig'); dispatch('requestConfig');
return axios return axios
.get(endpoint) .get(endpoint)
.then(({ data }) => dispatch('receiveConfigSuccess', data)) .then(({ data }) => {
if (data) {
dispatch('receiveConfigSuccess', data);
} else {
dispatch('receiveConfigError');
}
})
.catch(error => { .catch(error => {
const message = `${__('There was an error fetching configuration for charts')}: ${ dispatch('receiveConfigError', error.response.data.message);
error.response.data.message
}`;
createFlash(message);
dispatch('receiveConfigError');
}); });
}; };
......
---
title: Display error for invalid insights config
merge_request: 17589
author:
type: fixed
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'spec/helpers/vuex_action_helper';
import * as actions from 'ee/insights/stores/modules/insights/actions'; import actionsModule, * as actions from 'ee/insights/stores/modules/insights/actions';
const ERROR_MESSAGE = 'TEST_ERROR_MESSAGE';
describe('Insights store actions', () => { describe('Insights store actions', () => {
const key = 'bugsPerTeam'; const key = 'bugsPerTeam';
...@@ -44,59 +46,105 @@ describe('Insights store actions', () => { ...@@ -44,59 +46,105 @@ describe('Insights store actions', () => {
}); });
describe('receiveConfigError', () => { describe('receiveConfigError', () => {
it('commits RECEIVE_CONFIG_ERROR', done => { let flashSpy;
beforeEach(() => {
flashSpy = spyOnDependency(actionsModule, 'createFlash');
});
it('commits RECEIVE_CONFIG_ERROR and shows flash message', done => {
testAction( testAction(
actions.receiveConfigError, actions.receiveConfigError,
null, ERROR_MESSAGE,
null, null,
[{ type: 'RECEIVE_CONFIG_ERROR' }], [{ type: 'RECEIVE_CONFIG_ERROR' }],
[], [],
done, () => {
expect(flashSpy).toHaveBeenCalledWith(
`There was an error fetching configuration for charts: ${ERROR_MESSAGE}`,
);
done();
},
);
});
it('flashes Unknown Error when error message is falsey', done => {
testAction(
actions.receiveConfigError,
null,
null,
jasmine.any(Array),
jasmine.any(Array),
() => {
expect(flashSpy).toHaveBeenCalledWith(
`There was an error fetching configuration for charts: Unknown Error`,
);
done();
},
); );
}); });
}); });
describe('fetchConfigData', () => { describe('fetchConfigData', () => {
let mock; let mock;
let dispatch;
beforeEach(() => { beforeEach(() => {
dispatch = jasmine.createSpy('dispatch');
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onGet(gl.TEST_HOST).reply(200, configData);
}); });
afterEach(() => { afterEach(() => {
mock.restore(); mock.restore();
}); });
it('calls requestConfig', done => { describe('success calls', () => {
const context = { beforeEach(() => {
dispatch, mock.onGet(gl.TEST_HOST).reply(200, configData);
}; });
actions it('calls requestConfig and receiveConfigSuccess', done => {
.fetchConfigData(context, gl.TEST_HOST) testAction(
.then(() => { actions.fetchConfigData,
expect(dispatch.calls.argsFor(0)).toEqual(['requestConfig']); gl.TEST_HOST,
}) {},
.then(done) [],
.catch(done.fail); [{ type: 'requestConfig' }, { type: 'receiveConfigSuccess', payload: configData }],
done,
);
});
});
describe('failed calls', () => {
beforeEach(() => {
mock.onGet(gl.TEST_HOST).reply(500, { message: ERROR_MESSAGE });
});
it('calls receiveConfigError upon error from service', done => {
testAction(
actions.fetchConfigData,
gl.TEST_HOST,
{},
[],
[{ type: 'requestConfig' }, { type: 'receiveConfigError', payload: ERROR_MESSAGE }],
done,
);
});
}); });
it('calls receiveConfigSuccess with config data', done => { describe('success calls with null data', () => {
const context = { beforeEach(() => {
dispatch, mock.onGet(gl.TEST_HOST).reply(200, null);
}; });
actions it('calls receiveConfigError upon null config data returned', done => {
.fetchConfigData(context, gl.TEST_HOST) testAction(
.then(() => { actions.fetchConfigData,
expect(dispatch.calls.argsFor(1)).toEqual(['receiveConfigSuccess', configData]); gl.TEST_HOST,
}) {},
.then(done) [],
.catch(done.fail); [{ type: 'requestConfig' }, { type: 'receiveConfigError' }],
done,
);
});
}); });
}); });
......
...@@ -17140,6 +17140,9 @@ msgstr "" ...@@ -17140,6 +17140,9 @@ msgstr ""
msgid "Unknown" msgid "Unknown"
msgstr "" msgstr ""
msgid "Unknown Error"
msgstr ""
msgid "Unknown encryption strategy: %{encrypted_strategy}!" msgid "Unknown encryption strategy: %{encrypted_strategy}!"
msgstr "" msgstr ""
......
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