Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rhsmTransformers): ent-5213 allow first dates to draw line #955

Merged
merged 2 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,126 @@ Object {
}
`;

exports[`RHSM Transformers should attempt to parse a tally response: tally, daily like first of month granularity 1`] = `
Object {
"data": Array [
Object {
"date": "2019-07-20T00:00:00Z",
"hasData": true,
"isCurrentDate": false,
"isFutureDate": false,
"x": 0,
"y": 0.1,
},
Object {
"date": "2019-07-20T00:00:00Z",
"hasData": true,
"isCurrentDate": true,
"isFutureDate": false,
"x": 1,
"y": 0.1,
},
Object {
"date": "2019-07-21T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 2,
"y": null,
},
Object {
"date": "2019-07-22T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 3,
"y": null,
},
Object {
"date": "2019-07-23T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 4,
"y": null,
},
Object {
"date": "2019-07-24T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 5,
"y": null,
},
Object {
"date": "2019-07-25T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 6,
"y": null,
},
Object {
"date": "2019-07-26T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 7,
"y": null,
},
Object {
"date": "2019-07-27T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 8,
"y": null,
},
Object {
"date": "2019-07-28T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 9,
"y": null,
},
Object {
"date": "2019-07-29T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 10,
"y": null,
},
Object {
"date": "2019-07-30T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 11,
"y": null,
},
Object {
"date": "2019-07-31T00:00:00Z",
"hasData": false,
"isCurrentDate": false,
"isFutureDate": true,
"x": 12,
"y": null,
},
],
"meta": Object {
"cloudigradeHasMismatch": undefined,
"count": undefined,
"metricId": undefined,
"productId": undefined,
"totalMonthlyDate": undefined,
"totalMonthlyHasData": undefined,
"totalMonthlyValue": undefined,
},
}
`;

exports[`RHSM Transformers should attempt to parse a tally response: tally, daily like granularity 1`] = `
Object {
"data": Array [
Expand Down
72 changes: 72 additions & 0 deletions src/services/rhsm/__tests__/rhsmTransformers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,78 @@ describe('RHSM Transformers', () => {

expect(rhsmTransformers.tally(dailyTallyResponse)).toMatchSnapshot('tally, daily like granularity');

const dailyTallyFirstMonthResponse = {
[rhsmConstants.RHSM_API_RESPONSE_DATA]: [
{
[TALLY_DATA_TYPES.DATE]: '2019-07-20T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.1,
[TALLY_DATA_TYPES.HAS_DATA]: true
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-21T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-22T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-23T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-24T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-25T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-26T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-27T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-28T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-29T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-30T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
},
{
[TALLY_DATA_TYPES.DATE]: '2019-07-31T00:00:00Z',
[TALLY_DATA_TYPES.VALUE]: 0.0,
[TALLY_DATA_TYPES.HAS_DATA]: false
}
],
[rhsmConstants.RHSM_API_RESPONSE_META]: {}
};

const transformedDailyTallyFirstMonthResponse = rhsmTransformers.tally(dailyTallyFirstMonthResponse);

expect(dailyTallyFirstMonthResponse[rhsmConstants.RHSM_API_RESPONSE_DATA].length).toBe(12);
expect(transformedDailyTallyFirstMonthResponse.data.length).toBe(13);
expect(transformedDailyTallyFirstMonthResponse).toMatchSnapshot('tally, daily like first of month granularity');

const monthlyTallyResponse = {
[rhsmConstants.RHSM_API_RESPONSE_DATA]: [
{
Expand Down
24 changes: 24 additions & 0 deletions src/services/rhsm/rhsmTransformers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ const rhsmInstances = response => {
return updatedResponse;
};

/**
* ToDo: Evaluate granularity alterations, transform logic is targeted at daily granularity
* Specifically, the "isCurrentDate" condition is targeted at daily. Weekly, monthly, and
* quarterly have not been tested, and may need logic adjustments for "isCurrentLikeDate".
*/
/**
* Parse RHSM tally response for caching.
*
Expand All @@ -63,6 +68,7 @@ const rhsmTally = response => {
const { [rhsmConstants.RHSM_API_RESPONSE_DATA]: data = [], [rhsmConstants.RHSM_API_RESPONSE_META]: meta = {} } =
response || {};
const currentDate = moment.utc(dateHelpers.getCurrentDate()).format('MM-D-YYYY');
let futureDateCount = 0;

updatedResponse.data = data.map(
(
Expand All @@ -73,6 +79,10 @@ const rhsmTally = response => {
const isCurrentDate = updatedDate.format('MM-D-YYYY') === currentDate;
const isFutureDate = updatedDate.diff(currentDate) > 0;

if (isFutureDate) {
futureDateCount += 1;
}

return {
x: index,
y: (hasData === false && isFutureDate) || (hasData === false && isCurrentDate) ? null : value,
Expand All @@ -84,6 +94,20 @@ const rhsmTally = response => {
}
);

/**
* Add an extra date to the first entry of the range to help Victory charts display.
*/
if (futureDateCount === updatedResponse.data.length - 1) {
updatedResponse.data = [
{
...updatedResponse.data[0],
x: 0,
isCurrentDate: false
},
...updatedResponse.data
].map((props, index) => ({ ...props, x: index }));
}

updatedResponse.meta = {
count: meta[TALLY_META_TYPES.COUNT],
cloudigradeHasMismatch: meta[TALLY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH],
Expand Down