Skip to content

Commit

Permalink
Merge pull request Expensify#33688 from wlegolas/bugfix/issue-33248
Browse files Browse the repository at this point in the history
Fix oldCreated date format when the created date was changed
  • Loading branch information
youssef-lr authored Jan 12, 2024
2 parents e2d1443 + 326f61d commit b6a18b1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {format} from 'date-fns';
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTags, ReportAction} from '@src/types/onyx';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import * as Localize from './Localize';
import * as PolicyUtils from './PolicyUtils';
import * as ReportUtils from './ReportUtils';
Expand Down Expand Up @@ -145,13 +145,11 @@ function getForReportAction(reportAction: ReportAction): string {
);
}

const hasModifiedCreated = reportActionOriginalMessage && 'oldCreated' in reportActionOriginalMessage && 'created' in reportActionOriginalMessage;
if (hasModifiedCreated) {
// Take only the YYYY-MM-DD value as the original date includes timestamp
let formattedOldCreated: Date | string = new Date(reportActionOriginalMessage?.oldCreated ? reportActionOriginalMessage.oldCreated : 0);
formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING);
if (reportActionOriginalMessage?.oldCreated && reportActionOriginalMessage?.created) {
const formattedOldCreated = DateUtils.formatWithUTCTimeZone(reportActionOriginalMessage.oldCreated, CONST.DATE.FNS_FORMAT_STRING);

buildMessageFragmentForValue(
reportActionOriginalMessage?.created ?? '',
reportActionOriginalMessage.created,
formattedOldCreated,
Localize.translateLocal('common.date'),
false,
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/ModifiedExpenseMessageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,42 @@ describe('ModifiedExpenseMessage', () => {
expect(result).toEqual(expectedResult);
});
});

describe('when the created date is changed', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
originalMessage: {
created: '2023-12-27',
oldCreated: '2023-12-26',
},
};

it('returns the correct text message', () => {
const expectedResult = 'changed the date to 2023-12-27 (previously 2023-12-26).';

const result = ModifiedExpenseMessage.getForReportAction(reportAction);

expect(result).toEqual(expectedResult);
});
});

describe('when the created date was not changed', () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
originalMessage: {
created: '2023-12-27',
},
};

it('returns the correct text message', () => {
const expectedResult = 'changed the request';

const result = ModifiedExpenseMessage.getForReportAction(reportAction);

expect(result).toEqual(expectedResult);
});
});
});
});

0 comments on commit b6a18b1

Please sign in to comment.