Commit 8ac27d4f authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Replace old cycle analytics summary data endpoint

Updates the request for cycle analytics summary
data in ee/app/assets/javascripts/api.js to
point to the new endpoint, and updates the
relevant jest tests.
parent 707e97ac
...@@ -139,17 +139,16 @@ export const receiveSummaryDataSuccess = ({ commit }, data) => ...@@ -139,17 +139,16 @@ export const receiveSummaryDataSuccess = ({ commit }, data) =>
commit(types.RECEIVE_SUMMARY_DATA_SUCCESS, data); commit(types.RECEIVE_SUMMARY_DATA_SUCCESS, data);
export const fetchSummaryData = ({ state, dispatch, getters }) => { export const fetchSummaryData = ({ state, dispatch, getters }) => {
const { cycleAnalyticsRequestParams = {} } = getters; const {
cycleAnalyticsRequestParams: { created_after, created_before },
} = getters;
dispatch('requestSummaryData'); dispatch('requestSummaryData');
const { const {
selectedGroup: { fullPath }, selectedGroup: { fullPath },
} = state; } = state;
return Api.cycleAnalyticsSummaryData( return Api.cycleAnalyticsSummaryData({ group_id: fullPath, created_after, created_before })
fullPath,
nestQueryStringKeys(cycleAnalyticsRequestParams, 'cycle_analytics'),
)
.then(({ data }) => dispatch('receiveSummaryDataSuccess', data)) .then(({ data }) => dispatch('receiveSummaryDataSuccess', data))
.catch(error => dispatch('receiveSummaryDataError', error)); .catch(error => dispatch('receiveSummaryDataError', error));
}; };
......
...@@ -111,8 +111,7 @@ export default { ...@@ -111,8 +111,7 @@ export default {
state.summary = []; state.summary = [];
}, },
[types.RECEIVE_SUMMARY_DATA_SUCCESS](state, data) { [types.RECEIVE_SUMMARY_DATA_SUCCESS](state, data) {
const { summary } = data; state.summary = data.map(item => ({
state.summary = summary.map(item => ({
...item, ...item,
value: item.value || '-', value: item.value || '-',
})); }));
......
...@@ -16,7 +16,7 @@ export default { ...@@ -16,7 +16,7 @@ export default {
projectPackagesPath: '/api/:version/projects/:id/packages', projectPackagesPath: '/api/:version/projects/:id/packages',
projectPackagePath: '/api/:version/projects/:id/packages/:package_id', projectPackagePath: '/api/:version/projects/:id/packages/:package_id',
cycleAnalyticsTasksByTypePath: '/-/analytics/type_of_work/tasks_by_type', cycleAnalyticsTasksByTypePath: '/-/analytics/type_of_work/tasks_by_type',
cycleAnalyticsSummaryDataPath: '/groups/:group_id/-/cycle_analytics', cycleAnalyticsSummaryDataPath: '/-/analytics/cycle_analytics/summary',
cycleAnalyticsGroupStagesAndEventsPath: '/-/analytics/cycle_analytics/stages', cycleAnalyticsGroupStagesAndEventsPath: '/-/analytics/cycle_analytics/stages',
cycleAnalyticsStageEventsPath: '/-/analytics/cycle_analytics/stages/:stage_id/records', cycleAnalyticsStageEventsPath: '/-/analytics/cycle_analytics/stages/:stage_id/records',
cycleAnalyticsStageMedianPath: '/-/analytics/cycle_analytics/stages/:stage_id/median', cycleAnalyticsStageMedianPath: '/-/analytics/cycle_analytics/stages/:stage_id/median',
...@@ -144,9 +144,8 @@ export default { ...@@ -144,9 +144,8 @@ export default {
return axios.get(url, { params }); return axios.get(url, { params });
}, },
cycleAnalyticsSummaryData(groupId, params = {}) { cycleAnalyticsSummaryData(params = {}) {
const url = Api.buildUrl(this.cycleAnalyticsSummaryDataPath).replace(':group_id', groupId); const url = Api.buildUrl(this.cycleAnalyticsSummaryDataPath);
return axios.get(url, { params }); return axios.get(url, { params });
}, },
......
...@@ -364,7 +364,7 @@ describe('Cycle Analytics component', () => { ...@@ -364,7 +364,7 @@ describe('Cycle Analytics component', () => {
fetchSummaryData: { fetchSummaryData: {
status: defaultStatus, status: defaultStatus,
endpoint: `/-/analytics/cycle_analytics/summary`, endpoint: `/-/analytics/cycle_analytics/summary`,
response: { ...mockData.summaryData }, response: [...mockData.summaryData],
}, },
fetchGroupStagesAndEvents: { fetchGroupStagesAndEvents: {
status: defaultStatus, status: defaultStatus,
...@@ -435,7 +435,7 @@ describe('Cycle Analytics component', () => { ...@@ -435,7 +435,7 @@ describe('Cycle Analytics component', () => {
overrides: { overrides: {
fetchSummaryData: { fetchSummaryData: {
status: httpStatusCodes.NOT_FOUND, status: httpStatusCodes.NOT_FOUND,
endpoint: '/analytics/cycle_analytics/summary', endpoint: '/-/analytics/cycle_analytics/summary',
response: { response: { status: httpStatusCodes.NOT_FOUND } }, response: { response: { status: httpStatusCodes.NOT_FOUND } },
}, },
}, },
......
...@@ -165,7 +165,6 @@ describe('Cycle analytics mutations', () => { ...@@ -165,7 +165,6 @@ describe('Cycle analytics mutations', () => {
describe(`${types.RECEIVE_SUMMARY_DATA_SUCCESS}`, () => { describe(`${types.RECEIVE_SUMMARY_DATA_SUCCESS}`, () => {
beforeEach(() => { beforeEach(() => {
console.log('summaryData', summaryData);
state = { stages: [{ slug: 'plan' }, { slug: 'issue' }, { slug: 'test' }] }; state = { stages: [{ slug: 'plan' }, { slug: 'issue' }, { slug: 'test' }] };
mutations[types.RECEIVE_SUMMARY_DATA_SUCCESS](state, summaryData); mutations[types.RECEIVE_SUMMARY_DATA_SUCCESS](state, summaryData);
}); });
......
...@@ -319,6 +319,11 @@ describe('Api', () => { ...@@ -319,6 +319,11 @@ describe('Api', () => {
const createdBefore = '2019-11-18'; const createdBefore = '2019-11-18';
const createdAfter = '2019-08-18'; const createdAfter = '2019-08-18';
const stageId = 'thursday'; const stageId = 'thursday';
const defaultParams = {
group_id: groupId,
created_after: createdAfter,
created_before: createdBefore,
};
const expectRequestWithCorrectParameters = (responseObj, { params, expectedUrl, response }) => { const expectRequestWithCorrectParameters = (responseObj, { params, expectedUrl, response }) => {
const { const {
...@@ -351,9 +356,7 @@ describe('Api', () => { ...@@ -351,9 +356,7 @@ describe('Api', () => {
]; ];
const labelIds = [10, 9, 8, 7]; const labelIds = [10, 9, 8, 7];
const params = { const params = {
group_id: groupId, ...defaultParams,
created_after: createdAfter,
created_before: createdBefore,
project_ids: null, project_ids: null,
subject: cycleAnalyticsConstants.TASKS_BY_TYPE_SUBJECT_ISSUE, subject: cycleAnalyticsConstants.TASKS_BY_TYPE_SUBJECT_ISSUE,
label_ids: labelIds, label_ids: labelIds,
...@@ -372,16 +375,16 @@ describe('Api', () => { ...@@ -372,16 +375,16 @@ describe('Api', () => {
}); });
describe('cycleAnalyticsSummaryData', () => { describe('cycleAnalyticsSummaryData', () => {
it('fetches cycle analytics summary, stage stats and permissions data', done => { it('fetches cycle analytics summary data', done => {
const response = { summary: [], stats: [], permissions: {} }; const response = [{ value: 0, title: 'New Issues' }, { value: 0, title: 'Deploys' }];
const params = { const params = {
'cycle_analytics[created_after]': createdAfter, ...defaultParams,
'cycle_analytics[created_before]': createdBefore,
}; };
const expectedUrl = `${dummyUrlRoot}/groups/${groupId}/-/cycle_analytics`;
const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/summary`;
mock.onGet(expectedUrl).reply(200, response); mock.onGet(expectedUrl).reply(200, response);
Api.cycleAnalyticsSummaryData(groupId, params) Api.cycleAnalyticsSummaryData(params)
.then(responseObj => .then(responseObj =>
expectRequestWithCorrectParameters(responseObj, { expectRequestWithCorrectParameters(responseObj, {
response, response,
...@@ -422,9 +425,7 @@ describe('Api', () => { ...@@ -422,9 +425,7 @@ describe('Api', () => {
it('fetches stage events', done => { it('fetches stage events', done => {
const response = { events: [] }; const response = { events: [] };
const params = { const params = {
group_id: groupId, ...defaultParams,
created_after: createdAfter,
created_before: createdBefore,
}; };
const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/stages/${stageId}/records`; const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/stages/${stageId}/records`;
mock.onGet(expectedUrl).reply(200, response); mock.onGet(expectedUrl).reply(200, response);
...@@ -446,9 +447,7 @@ describe('Api', () => { ...@@ -446,9 +447,7 @@ describe('Api', () => {
it('fetches stage events', done => { it('fetches stage events', done => {
const response = { value: '5 days ago' }; const response = { value: '5 days ago' };
const params = { const params = {
group_id: groupId, ...defaultParams,
created_after: createdAfter,
created_before: createdBefore,
}; };
const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/stages/${stageId}/median`; const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/stages/${stageId}/median`;
mock.onGet(expectedUrl).reply(200, response); mock.onGet(expectedUrl).reply(200, response);
...@@ -535,9 +534,7 @@ describe('Api', () => { ...@@ -535,9 +534,7 @@ describe('Api', () => {
it('fetches stage duration data', done => { it('fetches stage duration data', done => {
const response = []; const response = [];
const params = { const params = {
group_id: groupId, ...defaultParams,
created_after: createdAfter,
created_before: createdBefore,
}; };
const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/stages/thursday/duration_chart`; const expectedUrl = `${dummyUrlRoot}/-/analytics/cycle_analytics/stages/thursday/duration_chart`;
mock.onGet(expectedUrl).reply(200, response); mock.onGet(expectedUrl).reply(200, response);
......
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