Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 1 addition & 6 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 745 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -838,7 +838,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 841 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -852,7 +852,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 855 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -861,7 +861,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 864 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -875,7 +875,7 @@
});

let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStepDeprecated>> = {};
Onyx.connect({

Check warning on line 878 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.NEXT_STEP,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -887,14 +887,14 @@
// `allRecentlyUsedTags` was moved here temporarily from `src/libs/actions/Policy/Tag.ts` during the `Deprecate Onyx.connect` refactor.
// All uses of this variable should be replaced with `useOnyx`.
let allRecentlyUsedTags: OnyxCollection<RecentlyUsedTags> = {};
Onyx.connect({

Check warning on line 890 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS,
waitForCollectionCallback: true,
callback: (val) => (allRecentlyUsedTags = val),
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 897 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -903,7 +903,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 906 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -913,7 +913,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 916 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -922,7 +922,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 925 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand Down Expand Up @@ -4762,15 +4762,10 @@
) {
const currentTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`] ?? [];
// If the amount, currency or date have been modified, we remove the duplicate violations since they would be out of date as the transaction has changed
let optimisticViolations =
const optimisticViolations =
hasModifiedAmount || hasModifiedDate || hasModifiedCurrency
? currentTransactionViolations.filter((violation) => violation.name !== CONST.VIOLATIONS.DUPLICATED_TRANSACTION)
: currentTransactionViolations;
optimisticViolations =
hasModifiedCategory && transactionChanges.category === ''
? optimisticViolations.filter((violation) => violation.name !== CONST.VIOLATIONS.CATEGORY_OUT_OF_POLICY)
: optimisticViolations;

const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(
updatedTransaction,
optimisticViolations,
Expand Down Expand Up @@ -5072,7 +5067,7 @@
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null;
let data: UpdateMoneyRequestData;
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {

Check failure on line 5070 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`isTrackExpenseReport` is deprecated. Use isTrackExpenseReportNew function instead
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
Expand Down Expand Up @@ -5173,7 +5168,7 @@
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null;
let data: UpdateMoneyRequestData;
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {

Check failure on line 5171 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`isTrackExpenseReport` is deprecated. Use isTrackExpenseReportNew function instead
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
Expand Down Expand Up @@ -5367,7 +5362,7 @@
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null;
let data: UpdateMoneyRequestData;
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {

Check failure on line 5365 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`isTrackExpenseReport` is deprecated. Use isTrackExpenseReportNew function instead
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
Expand Down Expand Up @@ -5494,7 +5489,7 @@
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null;
let data: UpdateMoneyRequestData;
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {

Check failure on line 5492 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`isTrackExpenseReport` is deprecated. Use isTrackExpenseReportNew function instead
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
Expand Down Expand Up @@ -5560,7 +5555,7 @@
}

let data: UpdateMoneyRequestData;
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {

Check failure on line 5558 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`isTrackExpenseReport` is deprecated. Use isTrackExpenseReportNew function instead
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
Expand Down Expand Up @@ -8652,7 +8647,7 @@
const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null;
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null;
let data: UpdateMoneyRequestData;
if (isTrackExpenseReport(transactionThreadReport) && isSelfDM(parentReport)) {

Check failure on line 8650 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

`isTrackExpenseReport` is deprecated. Use isTrackExpenseReportNew function instead
data = getUpdateTrackExpenseParams(transactionID, transactionThreadReportID, transactionChanges, policy);
} else {
data = getUpdateMoneyRequestParams({
Expand Down
54 changes: 0 additions & 54 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6467,60 +6467,6 @@ describe('actions/IOU', () => {
});
});
});

it('should remove all existing category violations when the transaction "Category" is unset', async () => {
const transactionID = '1';
const policyID = '2';
const transactionThreadReportID = '3';
const category = '';
const fakePolicy: Policy = {
...createRandomPolicy(Number(policyID)),
requiresCategory: true,
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
amount: 100,
transactionID,
});
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, [
{
type: CONST.VIOLATION_TYPES.VIOLATION,
name: CONST.VIOLATIONS.CATEGORY_OUT_OF_POLICY,
data: {},
showInReview: true,
},
]);
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {reportID: transactionThreadReportID});

// When updating a money request category
updateMoneyRequestCategory({
transactionID,
transactionThreadReportID,
category,
policy: fakePolicy,
policyTagList: undefined,
policyCategories: undefined,
policyRecentlyUsedCategories: [],
currentUserAccountIDParam: 123,
currentUserEmailParam: 'existing@example.com',
isASAPSubmitBetaEnabled: false,
});

await waitForBatchedUpdates();

// Any existing category violations will be removed, leaving only the MISSING_CATEGORY violation in the end
await new Promise<void>((resolve) => {
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
callback: (transactionViolations) => {
Onyx.disconnect(connection);
expect(transactionViolations).toHaveLength(1);
expect(transactionViolations?.at(0)?.name).toEqual(CONST.VIOLATIONS.MISSING_CATEGORY);
resolve();
},
});
});
});
});

describe('setDraftSplitTransaction', () => {
Expand Down
Loading