Skip to content

Commit 5ed6a7b

Browse files
committed
Fix - Double violation briefly visible when removing a disabled category from report
1 parent 76f127b commit 5ed6a7b

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

tests/actions/IOUTest.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import * as API from '@src/libs/API';
8686
import DateUtils from '@src/libs/DateUtils';
8787
import ONYXKEYS from '@src/ONYXKEYS';
8888
import ROUTES from '@src/ROUTES';
89-
import type {OriginalMessageIOU, PersonalDetailsList, Policy, PolicyTagLists, Report, ReportNameValuePairs, SearchResults} from '@src/types/onyx';
89+
import type {OriginalMessageIOU, PersonalDetailsList, Policy, PolicyTagLists, Report, ReportNameValuePairs, SearchResults, TransactionViolations} from '@src/types/onyx';
9090
import type {Accountant, Attendee} from '@src/types/onyx/IOU';
9191
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
9292
import type {Participant, ReportCollectionDataSet} from '@src/types/onyx/Report';
@@ -6299,6 +6299,60 @@ describe('actions/IOU', () => {
62996299
});
63006300
});
63016301
});
6302+
6303+
it('should remove all existing category violations when the transaction "Category" is unset', async () => {
6304+
const transactionID = '1';
6305+
const policyID = '2';
6306+
const transactionThreadReportID = '3';
6307+
const category = '';
6308+
const fakePolicy: Policy = {
6309+
...createRandomPolicy(Number(policyID)),
6310+
requiresCategory: true,
6311+
};
6312+
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
6313+
amount: 100,
6314+
transactionID,
6315+
});
6316+
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, [
6317+
{
6318+
type: CONST.VIOLATION_TYPES.VIOLATION,
6319+
name: CONST.VIOLATIONS.CATEGORY_OUT_OF_POLICY,
6320+
data: {},
6321+
showInReview: true,
6322+
},
6323+
]);
6324+
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
6325+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {reportID: transactionThreadReportID});
6326+
6327+
// When updating a money request category
6328+
updateMoneyRequestCategory({
6329+
transactionID,
6330+
transactionThreadReportID,
6331+
category,
6332+
policy: fakePolicy,
6333+
policyTagList: undefined,
6334+
policyCategories: undefined,
6335+
policyRecentlyUsedCategories: [],
6336+
currentUserAccountIDParam: 123,
6337+
currentUserEmailParam: 'existing@example.com',
6338+
isASAPSubmitBetaEnabled: false,
6339+
});
6340+
6341+
await waitForBatchedUpdates();
6342+
6343+
// Any existing category violations will be removed, leaving only the MISSING_CATEGORY violation in the end
6344+
await new Promise<void>((resolve) => {
6345+
const connection = Onyx.connect({
6346+
key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
6347+
callback: (transactionViolations) => {
6348+
Onyx.disconnect(connection);
6349+
expect(transactionViolations).toHaveLength(1);
6350+
expect((transactionViolations as unknown as TransactionViolations)[0].name).toEqual(CONST.VIOLATIONS.MISSING_CATEGORY);
6351+
resolve();
6352+
},
6353+
});
6354+
});
6355+
});
63026356
});
63036357

63046358
describe('setDraftSplitTransaction', () => {

0 commit comments

Comments
 (0)