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