Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 58 additions & 58 deletions tests/actions/ReportPreviewActionUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ describe('getReportPreviewAction', () => {
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 general: createMock<T> usage is consistent and safe

Same sanctioned createMock<T> pattern as the other PRs, including createMock<NetSuiteConnection>({}) for the connection fixture. The partials are type-checked against the real models, which is exactly what surfaced the two bugs above.

This is the direction we wanted for the series, nothing to change ✅

it('getReportPreviewAction should return ADD_EXPENSE action for report preview with no transactions', async () => {
const report = {
reportID: REPORT_ID,
const report = createMock<Report>({
reportID: `${REPORT_ID}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 tests/actions/ReportPreviewActionUtilsTest.ts:75: reportID string fix is correct

REPORT_ID is 1 (a number, line 40) but Report.reportID is a string, so the old reportID: REPORT_ID was a number-vs-string mismatch that as unknown as Report hid. Wrapping it as `${REPORT_ID}` is the right fix.

The report is merged under the same key and the assertions check the returned action, not reportID, so no behavior change - correct ✅

type: CONST.REPORT.TYPE.EXPENSE,
ownerAccountID: CURRENT_USER_ACCOUNT_ID,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
isWaitingOnBankAccount: false,
} as unknown as Report;
});
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

const policy = createRandomPolicy(0, CONST.POLICY.TYPE.CORPORATE);
Expand Down Expand Up @@ -114,12 +114,12 @@ describe('getReportPreviewAction', () => {
policy.harvesting.enabled = false;
}
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

// Simulate how components use a hook to pass the isReportArchived parameter
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
Expand Down Expand Up @@ -207,12 +207,12 @@ describe('getReportPreviewAction', () => {
}
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
await Onyx.merge(ONYXKEYS.SESSION, {email: MANAGER_EMAIL, accountID: MANAGER_ACCOUNT_ID});
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -254,12 +254,12 @@ describe('getReportPreviewAction', () => {
}
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
await Onyx.merge(ONYXKEYS.SESSION, {email: ADMIN_EMAIL, accountID: ADMIN_ACCOUNT_ID});
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -300,12 +300,12 @@ describe('getReportPreviewAction', () => {

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

// Simulate how components use a hook to pass the isReportArchived parameter
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
Expand Down Expand Up @@ -341,13 +341,13 @@ describe('getReportPreviewAction', () => {
policy.harvesting.enabled = false;
}
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
status: CONST.TRANSACTION.STATUS.PENDING,
amount: 10,
merchant: 'Merchant',
date: '2025-01-01',
} as unknown as Transaction;
created: '2025-01-01',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 tests/actions/ReportPreviewActionUtilsTest.ts:349 and :786: good catch on date to created

Nice, this is a real fixture bug the old cast was hiding. date is not a top-level Transaction field (the only date in the type is on ReservationTimeDetails, the trip reservation object), so {date: '2025-01-01'} as unknown as Transaction was setting a property that production code never reads.

createMock<Transaction> correctly rejected it, and created is the right field (src/types/onyx/Transaction.ts:524). I checked that ReportPreviewActionUtils does not read created, so both pending tests still exercise the same path, they just have a valid date now instead of a dead one.

No change needed, just confirming it is correct ✅

});

// Simulate how components use a hook to pass the isReportArchived parameter
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
Expand Down Expand Up @@ -590,10 +590,10 @@ describe('getReportPreviewAction', () => {
}
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

const transaction = {
const transaction = createMock<Transaction>({
transactionID: TRANSACTION_ID,
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const violations = {
[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${TRANSACTION_ID}`]: [
Expand Down Expand Up @@ -650,13 +650,13 @@ describe('getReportPreviewAction', () => {
}
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);

const transaction = {
const transaction = createMock<Transaction>({
transactionID: TRANSACTION_ID,
reportID: `${REPORT_ID}`,
iouRequestType: CONST.IOU.REQUEST_TYPE.SCAN,
receipt: {state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED},
merchant: '',
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));

Expand Down Expand Up @@ -696,12 +696,12 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -738,12 +738,12 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
receipt: {
state: CONST.IOU.RECEIPT_STATE.SCANNING,
},
} as unknown as Transaction;
});

expect(
getReportPreviewAction({
Expand Down Expand Up @@ -778,13 +778,13 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
status: CONST.TRANSACTION.STATUS.PENDING,
amount: 10,
merchant: 'Merchant',
date: '2025-01-01',
} as unknown as Transaction;
created: '2025-01-01',
});

expect(
getReportPreviewAction({
Expand Down Expand Up @@ -817,12 +817,12 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

expect(
getReportPreviewAction({
Expand Down Expand Up @@ -856,12 +856,12 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

expect(
getReportPreviewAction({
Expand Down Expand Up @@ -937,9 +937,9 @@ describe('getReportPreviewAction', () => {
policy.reimbursementChoice = CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -1023,9 +1023,9 @@ describe('getReportPreviewAction', () => {
policy.reimbursementChoice = CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

await waitForBatchedUpdatesWithAct();
// Should not show PAY button for zero amount Expenses
Expand Down Expand Up @@ -1064,9 +1064,9 @@ describe('getReportPreviewAction', () => {
jest.mocked(hasOnlyNonReimbursableTransactions).mockReturnValueOnce(true);

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -1106,9 +1106,9 @@ describe('getReportPreviewAction', () => {
jest.mocked(getValidConnectedIntegration).mockReturnValueOnce(undefined);

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -1147,9 +1147,9 @@ describe('getReportPreviewAction', () => {
invoiceReceiverPolicy.role = CONST.POLICY.ROLE.ADMIN;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -1202,9 +1202,9 @@ describe('getReportPreviewAction', () => {
const invoiceReceiverPolicy = createRandomPolicy(0);
invoiceReceiverPolicy.role = CONST.POLICY.ROLE.ADMIN;

const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${PARENT_REPORT_ID}`, parentReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
Expand Down Expand Up @@ -1252,9 +1252,9 @@ describe('getReportPreviewAction', () => {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`, {
private_isArchived: new Date().toString(),
});
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
expect(
Expand Down Expand Up @@ -1290,9 +1290,9 @@ describe('getReportPreviewAction', () => {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`, {
private_isArchived: new Date().toString(),
});
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

// Simulate how components determined if a chat report is archived by using this hook
const {result: isChatReportArchived} = renderHook(() => useReportIsArchived(report?.chatReportID));
Expand Down Expand Up @@ -1325,12 +1325,12 @@ describe('getReportPreviewAction', () => {

const policy = createRandomPolicy(0);
policy.type = CONST.POLICY.TYPE.CORPORATE;
policy.connections = {[CONST.POLICY.CONNECTIONS.NAME.NETSUITE]: {} as NetSuiteConnection};
policy.connections = {[CONST.POLICY.CONNECTIONS.NAME.NETSUITE]: createMock<NetSuiteConnection>({})};
policy.reimbursementChoice = CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO;
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -1365,9 +1365,9 @@ describe('getReportPreviewAction', () => {
policy.type = CONST.POLICY.TYPE.CORPORATE;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));

Expand Down Expand Up @@ -1412,9 +1412,9 @@ describe('getReportPreviewAction', () => {
}

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));

Expand Down Expand Up @@ -1459,9 +1459,9 @@ describe('getReportPreviewAction', () => {
}

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));

Expand Down Expand Up @@ -1507,12 +1507,12 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -1554,12 +1554,12 @@ describe('getReportPreviewAction', () => {
policy.preventSelfApproval = false;

await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
const transaction = {
const transaction = createMock<Transaction>({
reportID: `${REPORT_ID}`,
amount: 100,
merchant: 'Test Merchant',
created: '2025-01-01',
} as unknown as Transaction;
});

const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
await waitForBatchedUpdatesWithAct();
Expand Down
Loading