Commit 843c7026 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'threat-monitoring-improve-not-found' into 'master'

Improve NOT_FOUND response handling on ThreatMonitoring page

See merge request gitlab-org/gitlab!29452
parents 87fc7205 fefbc89b
......@@ -3,7 +3,6 @@ import pollUntilComplete from '~/lib/utils/poll_until_complete';
import httpStatusCodes from '~/lib/utils/http_status';
import createFlash from '~/flash';
import * as types from './mutation_types';
import createState from './state';
import { getTimeWindowParams } from '../../utils';
export const requestStatistics = ({ commit }, timeWindowParams) => {
......@@ -40,7 +39,7 @@ export const fetchStatistics = ({ state, dispatch, rootState }) => {
// no data, but we can't distinguish between them, yet. So, just render
// no data.
if (error.response.status === httpStatusCodes.NOT_FOUND) {
dispatch('receiveStatisticsSuccess', createState().statistics);
dispatch('receiveStatisticsSuccess', null);
} else {
dispatch('receiveStatisticsError');
}
......
import * as types from './mutation_types';
import createState from './state';
export default transformFunc => ({
[types.SET_ENDPOINT](state, endpoint) {
......@@ -10,7 +11,8 @@ export default transformFunc => ({
state.timeRange = timeRange;
},
[types.RECEIVE_STATISTICS_SUCCESS](state, payload) {
state.statistics = transformFunc(payload);
const stats = payload ? transformFunc(payload) : createState().statistics;
state.statistics = stats;
state.isLoadingStatistics = false;
state.errorLoadingStatistics = false;
},
......
......@@ -140,17 +140,7 @@ describe('threatMonitoringStatistics actions', () => {
[],
[
{ type: 'requestStatistics', payload: expect.any(Object) },
{
type: 'receiveStatisticsSuccess',
payload: expect.objectContaining({
total: 0,
anomalous: 0,
history: {
nominal: [],
anomalous: [],
},
}),
},
{ type: 'receiveStatisticsSuccess', payload: null },
],
));
});
......
......@@ -53,6 +53,31 @@ describe('threatMonitoringStatistics mutations', () => {
it('sets errorLoadingStatistics to false', () => {
expect(state.errorLoadingStatistics).toBe(false);
});
describe('with null payload', () => {
beforeEach(() => {
mutations[types.RECEIVE_STATISTICS_SUCCESS](state, null);
});
it('sets statistics to the empty state', () => {
expect(state.statistics).toEqual({
total: 0,
anomalous: 0,
history: {
nominal: [],
anomalous: [],
},
});
});
it('sets isLoadingStatistics to false', () => {
expect(state.isLoadingStatistics).toBe(false);
});
it('sets errorLoadingStatistics to false', () => {
expect(state.errorLoadingStatistics).toBe(false);
});
});
});
describe(types.RECEIVE_STATISTICS_ERROR, () => {
......
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