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

Move from moment to native Date object backed with date-fns #1580

Merged
merged 29 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3382fe3
Remove momentjs package and replace with date-fns
kr8n3r Oct 28, 2020
713f26d
Update DATE related constant formating
kr8n3r Oct 28, 2020
38eccf9
Replace momentjs in service-metrics/view file
kr8n3r Oct 28, 2020
63e29eb
Replace moment in the service component
paroxp Jun 17, 2021
fe40baa
Make sure the PM and AM are lower cased as per tests
paroxp Jun 17, 2021
6fd4c81
Address linting issues
paroxp Jun 17, 2021
e439d86
Replace moment in the app component
paroxp Jun 22, 2021
a926048
Replace moment in the calculator component
paroxp Jun 22, 2021
3c64d0d
Replace moment in the application-events component
paroxp Jun 22, 2021
9ac1471
Replace moment in the charts component
paroxp Jun 22, 2021
7b6e91f
Replace moment in the events component
paroxp Jun 22, 2021
358e6f2
Replace moment in the performance component
paroxp Jun 22, 2021
b2e3d06
Replace moment in the platform-admin component
paroxp Jun 22, 2021
64c331c
Replace moment in the reports component
paroxp Jun 22, 2021
abc4a70
Replace moment in the service-events component
paroxp Jun 22, 2021
bd99d63
Replace moment in the service-metrics component
paroxp Jun 22, 2021
d34e762
Replace moment in the services component
paroxp Jun 22, 2021
4cd1f64
Replace moment in the spaces component
paroxp Jun 22, 2021
3713cde
Replace moment in the statements component
paroxp Jun 22, 2021
d56328d
Replace moment in the users component
paroxp Jun 22, 2021
2a2b343
Replace moment in the layouts
paroxp Jun 22, 2021
e52dcf2
Replace moment in the accounts library
paroxp Jun 22, 2021
e6c51f2
Replace moment in the billing library
paroxp Jun 22, 2021
dba0676
Replace moment in the metric-data-getters library
paroxp Jun 22, 2021
9cc260f
Replace moment in the metrics library
paroxp Jun 22, 2021
df54ab8
Replace moment in the moments library
paroxp Jun 22, 2021
92a161b
Replace moment in the prom library
paroxp Jun 22, 2021
cbeb8ec
Replace moment in the stub-api
paroxp Jun 22, 2021
c06836d
Hack Duration to human readable
paroxp Jun 22, 2021
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
54 changes: 18 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@types/jsdom": "^16.2.11",
"@types/jsonwebtoken": "^8.5.1",
"@types/lodash": "^4.14.170",
"@types/moment": "^2.13.0",
"@types/node-jose": "^1.1.6",
"@types/passport": "^1.0.6",
"@types/passport-oauth2": "^1.4.10",
Expand Down Expand Up @@ -124,6 +123,7 @@
"d3-scale": "^3.3.0",
"d3-selection": "^2.0.0",
"d3-shape": "^2.1.0",
"date-fns": "^2.22.1",
"express": "^4.17.1",
"express-pino-logger": "^6.0.0",
"express-static-gzip": "^2.1.1",
Expand All @@ -133,7 +133,6 @@
"helmet": "^4.6.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"nanoid": "^3.1.23",
"node-jose": "^2.0.0",
"node-zendesk": "^2.1.0",
Expand Down
20 changes: 8 additions & 12 deletions src/components/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Mocking request-promise-native is a workaround. See https://github.com/request/request-promise/issues/247.
jest.mock('request-promise-native');

import { endOfMonth, format, startOfMonth } from 'date-fns';
import jwt from 'jsonwebtoken';
import moment from 'moment';
import nock from 'nock';
import request, { SuperTest, Test } from 'supertest';

Expand All @@ -19,10 +19,10 @@ import Router, { IParameters } from '../../lib/router';
import { CLOUD_CONTROLLER_ADMIN } from '../auth';

import init from './app';
import csp from './app.csp';
import { csp } from './app.csp';
import { config } from './app.test.config';
import { IContext, initContext } from './context';
import router from './router';
import { router } from './router';

const tokenKey = 'tokensecret';

Expand Down Expand Up @@ -126,12 +126,8 @@ describe('app test suite', () => {
});

