Skip to content
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
12 changes: 12 additions & 0 deletions static/app/utils/getDaysSinceDate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ describe('getDaysSinceDate', () => {
it('simple test', () => {
expect(getDaysSinceDate('2022-05-11')).toBe(26);
});
it('deprecated date format', () => {
expect(getDaysSinceDate('Thu May 11 2022')).toBe(26);
});
it('iso string', () => {
expect(getDaysSinceDate('2022-05-11T17:19:18.307Z')).toBe(26);
});
it('iso string 23:59', () => {
expect(getDaysSinceDate('2022-05-11T23:59:59.900Z')).toBe(26);
});
it('iso string 00:00', () => {
expect(getDaysSinceDate('2022-05-11T00:00:00.100Z')).toBe(26);
});
});
28 changes: 24 additions & 4 deletions static/gsApp/components/navBillingStatus.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
);
localStorage.setItem(
`billing-status-last-shown-date-${organization.id}`,
'Mon Jun 06 2022' // MOCK_TODAY
'2022-06-06T05:09:33.000Z' // MOCK_TODAY
);
});

Expand All @@ -97,7 +97,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
).toBe('errors-replays-spans-profileDuration');
expect(
localStorage.getItem(`billing-status-last-shown-date-${organization.id}`)
).toBe('Mon Jun 06 2022');
).toBe('2022-06-06T05:09:33.000Z');
}

it('should render for multiple categories', async () => {
Expand Down Expand Up @@ -399,7 +399,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
assertLocalStorageStateAfterAutoOpen();
});

it('should auto open the alert when more than a day has passed', async () => {
it('should auto open the alert when more than a day has passed (deprecated date format)', async () => {
localStorage.setItem(
`billing-status-last-shown-date-${organization.id}`,
'Sun Jun 05 2022'
Expand All @@ -409,7 +409,7 @@ describe('PrimaryNavigationQuotaExceeded', () => {
assertLocalStorageStateAfterAutoOpen();
});

it('should auto open the alert when the last shown date is before the current usage cycle started', async () => {
it('should auto open the alert when the last shown date is before the current usage cycle started (deprecated date format)', async () => {
localStorage.setItem(
`billing-status-last-shown-date-${organization.id}`,
'Sun May 29 2022'
Expand All @@ -418,4 +418,24 @@ describe('PrimaryNavigationQuotaExceeded', () => {
expect(await screen.findByText('Quotas Exceeded')).toBeInTheDocument();
assertLocalStorageStateAfterAutoOpen();
});

it('should auto open the alert when more than a day has passed (ISO date format)', async () => {
localStorage.setItem(
`billing-status-last-shown-date-${organization.id}`,
'2022-06-05T15:00:32.000Z'
); // more than a day, so alert should show even though categories haven't changed
render(<PrimaryNavigationQuotaExceeded organization={organization} />);
expect(await screen.findByText('Quotas Exceeded')).toBeInTheDocument();
assertLocalStorageStateAfterAutoOpen();
});

it('should auto open the alert when the last shown date is before the current usage cycle started (ISO date format))', async () => {
localStorage.setItem(
`billing-status-last-shown-date-${organization.id}`,
'2022-05-29T05:09:33.000Z'
); // last seen before current usage cycle started, so alert should show even though categories haven't changed
render(<PrimaryNavigationQuotaExceeded organization={organization} />);
expect(await screen.findByText('Quotas Exceeded')).toBeInTheDocument();
assertLocalStorageStateAfterAutoOpen();
});
});
6 changes: 2 additions & 4 deletions static/gsApp/components/navBillingStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ function PrimaryNavigationQuotaExceeded({organization}: {organization: Organizat
organization,
daysToSnooze:
-1 *
getDaysSinceDate(
subscription?.onDemandPeriodEnd ?? moment().utc().toDate().toDateString()
),
getDaysSinceDate(subscription?.onDemandPeriodEnd ?? moment().utc().toISOString()),
isDismissed: isSnoozedForCurrentPeriod,
options: {
Comment on lines +213 to 215
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback parameter passed to getDaysSinceDate has been changed to use ISO format (toISOString()), which is good practice and is now tested. However, there is an inconsistency: on line 245, the date is still being stored in localStorage using the deprecated toDateString() format ('Mon Jun 06 2022'). This means when lastShownDate is retrieved from localStorage and passed to getDaysSinceDate() on line 231, it will be in the old format. While getDaysSinceDate() appears to support both formats (as verified by the new tests), it would be more consistent and future-proof to also update line 245 to store dates in ISO format using moment().utc().toISOString() instead of moment().utc().toDate().toDateString().
Severity: MEDIUM

🤖 Prompt for AI Agent

Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: static/gsApp/components/navBillingStatus.tsx#L213-L215

Potential issue: The fallback parameter passed to getDaysSinceDate has been changed to
use ISO format (toISOString()), which is good practice and is now tested. However, there
is an inconsistency: on line 245, the date is still being stored in localStorage using
the deprecated toDateString() format ('Mon Jun 06 2022'). This means when lastShownDate
is retrieved from localStorage and passed to getDaysSinceDate() on line 231, it will be
in the old format. While getDaysSinceDate() appears to support both formats (as verified
by the new tests), it would be more consistent and future-proof to also update line 245
to store dates in ISO format using moment().utc().toISOString() instead of
moment().utc().toDate().toDateString().

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the localStorage to use ISO string as well. When reading from local storage, we parse the date with moment(), so it will remain compatible with both formats.

enabled: promptsToCheck.length > 0,
Comment on lines 210 to 216
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: localStorage.setItem at navBillingStatus.tsx:289 writes a deprecated date format, causing getDaysSinceDate to receive an invalid input.
Severity: HIGH | Confidence: 1.00

🔍 Detailed Analysis

The code at navBillingStatus.tsx:289 stores a date in localStorage using moment().utc().toDate().toDateString(), which generates a deprecated date format. This value is subsequently retrieved and passed to getDaysSinceDate() at line 277. Despite a fix for another instance, this specific localStorage write was not updated, causing getDaysSinceDate() to consistently receive the deprecated format and trigger deprecation warnings.

💡 Suggested Fix

Update the localStorage.setItem call at navBillingStatus.tsx:289 to store the date in ISO format using moment().utc().toISOString().

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: static/gsApp/components/navBillingStatus.tsx#L210-L216

Potential issue: The code at `navBillingStatus.tsx:289` stores a date in `localStorage`
using `moment().utc().toDate().toDateString()`, which generates a deprecated date
format. This value is subsequently retrieved and passed to `getDaysSinceDate()` at line
277. Despite a fix for another instance, this specific `localStorage` write was not
updated, causing `getDaysSinceDate()` to consistently receive the deprecated format and
trigger deprecation warnings.

Did we get this right? 👍 / 👎 to inform future reviews.

Expand Down Expand Up @@ -262,7 +260,7 @@ function PrimaryNavigationQuotaExceeded({organization}: {organization: Organizat
);
localStorage.setItem(
`billing-status-last-shown-date-${organization.id}`,
moment().utc().toDate().toDateString()
moment().utc().toISOString()
);
}
}, [
Expand Down
Loading