-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Fix] Create Expense - Submits To Display Name Missing #57426
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
Merged
grgia
merged 6 commits into
Expensify:main
from
callstack-internal:JKobrynski/fix/56609-display-name-missing
Mar 5, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1872d70
fix the condition in getManagerAccountID
JKobrynski c7288ed
Merge remote-tracking branch 'upstream/main' into JKobrynski/fix/5660…
JKobrynski 8bf4885
Merge remote-tracking branch 'upstream/main' into JKobrynski/fix/5660…
JKobrynski b75a0f2
Merge remote-tracking branch 'upstream/main' into JKobrynski/fix/5660…
JKobrynski 982c6d4
add unit tests for getManagerAccountID util
JKobrynski 4ce0268
Merge remote-tracking branch 'upstream/main' into JKobrynski/fix/5660…
JKobrynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import Onyx from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import DateUtils from '@libs/DateUtils'; | ||
import {getActivePolicies, getPolicyNameByID, getRateDisplayValue, getSubmitToAccountID, getUnitRateValue, shouldShowPolicy} from '@libs/PolicyUtils'; | ||
import {getActivePolicies, getManagerAccountID, getPolicyNameByID, getRateDisplayValue, getSubmitToAccountID, getUnitRateValue, shouldShowPolicy} from '@libs/PolicyUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {PersonalDetailsList, Policy, PolicyEmployeeList, Report, Transaction} from '@src/types/onyx'; | ||
|
@@ -20,6 +20,12 @@ const CARLOS_ACCOUNT_ID = 1; | |
function toLocaleDigitMock(dot: string): string { | ||
return dot; | ||
} | ||
const GENERATED_ACCOUNT_ID = '555555'; | ||
|
||
jest.mock('@libs/UserUtils', () => ({ | ||
// generateAccountID: () => GENERATED_ACCOUNT_ID, | ||
generateAccountID: jest.fn().mockReturnValue(GENERATED_ACCOUNT_ID), | ||
})); | ||
|
||
const testDate = DateUtils.getDBTime(); | ||
const employeeList: PolicyEmployeeList = { | ||
|
@@ -67,19 +73,22 @@ const categoryapprover2AccountID = 4; | |
const tagapprover1AccountID = 5; | ||
const tagapprover2AccountID = 6; | ||
const ownerAccountID = 7; | ||
const employeeEmail = '[email protected]'; | ||
const adminEmail = '[email protected]'; | ||
const categoryApprover1Email = '[email protected]'; | ||
|
||
const personalDetails: PersonalDetailsList = { | ||
'1': { | ||
accountID: adminAccountID, | ||
login: '[email protected]', | ||
login: adminEmail, | ||
}, | ||
'2': { | ||
accountID: employeeAccountID, | ||
login: '[email protected]', | ||
login: employeeEmail, | ||
}, | ||
'3': { | ||
accountID: categoryapprover1AccountID, | ||
login: '[email protected]', | ||
login: categoryApprover1Email, | ||
}, | ||
'4': { | ||
accountID: categoryapprover2AccountID, | ||
|
@@ -499,4 +508,85 @@ describe('PolicyUtils', () => { | |
expect(getPolicyNameByID('1')).toBe('1'); | ||
}); | ||
}); | ||
|
||
describe('getManagerAccountID', () => { | ||
beforeEach(() => { | ||
wrapOnyxWithWaitForBatchedUpdates(Onyx); | ||
Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetails); | ||
}); | ||
afterEach(async () => { | ||
await Onyx.clear(); | ||
await waitForBatchedUpdatesWithAct(); | ||
}); | ||
|
||
it('should return default approver for personal workspaces', () => { | ||
const policy: Policy = { | ||
...createRandomPolicy(0), | ||
type: CONST.POLICY.TYPE.PERSONAL, | ||
approver: categoryApprover1Email, | ||
}; | ||
const report: Report = { | ||
...createRandomReport(0), | ||
}; | ||
const result = getManagerAccountID(policy, report); | ||
|
||
expect(result).toBe(categoryapprover1AccountID); | ||
}); | ||
|
||
it('should return -1 if there is no employee or default approver', () => { | ||
const policy: Policy = { | ||
...createRandomPolicy(0), | ||
type: CONST.POLICY.TYPE.TEAM, | ||
approvalMode: undefined, | ||
approver: undefined, | ||
owner: '', | ||
}; | ||
const report: Report = { | ||
...createRandomReport(0), | ||
}; | ||
|
||
const result = getManagerAccountID(policy, report); | ||
|
||
expect(result).toBe(-1); | ||
}); | ||
|
||
it('should return submitsTo account ID', () => { | ||
const policy: Policy = { | ||
...createRandomPolicy(0), | ||
type: CONST.POLICY.TYPE.TEAM, | ||
approvalMode: undefined, | ||
employeeList: { | ||
[employeeEmail]: { | ||
email: employeeEmail, | ||
submitsTo: adminEmail, | ||
}, | ||
}, | ||
}; | ||
const report: Report = { | ||
...createRandomReport(0), | ||
ownerAccountID: employeeAccountID, | ||
}; | ||
|
||
const result = getManagerAccountID(policy, report); | ||
|
||
expect(result).toBe(adminAccountID); | ||
}); | ||
|
||
it('should return the default approver', () => { | ||
const policy: Policy = { | ||
...createRandomPolicy(0), | ||
type: CONST.POLICY.TYPE.TEAM, | ||
approvalMode: undefined, | ||
approver: categoryApprover1Email, | ||
}; | ||
const report: Report = { | ||
...createRandomReport(0), | ||
ownerAccountID: employeeAccountID, | ||
}; | ||
|
||
const result = getManagerAccountID(policy, report); | ||
|
||
expect(result).toBe(categoryapprover1AccountID); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@JKobrynski I think this is a good candidate for a unit test.
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.
All right, I'm on it!