@@ -1843,7 +1843,7 @@ describe('actions/Policy', () => {
18431843
18441844 const policyID = Policy . generatePolicyID ( ) ;
18451845
1846- Policy . createDraftInitialWorkspace ( { choice : CONST . ONBOARDING_CHOICES . TRACK_WORKSPACE } , WORKSPACE_NAME , policyID , false , CONST . CURRENCY . EUR ) ;
1846+ Policy . createDraftInitialWorkspace ( { choice : CONST . ONBOARDING_CHOICES . TRACK_WORKSPACE } , WORKSPACE_NAME , ESH_ACCOUNT_ID , ESH_EMAIL , policyID , false , CONST . CURRENCY . EUR ) ;
18471847 await waitForBatchedUpdates ( ) ;
18481848
18491849 const draft = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . POLICY_DRAFTS } ${ policyID } ` ) ;
@@ -1853,6 +1853,69 @@ describe('actions/Policy', () => {
18531853 expect ( draft ?. harvesting ?. enabled ) . toBe ( true ) ;
18541854 expect ( draft ?. outputCurrency ) . toBe ( CONST . CURRENCY . EUR ) ;
18551855 } ) ;
1856+
1857+ it ( 'should set owner and ownerAccountID from explicit parameters' , async ( ) => {
1858+ // Set Onyx session to a DIFFERENT accountID/email to verify the explicit parameters are used
1859+ await Onyx . set ( ONYXKEYS . SESSION , { email : ESH_EMAIL , accountID : ESH_ACCOUNT_ID } ) ;
1860+ await waitForBatchedUpdates ( ) ;
1861+
1862+ const customAccountID = 999 ;
1863+ const customEmail = 'custom@example.com' ;
1864+ const policyID = Policy . generatePolicyID ( ) ;
1865+
1866+ Policy . createDraftInitialWorkspace ( { choice : CONST . ONBOARDING_CHOICES . MANAGE_TEAM } , WORKSPACE_NAME , customAccountID , customEmail , policyID ) ;
1867+ await waitForBatchedUpdates ( ) ;
1868+
1869+ const draft = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . POLICY_DRAFTS } ${ policyID } ` ) ;
1870+
1871+ // Verify owner and ownerAccountID use the explicit parameters, not the Onyx session
1872+ expect ( draft ?. owner ) . toBe ( customEmail ) ;
1873+ expect ( draft ?. ownerAccountID ) . toBe ( customAccountID ) ;
1874+
1875+ // Verify that the Onyx session values are NOT used
1876+ expect ( draft ?. owner ) . not . toBe ( ESH_EMAIL ) ;
1877+ expect ( draft ?. ownerAccountID ) . not . toBe ( ESH_ACCOUNT_ID ) ;
1878+ } ) ;
1879+
1880+ it ( 'should set approver from explicit currentUserEmail parameter' , async ( ) => {
1881+ await Onyx . set ( ONYXKEYS . SESSION , { email : ESH_EMAIL , accountID : ESH_ACCOUNT_ID } ) ;
1882+ await waitForBatchedUpdates ( ) ;
1883+
1884+ const customAccountID = 888 ;
1885+ const customEmail = 'approver@example.com' ;
1886+ const policyID = Policy . generatePolicyID ( ) ;
1887+
1888+ Policy . createDraftInitialWorkspace ( { choice : CONST . ONBOARDING_CHOICES . MANAGE_TEAM } , WORKSPACE_NAME , customAccountID , customEmail , policyID ) ;
1889+ await waitForBatchedUpdates ( ) ;
1890+
1891+ const draft = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . POLICY_DRAFTS } ${ policyID } ` ) ;
1892+
1893+ expect ( draft ?. approver ) . toBe ( customEmail ) ;
1894+ expect ( draft ?. approver ) . not . toBe ( ESH_EMAIL ) ;
1895+ } ) ;
1896+
1897+ it ( 'should set employeeList using explicit currentUserEmail parameter' , async ( ) => {
1898+ await Onyx . set ( ONYXKEYS . SESSION , { email : ESH_EMAIL , accountID : ESH_ACCOUNT_ID } ) ;
1899+ await waitForBatchedUpdates ( ) ;
1900+
1901+ const customAccountID = 777 ;
1902+ const customEmail = 'employee@example.com' ;
1903+ const policyID = Policy . generatePolicyID ( ) ;
1904+
1905+ Policy . createDraftInitialWorkspace ( { choice : CONST . ONBOARDING_CHOICES . MANAGE_TEAM } , WORKSPACE_NAME , customAccountID , customEmail , policyID ) ;
1906+ await waitForBatchedUpdates ( ) ;
1907+
1908+ const draft = await getOnyxValue ( `${ ONYXKEYS . COLLECTION . POLICY_DRAFTS } ${ policyID } ` ) ;
1909+
1910+ // Verify the employeeList uses the explicit email parameter
1911+ expect ( draft ?. employeeList ?. [ customEmail ] ) . toBeDefined ( ) ;
1912+ expect ( draft ?. employeeList ?. [ customEmail ] ?. email ) . toBe ( customEmail ) ;
1913+ expect ( draft ?. employeeList ?. [ customEmail ] ?. submitsTo ) . toBe ( customEmail ) ;
1914+ expect ( draft ?. employeeList ?. [ customEmail ] ?. role ) . toBe ( CONST . POLICY . ROLE . ADMIN ) ;
1915+
1916+ // Verify the Onyx session email is NOT used in employeeList
1917+ expect ( draft ?. employeeList ?. [ ESH_EMAIL ] ) . toBeUndefined ( ) ;
1918+ } ) ;
18561919 } ) ;
18571920
18581921 describe ( 'createDraftWorkspace' , ( ) => {
0 commit comments