-
Notifications
You must be signed in to change notification settings - Fork 3k
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: add missing violation data #54603
base: main
Are you sure you want to change the base?
Conversation
policy.maxExpenseAmountNoReceipt && | ||
Math.abs(updatedTransaction.amount) > policy.maxExpenseAmountNoReceipt && | ||
!updatedTransaction.receipt?.receiptID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare this as a new const
newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.RECEIPT_REQUIRED}); | ||
} | ||
|
||
if (!hasOverLimitViolation && policyMaxExpenseAmount && Math.abs(updatedTransaction.amount) > policyMaxExpenseAmount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ^ (only the part after !hasOverLimitViolation &&
)
const hasFutureDateViolation = transactionViolations.some((violation) => violation.name === 'futureDate'); | ||
const hasReceiptRequiredViolation = transactionViolations.some((violation) => violation.name === 'receiptRequired'); | ||
const hasOverLimitViolation = transactionViolations.some((violation) => violation.name === 'overLimit'); | ||
const policyMaxExpenseAmount = policy.maxExpenseAmount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const policyMaxExpenseAmount = policy.maxExpenseAmount; |
Unnecessary const
tests/unit/ViolationUtilsTest.ts
Outdated
@@ -125,6 +154,26 @@ describe('getViolationsOnyxData', () => { | |||
expect(result.value).toEqual(expect.arrayContaining([missingCategoryViolation, ...transactionViolations])); | |||
}); | |||
|
|||
it('should add futureDate violation if the transaction has a future date', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure that all workspaces disallow future-dated expenses?
@@ -222,6 +259,19 @@ const ViolationsUtils = { | |||
newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.CUSTOM_UNIT_OUT_OF_POLICY}); | |||
} | |||
|
|||
const inputDate = new Date(updatedTransaction.created); | |||
const shouldDisplayFutureDateViolation = DateUtils.isFutureDate(inputDate) && policy.type === CONST.POLICY.TYPE.CORPORATE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be && type != TEAM
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also what about this being an invoice? There is not violation in this case either
const shouldShowReceiptRequiredViolation = | ||
policy.maxExpenseAmountNoReceipt && Math.abs(updatedTransaction.amount) > policy.maxExpenseAmountNoReceipt && !updatedTransaction.receipt?.receiptID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use TransactionUtils.hasReceipt
@@ -222,6 +259,19 @@ const ViolationsUtils = { | |||
newTransactionViolations = reject(newTransactionViolations, {name: CONST.VIOLATIONS.CUSTOM_UNIT_OUT_OF_POLICY}); | |||
} | |||
|
|||
const inputDate = new Date(updatedTransaction.created); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two fields created
and modifiedCreated
. If you update the transaction to a non-future date, will the violation go away correctly? (or do we have to check modifiedCreated
)
(same goes for amount)
/** | ||
* Checks if the input time is after the reference date | ||
* param {Date} inputDate - The date to validate. | ||
* returns {boolean} - Returns true if the input date is after the reference date, otherwise false. | ||
*/ | ||
const isFutureDate = (inputDate: Date): boolean => { | ||
return isAfter(startOfDay(inputDate), startOfDay(new Date())); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove startOfDay
?
it('should not add futureDate violation if the policy is not corporate', () => { | ||
policy.type = 'personal'; | ||
const result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policy, policyTags, policyCategories, false); | ||
expect(result.value).toEqual(transactionViolations); | ||
}); | ||
|
||
it('should add futureDate violation if the transaction has a future date and policy is corporate', () => { | ||
policy.type = 'corporate'; | ||
const result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policy, policyTags, policyCategories, false); | ||
expect(result.value).toEqual(expect.arrayContaining([futureDateViolation, ...transactionViolations])); | ||
}); | ||
|
||
it('should remove futureDate violation if the policy is downgraded', () => { | ||
policy.type = 'personal'; | ||
transactionViolations = [futureDateViolation]; | ||
const result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policy, policyTags, policyCategories, false); | ||
expect(result.value).not.toContainEqual(futureDateViolation); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rewrite this to be based on whether the policy is team or not
Explanation of Change
Fixed Issues
$ #54510
PROPOSAL: #54510 (comment)
Tests
Precondition:
Steps:
Offline tests
Same as above
QA Steps
Precondition:
Steps:
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Screen.Recording.2024-12-27.at.12.37.14.mov
Android: mWeb Chrome
Screen.Recording.2024-12-27.at.12.38.46.mov
iOS: Native
Screen.Recording.2024-12-27.at.12.40.46.mov
iOS: mWeb Safari
Screen.Recording.2024-12-27.at.12.41.54.mov
MacOS: Chrome / Safari
Screen.Recording.2024-12-27.at.12.15.54.mov
MacOS: Desktop
Screen.Recording.2024-12-27.at.12.42.34.mov