Refactor: Deprecate getPolicy (part 7)#77982
Conversation
|
@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
PR doesn’t need product input as a refactor PR. Unassigning and unsubscribing myself. |
Reviewer Checklist
Screenshots/VideosScreen.Recording.2025-12-19.at.17.54.52.mov |
| const authToken = NetworkStore.getAuthToken(); | ||
| const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID); | ||
|
|
||
| if (!authToken || !policyID) { |
There was a problem hiding this comment.
🟡 No Default Validation for workspaceAccountID Parameter (Edge Case Handling)
Why this matters: If workspaceAccountID is 0 (CONST.DEFAULT_NUMBER_ID), the function will proceed with potentially invalid Onyx keys like SHARED_NVP_PRIVATE_DOMAIN_MEMBER0 which could cause:
- Silent failures when writing to Onyx
- Data being written to unexpected keys
- Difficult-to-debug issues
Suggested fix:
if (!authToken || !policyID || !workspaceAccountID) {
return;
}There was a problem hiding this comment.
@ikevin127 I can make this change, but I would not like to make changes related to logic as I want to make the changes as minimal as possible.
cc @tgolen for the opinion.
There was a problem hiding this comment.
I agree on keeping the scope small and not making that change in this PR.
|
|
||
| function configureExpensifyCardsForPolicy(policyID: string, bankAccountID?: number) { | ||
| function configureExpensifyCardsForPolicy(policyID: string, workspaceAccountID: number, bankAccountID?: number) { | ||
| if (!bankAccountID) { |
There was a problem hiding this comment.
🧪 Test Coverage Gap (Testing)File: The removed test section ( Why this matters: If someone accidentally removes the Suggested addition: describe('workspaceAccountID handling', () => {
it('uses policy workspaceAccountID for building expensify cards key', async () => {
const policyWithWorkspaceID = {
...mockPolicy,
workspaceAccountID: 456,
};
mockUsePolicy.mockReturnValue(policyWithWorkspaceID);
mockIsPolicyAdmin.mockReturnValue(true);
const workspaceCardsKey = `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}456_${CONST.EXPENSIFY_CARD.BANK}` as OnyxKey;
mockUseWorkspaceCardList.mockReturnValue({[workspaceCardsKey]: {123: mockCard}});
const {result} = renderHook(() => useGetExpensifyCardFromReportAction({reportAction: createMockReportAction(), policyID: 'policy123'}));
await waitForBatchedUpdatesWithAct();
expect(result.current).toEqual(mockCard);
});
it('uses DEFAULT_NUMBER_ID when policy has no workspaceAccountID', async () => {
const policyWithoutWorkspaceID = {
...mockPolicy,
workspaceAccountID: undefined,
};
mockUsePolicy.mockReturnValue(policyWithoutWorkspaceID);
mockIsPolicyAdmin.mockReturnValue(true);
const workspaceCardsKey = `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${CONST.DEFAULT_NUMBER_ID}_${CONST.EXPENSIFY_CARD.BANK}` as OnyxKey;
mockUseWorkspaceCardList.mockReturnValue({[workspaceCardsKey]: {123: mockCard}});
const {result} = renderHook(() => useGetExpensifyCardFromReportAction({reportAction: createMockReportAction(), policyID: 'policy123'}));
await waitForBatchedUpdatesWithAct();
expect(result.current).toEqual(mockCard);
});
}); |
ikevin127
left a comment
There was a problem hiding this comment.
🟢 LGTM - Couple of non-blocking issues / comments to be addressed by the author if they see fit 🙌
Co-authored-by: Kevin Brian Bader <56457735+ikevin127@users.noreply.github.com>
|
@shubham1206agra This picked up a conflict |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/tgolen in version: 9.2.90-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.2.90-2 🚀
|
Explanation of Change
Fixed Issues
$ #66397
Tests
Offline tests
Same as Tests
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Screen.Recording.2025-12-18.at.6.56.12.PM.mov