From 95ef3b1abcf21e25e5495c4897d05323fd31f419 Mon Sep 17 00:00:00 2001 From: Ben Limpich Date: Fri, 3 Oct 2025 15:55:30 -0700 Subject: [PATCH 1/2] checkpoint --- codecov.yml | 4 ++-- src/libs/CurrencyUtils.ts | 2 +- src/libs/DistanceRequestUtils.ts | 1 + tests/unit/DistanceRequestUtilsTest.ts | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/codecov.yml b/codecov.yml index b9eb26bc27e5..8b5c658a21a0 100644 --- a/codecov.yml +++ b/codecov.yml @@ -17,8 +17,8 @@ codecov: after_n_builds: 3 comment: - require_changes: "coverage_drop OR uncovered_patch" - layout: "condensed_header, diff, condensed_footer" + require_changes: false + layout: "condensed_header, files, condensed_footer" behavior: default hide_project_coverage: true diff --git a/src/libs/CurrencyUtils.ts b/src/libs/CurrencyUtils.ts index 2587e3610eb7..05905e05090e 100644 --- a/src/libs/CurrencyUtils.ts +++ b/src/libs/CurrencyUtils.ts @@ -24,7 +24,7 @@ Onyx.connect({ * For currencies that have decimal places > 2, floor to 2 instead: * https://github.com/Expensify/App/issues/15878#issuecomment-1496291464 * - * @param currency - IOU currency + * @param currency - IOU currency defaults to USD */ function getCurrencyDecimals(currency: string = CONST.CURRENCY.USD): number { const decimals = currencyList?.[currency]?.decimals; diff --git a/src/libs/DistanceRequestUtils.ts b/src/libs/DistanceRequestUtils.ts index 9fc752b2dbfa..252f920c2f2c 100644 --- a/src/libs/DistanceRequestUtils.ts +++ b/src/libs/DistanceRequestUtils.ts @@ -409,6 +409,7 @@ export default { getRateByCustomUnitRateID, getDistanceForDisplayLabel, convertDistanceUnit, + ensureRateDefined }; export type {MileageRate}; diff --git a/tests/unit/DistanceRequestUtilsTest.ts b/tests/unit/DistanceRequestUtilsTest.ts index d2ec4c6037d9..22a2efcad13b 100644 --- a/tests/unit/DistanceRequestUtilsTest.ts +++ b/tests/unit/DistanceRequestUtilsTest.ts @@ -98,6 +98,8 @@ describe('DistanceRequestUtils', () => { const reportID = '1234'; const isPolicyExpenseChat = true; + DistanceRequestUtils.ensureRateDefined(2134); + const result = DistanceRequestUtils.getCustomUnitRateID({ reportID, isPolicyExpenseChat, From 8de7bf95efb2beb40fc23dff99bc41081833cff1 Mon Sep 17 00:00:00 2001 From: Ben Limpich Date: Fri, 3 Oct 2025 15:56:07 -0700 Subject: [PATCH 2/2] checkpoint --- tests/unit/DateUtilsTest.ts | 137 ------------------------------------ 1 file changed, 137 deletions(-) diff --git a/tests/unit/DateUtilsTest.ts b/tests/unit/DateUtilsTest.ts index 7c3d135c74fb..f89fe406c8a5 100644 --- a/tests/unit/DateUtilsTest.ts +++ b/tests/unit/DateUtilsTest.ts @@ -56,143 +56,6 @@ describe('DateUtils', () => { expect(zoneAbbreviation).toBe('GMT-8'); }); - it('formatToLongDateWithWeekday should return a long date with a weekday', () => { - const formattedDate = DateUtils.formatToLongDateWithWeekday(datetime); - expect(formattedDate).toBe('Monday, November 7, 2022'); - }); - - it('formatToDayOfWeek should return a weekday', () => { - const weekDay = DateUtils.formatToDayOfWeek(new Date(datetime)); - expect(weekDay).toBe('Monday'); - }); - it('formatToLocalTime should return a date in a local format', () => { - const localTime = DateUtils.formatToLocalTime(datetime); - expect(localTime).toBe('12:00 AM'); - }); - - it('should return a date object with the formatted datetime when calling getLocalDateFromDatetime', () => { - const localDate = DateUtils.getLocalDateFromDatetime(LOCALE, timezone, datetime); - expect(tzFormat(localDate, CONST.DATE.FNS_TIMEZONE_FORMAT_STRING, {timeZone: timezone})).toEqual('2022-11-06T16:00:00-08:00'); - }); - - it('should fallback to current date when getLocalDateFromDatetime is failing', () => { - const localDate = DateUtils.getLocalDateFromDatetime(LOCALE, 'InvalidTimezone' as SelectedTimezone, undefined); - expect(localDate.getTime()).not.toBeNaN(); - }); - - it('should return the date in calendar time when calling datetimeToCalendarTime', () => { - const today = setMinutes(setHours(new Date(), 14), 32).toString(); - expect(DateUtils.datetimeToCalendarTime(LOCALE, today, UTC as SelectedTimezone, false)).toBe('Today at 2:32 PM'); - - const tomorrow = addDays(setMinutes(setHours(new Date(), 14), 32), 1).toString(); - expect(DateUtils.datetimeToCalendarTime(LOCALE, tomorrow, UTC as SelectedTimezone, false)).toBe('Tomorrow at 2:32 PM'); - - const yesterday = setMinutes(setHours(subDays(new Date(), 1), 7), 43).toString(); - expect(DateUtils.datetimeToCalendarTime(LOCALE, yesterday, UTC as SelectedTimezone, false)).toBe('Yesterday at 7:43 AM'); - - const date = setMinutes(setHours(new Date('2022-11-05'), 10), 17).toString(); - expect(DateUtils.datetimeToCalendarTime(LOCALE, date, UTC as SelectedTimezone, false)).toBe('Nov 5, 2022 at 10:17 AM'); - - const todayLowercaseDate = setMinutes(setHours(new Date(), 14), 32).toString(); - expect(DateUtils.datetimeToCalendarTime(LOCALE, todayLowercaseDate, UTC as SelectedTimezone, false, true)).toBe('today at 2:32 PM'); - }); - - it('should update timezone if automatic and selected timezone do not match', async () => { - jest.spyOn(Intl, 'DateTimeFormat').mockImplementation( - () => - ({ - resolvedOptions: () => ({timeZone: 'America/Chicago'}), - }) as Intl.DateTimeFormat, - ); - Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {'999': {accountID: 999, timezone: {selected: 'Europe/London', automatic: true}}}); - await waitForBatchedUpdates(); - const result = DateUtils.getCurrentTimezone({selected: 'Europe/London', automatic: true}); - expect(result).toEqual({ - selected: 'America/Chicago', - automatic: true, - }); - }); - - it('should not update timezone if automatic and selected timezone match', async () => { - jest.spyOn(Intl, 'DateTimeFormat').mockImplementation( - () => - ({ - resolvedOptions: () => ({timeZone: UTC}), - }) as Intl.DateTimeFormat, - ); - Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {'999': {accountID: 999, timezone: {selected: 'Europe/London', automatic: true}}}); - await waitForBatchedUpdates(); - const result = DateUtils.getCurrentTimezone({selected: 'Europe/London', automatic: true}); - expect(result).toEqual({ - selected: UTC, - automatic: true, - }); - }); - - it('canUpdateTimezone should return true when lastUpdatedTimezoneTime is more than 5 minutes ago', () => { - // Use fake timers to control the current time - jest.useFakeTimers(); - jest.setSystemTime(addMinutes(new Date(), 6)); - const isUpdateTimezoneAllowed = DateUtils.canUpdateTimezone(); - expect(isUpdateTimezoneAllowed).toBe(true); - }); - - it('canUpdateTimezone should return false when lastUpdatedTimezoneTime is less than 5 minutes ago', () => { - // Use fake timers to control the current time - jest.useFakeTimers(); - DateUtils.setTimezoneUpdated(); - jest.setSystemTime(addMinutes(new Date(), 4)); - const isUpdateTimezoneAllowed = DateUtils.canUpdateTimezone(); - expect(isUpdateTimezoneAllowed).toBe(false); - }); - - it('should return the date in calendar time when calling datetimeToRelative', () => { - const aFewSecondsAgo = subSeconds(new Date(), 10).toString(); - expect(DateUtils.datetimeToRelative(LOCALE, aFewSecondsAgo, UTC as SelectedTimezone)).toBe('less than a minute ago'); - - const aMinuteAgo = subMinutes(new Date(), 1).toString(); - expect(DateUtils.datetimeToRelative(LOCALE, aMinuteAgo, UTC as SelectedTimezone)).toBe('1 minute ago'); - - const anHourAgo = subHours(new Date(), 1).toString(); - expect(DateUtils.datetimeToRelative(LOCALE, anHourAgo, UTC as SelectedTimezone)).toBe('about 1 hour ago'); - }); - - it('subtractMillisecondsFromDateTime should subtract milliseconds from a given date and time', () => { - const initialDateTime = '2023-07-18T10:30:00Z'; - const millisecondsToSubtract = 5000; // 5 seconds - const expectedDateTime = '2023-07-18 10:29:55.000'; - const result = DateUtils.subtractMillisecondsFromDateTime(initialDateTime, millisecondsToSubtract); - expect(result).toBe(expectedDateTime); - }); - - describe('Date Comparison Functions', () => { - const today = new Date(); - const tomorrow = addDays(today, 1); - const yesterday = subDays(today, 1); - - const todayInTimezone = toZonedTime(today, timezone); - const tomorrowInTimezone = toZonedTime(tomorrow, timezone); - const yesterdayInTimezone = toZonedTime(yesterday, timezone); - - it('isToday should correctly identify today', () => { - expect(DateUtils.isToday(todayInTimezone, timezone)).toBe(true); - expect(DateUtils.isToday(tomorrowInTimezone, timezone)).toBe(false); - expect(DateUtils.isToday(yesterdayInTimezone, timezone)).toBe(false); - }); - - it('isTomorrow should correctly identify tomorrow', () => { - expect(DateUtils.isTomorrow(tomorrowInTimezone, timezone)).toBe(true); - expect(DateUtils.isTomorrow(todayInTimezone, timezone)).toBe(false); - expect(DateUtils.isTomorrow(yesterdayInTimezone, timezone)).toBe(false); - }); - - it('isYesterday should correctly identify yesterday', () => { - expect(DateUtils.isYesterday(yesterdayInTimezone, timezone)).toBe(true); - expect(DateUtils.isYesterday(todayInTimezone, timezone)).toBe(false); - expect(DateUtils.isYesterday(tomorrowInTimezone, timezone)).toBe(false); - }); - }); - describe('getDBTime', () => { it('should return the date in the format expected by the database', () => { const getDBTime = DateUtils.getDBTime();