summaryrefslogtreecommitdiff
path: root/spec/frontend/monitoring/store/actions_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/monitoring/store/actions_spec.js')
-rw-r--r--spec/frontend/monitoring/store/actions_spec.js212
1 files changed, 100 insertions, 112 deletions
diff --git a/spec/frontend/monitoring/store/actions_spec.js b/spec/frontend/monitoring/store/actions_spec.js
index 9f0b4d16fc1..7c559aed2c5 100644
--- a/spec/frontend/monitoring/store/actions_spec.js
+++ b/spec/frontend/monitoring/store/actions_spec.js
@@ -5,13 +5,13 @@ import axios from '~/lib/utils/axios_utils';
import statusCodes from '~/lib/utils/http_status';
import * as commonUtils from '~/lib/utils/common_utils';
import createFlash from '~/flash';
+import { defaultTimeRange } from '~/vue_shared/constants';
import store from '~/monitoring/stores';
import * as types from '~/monitoring/stores/mutation_types';
import {
fetchDashboard,
receiveMetricsDashboardSuccess,
- receiveMetricsDashboardFailure,
fetchDeploymentsData,
fetchEnvironmentsData,
fetchPrometheusMetrics,
@@ -77,42 +77,40 @@ describe('Monitoring store actions', () => {
});
describe('fetchDeploymentsData', () => {
- it('commits RECEIVE_DEPLOYMENTS_DATA_SUCCESS on error', done => {
- const dispatch = jest.fn();
+ it('dispatches receiveDeploymentsDataSuccess on success', () => {
const { state } = store;
state.deploymentsEndpoint = '/success';
mock.onGet(state.deploymentsEndpoint).reply(200, {
deployments: deploymentData,
});
- fetchDeploymentsData({
+
+ return testAction(
+ fetchDeploymentsData,
+ null,
state,
- dispatch,
- })
- .then(() => {
- expect(dispatch).toHaveBeenCalledWith('receiveDeploymentsDataSuccess', deploymentData);
- done();
- })
- .catch(done.fail);
+ [],
+ [{ type: 'receiveDeploymentsDataSuccess', payload: deploymentData }],
+ );
});
- it('commits RECEIVE_DEPLOYMENTS_DATA_FAILURE on error', done => {
- const dispatch = jest.fn();
+ it('dispatches receiveDeploymentsDataFailure on error', () => {
const { state } = store;
state.deploymentsEndpoint = '/error';
mock.onGet(state.deploymentsEndpoint).reply(500);
- fetchDeploymentsData({
+
+ return testAction(
+ fetchDeploymentsData,
+ null,
state,
- dispatch,
- })
- .then(() => {
- expect(dispatch).toHaveBeenCalledWith('receiveDeploymentsDataFailure');
- done();
- })
- .catch(done.fail);
+ [],
+ [{ type: 'receiveDeploymentsDataFailure' }],
+ () => {
+ expect(createFlash).toHaveBeenCalled();
+ },
+ );
});
});
describe('fetchEnvironmentsData', () => {
- const dispatch = jest.fn();
const { state } = store;
state.projectPath = 'gitlab-org/gitlab-test';
@@ -164,15 +162,19 @@ describe('Monitoring store actions', () => {
state.environmentsSearchTerm = searchTerm;
mockMutate.mockReturnValue(Promise.resolve());
- return fetchEnvironmentsData({
+ return testAction(
+ fetchEnvironmentsData,
+ null,
state,
- dispatch,
- }).then(() => {
- expect(mockMutate).toHaveBeenCalledWith(mutationVariables);
- });
+ [],
+ [{ type: 'requestEnvironmentsData' }, { type: 'receiveEnvironmentsDataFailure' }],
+ () => {
+ expect(mockMutate).toHaveBeenCalledWith(mutationVariables);
+ },
+ );
});
- it('commits RECEIVE_ENVIRONMENTS_DATA_SUCCESS on success', () => {
+ it('dispatches receiveEnvironmentsDataSuccess on success', () => {
jest.spyOn(gqClient, 'mutate').mockReturnValue(
Promise.resolve({
data: {
@@ -185,26 +187,31 @@ describe('Monitoring store actions', () => {
}),
);
- return fetchEnvironmentsData({
+ return testAction(
+ fetchEnvironmentsData,
+ null,
state,
- dispatch,
- }).then(() => {
- expect(dispatch).toHaveBeenCalledWith(
- 'receiveEnvironmentsDataSuccess',
- parseEnvironmentsResponse(environmentData, state.projectPath),
- );
- });
+ [],
+ [
+ { type: 'requestEnvironmentsData' },
+ {
+ type: 'receiveEnvironmentsDataSuccess',
+ payload: parseEnvironmentsResponse(environmentData, state.projectPath),
+ },
+ ],
+ );
});
- it('commits RECEIVE_ENVIRONMENTS_DATA_FAILURE on error', () => {
+ it('dispatches receiveEnvironmentsDataFailure on error', () => {
jest.spyOn(gqClient, 'mutate').mockReturnValue(Promise.reject());
- return fetchEnvironmentsData({
+ return testAction(
+ fetchEnvironmentsData,
+ null,
state,
- dispatch,
- }).then(() => {
- expect(dispatch).toHaveBeenCalledWith('receiveEnvironmentsDataFailure');
- });
+ [],
+ [{ type: 'requestEnvironmentsData' }, { type: 'receiveEnvironmentsDataFailure' }],
+ );
});
});
@@ -266,27 +273,24 @@ describe('Monitoring store actions', () => {
state = storeState();
state.dashboardEndpoint = '/dashboard';
});
- it('on success, dispatches receive and success actions', done => {
- const params = {};
+
+ it('on success, dispatches receive and success actions', () => {
document.body.dataset.page = 'projects:environments:metrics';
mock.onGet(state.dashboardEndpoint).reply(200, response);
- fetchDashboard(
- {
- state,
- commit,
- dispatch,
- },
- params,
- )
- .then(() => {
- expect(dispatch).toHaveBeenCalledWith('requestMetricsDashboard');
- expect(dispatch).toHaveBeenCalledWith('receiveMetricsDashboardSuccess', {
- response,
- params,
- });
- done();
- })
- .catch(done.fail);
+
+ return testAction(
+ fetchDashboard,
+ null,
+ state,
+ [],
+ [
+ { type: 'requestMetricsDashboard' },
+ {
+ type: 'receiveMetricsDashboardSuccess',
+ payload: { response },
+ },
+ ],
+ );
});
describe('on failure', () => {
@@ -299,7 +303,7 @@ describe('Monitoring store actions', () => {
};
});
- it('dispatches a failure action', done => {
+ it('dispatches a failure', done => {
result()
.then(() => {
expect(commit).toHaveBeenCalledWith(
@@ -351,31 +355,22 @@ describe('Monitoring store actions', () => {
let commit;
let dispatch;
let state;
+
beforeEach(() => {
commit = jest.fn();
dispatch = jest.fn();
state = storeState();
});
- it('stores groups ', () => {
- const params = {};
+
+ it('stores groups', () => {
const response = metricsDashboardResponse;
- receiveMetricsDashboardSuccess(
- {
- state,
- commit,
- dispatch,
- },
- {
- response,
- params,
- },
- );
+ receiveMetricsDashboardSuccess({ state, commit, dispatch }, { response });
expect(commit).toHaveBeenCalledWith(
- types.RECEIVE_METRICS_DATA_SUCCESS,
+ types.RECEIVE_METRICS_DASHBOARD_SUCCESS,
metricsDashboardResponse.dashboard,
);
- expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetrics', params);
+ expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetrics');
});
it('sets the dashboards loaded from the repository', () => {
const params = {};
@@ -395,29 +390,7 @@ describe('Monitoring store actions', () => {
expect(commit).toHaveBeenCalledWith(types.SET_ALL_DASHBOARDS, dashboardGitResponse);
});
});
- describe('receiveMetricsDashboardFailure', () => {
- let commit;
- beforeEach(() => {
- commit = jest.fn();
- });
- it('commits failure action', () => {
- receiveMetricsDashboardFailure({
- commit,
- });
- expect(commit).toHaveBeenCalledWith(types.RECEIVE_METRICS_DATA_FAILURE, undefined);
- });
- it('commits failure action with error', () => {
- receiveMetricsDashboardFailure(
- {
- commit,
- },
- 'uh-oh',
- );
- expect(commit).toHaveBeenCalledWith(types.RECEIVE_METRICS_DATA_FAILURE, 'uh-oh');
- });
- });
describe('fetchPrometheusMetrics', () => {
- const params = {};
let commit;
let dispatch;
let state;
@@ -427,13 +400,15 @@ describe('Monitoring store actions', () => {
commit = jest.fn();
dispatch = jest.fn();
state = storeState();
+
+ state.timeRange = defaultTimeRange;
});
it('commits empty state when state.groups is empty', done => {
const getters = {
metricsWithData: () => [],
};
- fetchPrometheusMetrics({ state, commit, dispatch, getters }, params)
+ fetchPrometheusMetrics({ state, commit, dispatch, getters })
.then(() => {
expect(Tracking.event).toHaveBeenCalledWith(
document.body.dataset.page,
@@ -444,7 +419,9 @@ describe('Monitoring store actions', () => {
value: 0,
},
);
- expect(dispatch).not.toHaveBeenCalled();
+ expect(dispatch).toHaveBeenCalledTimes(1);
+ expect(dispatch).toHaveBeenCalledWith('fetchDeploymentsData');
+
expect(createFlash).not.toHaveBeenCalled();
done();
})
@@ -460,11 +437,15 @@ describe('Monitoring store actions', () => {
metricsWithData: () => [metric.id],
};
- fetchPrometheusMetrics({ state, commit, dispatch, getters }, params)
+ fetchPrometheusMetrics({ state, commit, dispatch, getters })
.then(() => {
expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetric', {
metric,
- params,
+ defaultQueryParams: {
+ start_time: expect.any(String),
+ end_time: expect.any(String),
+ step: expect.any(Number),
+ },
});
expect(Tracking.event).toHaveBeenCalledWith(
@@ -487,16 +468,22 @@ describe('Monitoring store actions', () => {
state.dashboard.panelGroups = metricsDashboardViewModel.panelGroups;
const metric = state.dashboard.panelGroups[0].panels[0].metrics[0];
+ dispatch.mockResolvedValueOnce(); // fetchDeploymentsData
// Mock having one out of four metrics failing
dispatch.mockRejectedValueOnce(new Error('Error fetching this metric'));
dispatch.mockResolvedValue();
- fetchPrometheusMetrics({ state, commit, dispatch }, params)
+ fetchPrometheusMetrics({ state, commit, dispatch })
.then(() => {
- expect(dispatch).toHaveBeenCalledTimes(9); // one per metric
+ expect(dispatch).toHaveBeenCalledTimes(10); // one per metric plus 1 for deployments
+ expect(dispatch).toHaveBeenCalledWith('fetchDeploymentsData');
expect(dispatch).toHaveBeenCalledWith('fetchPrometheusMetric', {
metric,
- params,
+ defaultQueryParams: {
+ start_time: expect.any(String),
+ end_time: expect.any(String),
+ step: expect.any(Number),
+ },
});
expect(createFlash).toHaveBeenCalledTimes(1);
@@ -508,9 +495,10 @@ describe('Monitoring store actions', () => {
});
});
describe('fetchPrometheusMetric', () => {
- const params = {
+ const defaultQueryParams = {
start_time: '2019-08-06T12:40:02.184Z',
end_time: '2019-08-06T20:40:02.184Z',
+ step: 60,
};
let metric;
let state;
@@ -532,7 +520,7 @@ describe('Monitoring store actions', () => {
testAction(
fetchPrometheusMetric,
- { metric, params },
+ { metric, defaultQueryParams },
state,
[
{
@@ -569,7 +557,7 @@ describe('Monitoring store actions', () => {
testAction(
fetchPrometheusMetric,
- { metric, params },
+ { metric, defaultQueryParams },
state,
[
{
@@ -611,7 +599,7 @@ describe('Monitoring store actions', () => {
testAction(
fetchPrometheusMetric,
- { metric, params },
+ { metric, defaultQueryParams },
state,
[
{
@@ -646,7 +634,7 @@ describe('Monitoring store actions', () => {
testAction(
fetchPrometheusMetric,
- { metric, params },
+ { metric, defaultQueryParams },
state,
[
{
@@ -682,7 +670,7 @@ describe('Monitoring store actions', () => {
testAction(
fetchPrometheusMetric,
- { metric, params },
+ { metric, defaultQueryParams },
state,
[
{