Commit 6765cc89 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'mw-pa-group-project-utils' into 'master'

Productivity Analytics: Add buildGroupFromDataset and buildProjectFromDataset utility functions

See merge request gitlab-org/gitlab!21654
parents 6113a16f 79738fe8
...@@ -186,3 +186,45 @@ export const getMedianLineData = (data, startDate, endDate, daysOffset) => { ...@@ -186,3 +186,45 @@ export const getMedianLineData = (data, startDate, endDate, daysOffset) => {
return result; return result;
}; };
/**
* Creates a group object from a dataset. Returns null if no groupId is present.
*
* @param {Object} dataset - The container's dataset
* @returns {Object} - A group object
*/
export const buildGroupFromDataset = dataset => {
const { groupId, groupName, groupFullPath, groupAvatarUrl } = dataset;
if (groupId) {
return {
id: Number(groupId),
name: groupName,
full_path: groupFullPath,
avatar_url: groupAvatarUrl,
};
}
return null;
};
/**
* Creates a project object from a dataset. Returns null if no projectId is present.
*
* @param {Object} dataset - The container's dataset
* @returns {Object} - A project object
*/
export const buildProjectFromDataset = dataset => {
const { projectId, projectName, projectPathWithNamespace, projectAvatarUrl } = dataset;
if (projectId) {
return {
id: Number(projectId),
name: projectName,
path_with_namespace: projectPathWithNamespace,
avatar_url: projectAvatarUrl,
};
}
return null;
};
...@@ -2,6 +2,8 @@ import { ...@@ -2,6 +2,8 @@ import {
getLabelsEndpoint, getLabelsEndpoint,
getMilestonesEndpoint, getMilestonesEndpoint,
getDefaultStartDate, getDefaultStartDate,
buildGroupFromDataset,
buildProjectFromDataset,
initDateArray, initDateArray,
transformScatterData, transformScatterData,
getScatterPlotData, getScatterPlotData,
...@@ -62,6 +64,51 @@ describe('Productivity Analytics utils', () => { ...@@ -62,6 +64,51 @@ describe('Productivity Analytics utils', () => {
}); });
}); });
describe('buildGroupFromDataset', () => {
it('returns null if groupId is missing', () => {
const dataset = { foo: 'bar' };
expect(buildGroupFromDataset(dataset)).toBeNull();
});
it('returns a group object when the groupId is given', () => {
const dataset = {
groupId: '1',
groupName: 'My Group',
groupFullPath: 'my-group',
groupAvatarUrl: 'foo/bar',
};
expect(buildGroupFromDataset(dataset)).toEqual({
id: 1,
name: 'My Group',
full_path: 'my-group',
avatar_url: 'foo/bar',
});
});
});
describe('buildProjectFromDataset', () => {
it('returns null if projectId is missing', () => {
const dataset = { foo: 'bar' };
expect(buildProjectFromDataset(dataset)).toBeNull();
});
it('returns a project object when the projectId is given', () => {
const dataset = {
projectId: '1',
projectName: 'My Project',
projectPathWithNamespace: 'my-group/my-project',
};
expect(buildProjectFromDataset(dataset)).toEqual({
id: 1,
name: 'My Project',
path_with_namespace: 'my-group/my-project',
avatar_url: undefined,
});
});
});
describe('initDateArray', () => { describe('initDateArray', () => {
it('creates a two-dimensional array with 3 empty arrays for startDate=2019-09-01 and endDate=2019-09-03', () => { it('creates a two-dimensional array with 3 empty arrays for startDate=2019-09-01 and endDate=2019-09-03', () => {
const startDate = new Date('2019-09-01'); const startDate = new Date('2019-09-01');
......
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