it('should be able to handle 500 error when accessing pricing calculator', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nockBilling
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand Down Expand Up @@ -208,7 +204,7 @@ describe('app test suite', () => {
});

it('should be able to access marketplace without login', async () => {
const service = { guid: 'SERVICE_GUID', name: 'postgres', broker_catalog: { metadata: {} }, tags: [] };
const service = { broker_catalog: { metadata: {} }, guid: 'SERVICE_GUID', name: 'postgres', tags: [] };
nockCF
.get('/v3/service_offerings').reply(200, { pagination: { next: null }, resources: [ service ] });

Expand All @@ -229,8 +225,8 @@ describe('app test suite', () => {
});

it('should be able to access marketplace service without login', async () => {
const service = { guid: 'SERVICE_GUID', name: 'postgres', broker_catalog: { metadata: {} }, tags: [] };
const plan = { name: 'tiny', broker_catalog: { metadata: {} } };
const service = { broker_catalog: { metadata: {} }, guid: 'SERVICE_GUID', name: 'postgres', tags: [] };
const plan = { broker_catalog: { metadata: {} }, name: 'tiny' };
nockCF
.get('/v3/service_offerings/SERVICE_GUID')
.reply(200, service)
Expand Down
16 changes: 8 additions & 8 deletions src/components/application-events/controllers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { format } from 'date-fns';
import lodash from 'lodash';
import moment from 'moment';
import nock from 'nock';

import { DATE_TIME } from '../../layouts';
import { spacesMissingAroundInlineElements } from '../../layouts/react-spacing.test';
import * as data from '../../lib/cf/cf.test.data';
import { app as defaultApp } from '../../lib/cf/test-data/app';
import { auditEvent as defaultAuditEvent, auditEventForAutoscaler } from '../../lib/cf/test-data/audit-event';
import { auditEventForAutoscaler, auditEvent as defaultAuditEvent } from '../../lib/cf/test-data/audit-event';
import { org as defaultOrg } from '../../lib/cf/test-data/org';
import { wrapV3Resources } from '../../lib/cf/test-data/wrap-resources';
import { createTestContext } from '../app/app.test-helpers';
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('application event', () => {
afterEach(() => {
nockAccounts.done();
nockCF.on('response', () => {
nockCF.done()
nockCF.done();
});

nock.cleanAll();
Expand All @@ -54,18 +54,18 @@ describe('application event', () => {
const event = defaultAuditEvent();

const response = await viewApplicationEvent(ctx, {
organizationGUID: '6e1ca5aa-55f1-4110-a97f-1f3473e771b9',
spaceGUID: '38511660-89d9-4a6e-a889-c32c7e94f139',
applicationGUID: defaultApp().metadata.guid,
eventGUID: event.guid,
organizationGUID: '6e1ca5aa-55f1-4110-a97f-1f3473e771b9',
spaceGUID: '38511660-89d9-4a6e-a889-c32c7e94f139',
});

expect(response.body).toContain(
`Application ${defaultApp().entity.name} Event details`,
);

expect(response.body).toContain(
/* DateTime */ moment(event.updated_at).format(DATE_TIME),
/* DateTime */ format(new Date(event.updated_at), DATE_TIME),
);
expect(response.body).toContain(/* Actor */ 'admin');
expect(response.body).toContain(/* Description */ 'Updated application');
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('application event', () => {
);

expect(response.body).toContain(
/* DateTime */ moment(event.updated_at).format(DATE_TIME),
/* DateTime */ format(new Date(event.updated_at), DATE_TIME),
);
expect(response.body).toContain(/* Actor */ 'one@user.in.database');
expect(response.body).toContain(/* Description */ 'Updated application');
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('application event', () => {
);

expect(response.body).toContain(
/* DateTime */ moment(event.updated_at).format(DATE_TIME),
/* DateTime */ format(new Date(event.updated_at), DATE_TIME),
);
expect(response.body).toContain(/* Actor */ 'unknown-actor');
expect(response.body).toContain(/* Description */ 'Updated application');
Expand Down
66 changes: 17 additions & 49 deletions src/components/calculator/controllers.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment';
import { endOfMonth, format, startOfMonth } from 'date-fns';
import nock from 'nock';

import { spacesMissingAroundInlineElements } from '../../layouts/react-spacing.test';
Expand Down Expand Up @@ -36,12 +36,8 @@ describe('calculator test suite', () => {
});

it('should get calculator', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand Down Expand Up @@ -107,12 +103,8 @@ describe('calculator test suite', () => {
});

it('should get a zero quote if no items are specified', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand All @@ -130,12 +122,8 @@ describe('calculator test suite', () => {
});

it('should calculate prices (including exchange rate) when provided fake services', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand Down Expand Up @@ -209,12 +197,8 @@ describe('calculator test suite', () => {
});

it('should sort the quote by order added', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

const postgresGuid = 'f4d4b95a-f55e-4593-8d54-3364c25798c4';
const appGuid = 'f4d4b95b-f55e-4593-8d54-3364c25798c0';
Expand Down Expand Up @@ -267,12 +251,8 @@ describe('calculator test suite', () => {
});

it('should filter out compose plans', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand All @@ -295,12 +275,8 @@ describe('calculator test suite', () => {
});

it('should show postgres plan and sort the versions', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand Down Expand Up @@ -357,12 +333,8 @@ describe('calculator test suite', () => {
});

it('should use calculator and ignore empty application', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand Down Expand Up @@ -419,12 +391,8 @@ describe('calculator test suite', () => {
});

it('should omit printing "default" when there is only a default pricing plan', async () => {
const rangeStart = moment()
.startOf('month')
.format('YYYY-MM-DD');
const rangeStop = moment()
.endOf('month')
.format('YYYY-MM-DD');
const rangeStart = format(startOfMonth(new Date()), 'yyyy-MM-dd');
const rangeStop = format(endOfMonth(new Date()), 'yyyy-MM-dd');

nock(config.billingAPI)
.get(`/pricing_plans?range_start=${rangeStart}&range_stop=${rangeStop}`)
Expand Down
Loading