Commit 4d969ea6 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Moved tasks by type request to api.js

Part of consolidating cycle analytics
api requests in the api module.

Added a spec for tasks by type request
parent 19e6fcc4
import axios from '~/lib/utils/axios_utils';
import createFlash, { hideFlash } from '~/flash';
import { __ } from '~/locale';
import Api from '~/api';
import Api from 'ee/api';
import httpStatus from '~/lib/utils/http_status';
import * as types from './mutation_types';
import { nestQueryStringKeys } from '../utils';
......@@ -195,13 +195,6 @@ export const createCustomStage = ({ dispatch, state }, data) => {
.catch(error => dispatch('receiveCreateCustomStageError', { error, data }));
};
export const receiveTasksByTypeSuccess = ({ commit }, data) =>
commit(types.RECEIVE_TASKS_BY_TYPE_SUCCESS, data);
export const receiveTasksByTypeError = ({ commit }, error) => {
commit(types.RECEIVE_TASKS_BY_TYPE_ERROR, error);
createFlash(__('There was an error fetching data for the form'));
};
export const receiveTasksByTypeDataSuccess = ({ commit }, data) =>
commit(types.RECEIVE_TASKS_BY_TYPE_DATA_SUCCESS, data);
......@@ -212,7 +205,6 @@ export const receiveTasksByTypeDataError = ({ commit }, error) => {
export const requestTasksByTypeData = ({ commit }) => commit(types.REQUEST_TASKS_BY_TYPE_DATA);
export const fetchTasksByTypeData = ({ dispatch, state, getters }) => {
const endpoint = '/-/analytics/type_of_work/tasks_by_type';
const {
currentGroupPath,
cycleAnalyticsRequestParams: { created_after, created_before, project_ids },
......@@ -226,17 +218,16 @@ export const fetchTasksByTypeData = ({ dispatch, state, getters }) => {
if (labelIds.length) {
const params = {
group_id: currentGroupPath,
label_ids: `[${labelIds.join(',')}]`,
created_after,
created_before,
project_ids,
subject,
label_ids: labelIds,
};
dispatch('requestTasksByTypeData');
return axios
.get(endpoint, { params })
return Api.cycleAnalyticsTasksByType(params)
.then(data => dispatch('receiveTasksByTypeDataSuccess', data))
.catch(error => dispatch('receiveTasksByTypeDataError', error));
}
......
......@@ -18,6 +18,7 @@ export default {
groupPackagesPath: '/api/:version/groups/:id/packages',
projectPackagesPath: '/api/:version/projects/:id/packages',
projectPackagePath: '/api/:version/projects/:id/packages/:package_id',
cycleAnalyticsTasksByTypePath: '/-/analytics/type_of_work/tasks_by_type',
userSubscription(namespaceId) {
const url = Api.buildUrl(this.subscriptionPath).replace(':id', encodeURIComponent(namespaceId));
......@@ -135,4 +136,9 @@ export default {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.delete(url);
},
cycleAnalyticsTasksByType(params = {}) {
const url = Api.buildUrl(this.cycleAnalyticsTasksByTypePath);
return axios.get(url, { params });
},
};
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import Api from 'ee/api';
import * as cycleAnalyticsConstants from 'ee/analytics/cycle_analytics/constants';
describe('Api', () => {
const dummyApiVersion = 'v3000';
......@@ -283,4 +284,51 @@ describe('Api', () => {
});
});
});
describe('Cycle analytics', () => {
const groupId = 'counting-54321';
const createdBefore = '2019-11-18';
const createdAfter = '2019-08-18';
describe('cycleAnalyticsTasksByType', () => {
it('fetches tasks by type data', done => {
const tasksByTypeResponse = [
{
label: {
id: 9,
title: 'Thursday',
color: '#7F8C8D',
description: 'What are you waiting for?',
group_id: 2,
project_id: null,
template: false,
text_color: '#FFFFFF',
created_at: '2019-08-20T05:22:49.046Z',
updated_at: '2019-08-20T05:22:49.046Z',
},
series: [['2019-11-03', 5]],
},
];
const labelIds = [10, 9, 8, 7];
const params = {
group_id: groupId,
created_after: createdAfter,
created_before: createdBefore,
project_ids: null,
subject: cycleAnalyticsConstants.TASKS_BY_TYPE_SUBJECT_ISSUE,
label_ids: labelIds,
};
const expectedUrl = `${dummyUrlRoot}/-/analytics/type_of_work/tasks_by_type`;
mock.onGet(expectedUrl).reply(200, tasksByTypeResponse);
Api.cycleAnalyticsTasksByType({ params })
.then(({ data, config: { params: reqParams } }) => {
expect(data).toEqual(tasksByTypeResponse);
expect(reqParams.params).toEqual(params);
})
.then(done)
.catch(done.fail);
});
});
});
});
......@@ -17422,9 +17422,6 @@ msgstr ""
msgid "There was an error fetching data for the chart"
msgstr ""
msgid "There was an error fetching data for the form"
msgstr ""
msgid "There was an error fetching data for the selected stage"
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