Skip to content

Commit 0a97e9f

Browse files
authored
tests
1 parent 85c646c commit 0a97e9f

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

tests/actions/IOUTest.ts

+76-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {OnyxCollection, OnyxEntry, OnyxInputValue} from 'react-native-onyx'
44
import Onyx from 'react-native-onyx';
55
import {
66
cancelPayment,
7+
canIOUBePaid,
78
deleteMoneyRequest,
89
payMoneyRequest,
910
putOnHold,
@@ -19,7 +20,7 @@ import {
1920
updateMoneyRequestAmountAndCurrency,
2021
updateMoneyRequestCategory,
2122
} from '@libs/actions/IOU';
22-
import {createWorkspace, generatePolicyID, setWorkspaceApprovalMode} from '@libs/actions/Policy/Policy';
23+
import {createWorkspace, deleteWorkspace, generatePolicyID, setWorkspaceApprovalMode} from '@libs/actions/Policy/Policy';
2324
import {addComment, deleteReport, notifyNewAction, openReport} from '@libs/actions/Report';
2425
import {clearAllRelatedReportActionErrors} from '@libs/actions/ReportActions';
2526
import {subscribeToUserEvents} from '@libs/actions/User';
@@ -3484,6 +3485,7 @@ describe('actions/IOU', () => {
34843485
const merchant = 'NASDAQ';
34853486
let expenseReport: OnyxEntry<Report>;
34863487
let chatReport: OnyxEntry<Report>;
3488+
let policy: OnyxEntry<Policy>;
34873489
return waitForBatchedUpdates()
34883490
.then(() => {
34893491
createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace");
@@ -3498,7 +3500,6 @@ describe('actions/IOU', () => {
34983500
callback: (allReports) => {
34993501
Onyx.disconnect(connection);
35003502
chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);
3501-
35023503
resolve();
35033504
},
35043505
});
@@ -3525,6 +3526,21 @@ describe('actions/IOU', () => {
35253526
}
35263527
return waitForBatchedUpdates();
35273528
})
3529+
.then(
3530+
() =>
3531+
new Promise<void>((resolve) => {
3532+
const connection = Onyx.connect({
3533+
key: ONYXKEYS.COLLECTION.POLICY,
3534+
waitForCollectionCallback: true,
3535+
callback: (allPolicies) => {
3536+
Onyx.disconnect(connection);
3537+
policy = Object.values(allPolicies ?? {}).find((p): p is OnyxEntry<Policy> => p?.name === "Carlos's Workspace");
3538+
expect(policy).toBeTruthy();
3539+
resolve();
3540+
},
3541+
});
3542+
}),
3543+
)
35283544
.then(
35293545
() =>
35303546
new Promise<void>((resolve) => {
@@ -3534,6 +3550,10 @@ describe('actions/IOU', () => {
35343550
callback: (allReports) => {
35353551
Onyx.disconnect(connection);
35363552
expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE);
3553+
3554+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], true)).toBe(true);
3555+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], false)).toBe(false);
3556+
35373557
Onyx.merge(`report_${expenseReport?.reportID}`, {
35383558
statusNum: 0,
35393559
stateNum: 0,
@@ -3553,6 +3573,9 @@ describe('actions/IOU', () => {
35533573
Onyx.disconnect(connection);
35543574
expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE);
35553575

3576+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], true)).toBe(false);
3577+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], false)).toBe(false);
3578+
35563579
// Verify report is a draft
35573580
expect(expenseReport?.stateNum).toBe(0);
35583581
expect(expenseReport?.statusNum).toBe(0);
@@ -3577,9 +3600,37 @@ describe('actions/IOU', () => {
35773600
Onyx.disconnect(connection);
35783601
expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE);
35793602

3603+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], false)).toBe(false);
3604+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], true)).toBe(true);
3605+
35803606
// Report is closed since the default policy settings is Submit and Close
35813607
expect(expenseReport?.stateNum).toBe(2);
35823608
expect(expenseReport?.statusNum).toBe(2);
3609+
resolve();
3610+
},
3611+
});
3612+
}),
3613+
)
3614+
.then(() => {
3615+
if (policy) {
3616+
deleteWorkspace(policy.id, policy.name);
3617+
}
3618+
return waitForBatchedUpdates();
3619+
})
3620+
.then(
3621+
() =>
3622+
new Promise<void>((resolve) => {
3623+
const connection = Onyx.connect({
3624+
key: ONYXKEYS.COLLECTION.POLICY,
3625+
waitForCollectionCallback: true,
3626+
callback: (allPolicies) => {
3627+
Onyx.disconnect(connection);
3628+
policy = Object.values(allPolicies ?? {}).find((p): p is OnyxEntry<Policy> => p?.name === "Carlos's Workspace");
3629+
3630+
expect(policy).toBeTruthy();
3631+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], false)).toBe(false);
3632+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], true)).toBe(true);
3633+
35833634
resolve();
35843635
},
35853636
});
@@ -3592,6 +3643,7 @@ describe('actions/IOU', () => {
35923643
const merchant = 'NASDAQ';
35933644
let expenseReport: OnyxEntry<Report>;
35943645
let chatReport: OnyxEntry<Report>;
3646+
let policy: OnyxEntry<Policy>;
35953647
return waitForBatchedUpdates()
35963648
.then(() => {
35973649
createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace");
@@ -3606,7 +3658,6 @@ describe('actions/IOU', () => {
36063658
callback: (allReports) => {
36073659
Onyx.disconnect(connection);
36083660
chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);
3609-
36103661
resolve();
36113662
},
36123663
});
@@ -3633,6 +3684,21 @@ describe('actions/IOU', () => {
36333684
}
36343685
return waitForBatchedUpdates();
36353686
})
3687+
.then(
3688+
() =>
3689+
new Promise<void>((resolve) => {
3690+
const connection = Onyx.connect({
3691+
key: ONYXKEYS.COLLECTION.POLICY,
3692+
waitForCollectionCallback: true,
3693+
callback: (allPolicies) => {
3694+
Onyx.disconnect(connection);
3695+
policy = Object.values(allPolicies ?? {}).find((p): p is OnyxEntry<Policy> => p?.name === "Carlos's Workspace");
3696+
expect(policy).toBeTruthy();
3697+
resolve();
3698+
},
3699+
});
3700+
}),
3701+
)
36363702
.then(
36373703
() =>
36383704
new Promise<void>((resolve) => {
@@ -3642,6 +3708,10 @@ describe('actions/IOU', () => {
36423708
callback: (allReports) => {
36433709
Onyx.disconnect(connection);
36443710
expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE);
3711+
3712+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], false)).toBe(false);
3713+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], true)).toBe(true);
3714+
36453715
Onyx.merge(`report_${expenseReport?.reportID}`, {
36463716
statusNum: 0,
36473717
stateNum: 0,
@@ -3686,6 +3756,9 @@ describe('actions/IOU', () => {
36863756
Onyx.disconnect(connection);
36873757
expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE);
36883758

3759+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], false)).toBe(false);
3760+
expect(canIOUBePaid(expenseReport, chatReport, policy, [], true)).toBe(false);
3761+
36893762
// Report was submitted with some fail
36903763
expect(expenseReport?.stateNum).toBe(0);
36913764
expect(expenseReport?.statusNum).toBe(0);

0 commit comments

Comments
 (0)