@@ -6396,6 +6396,60 @@ describe('actions/IOU', () => {
63966396 });
63976397 });
63986398 });
6399+
6400+ it('should remove all existing category violations when the transaction "Category" is unset', async () => {
6401+ const transactionID = '1';
6402+ const policyID = '2';
6403+ const transactionThreadReportID = '3';
6404+ const category = '';
6405+ const fakePolicy: Policy = {
6406+ ...createRandomPolicy(Number(policyID)),
6407+ requiresCategory: true,
6408+ };
6409+ await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
6410+ amount: 100,
6411+ transactionID,
6412+ });
6413+ await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`, [
6414+ {
6415+ type: CONST.VIOLATION_TYPES.VIOLATION,
6416+ name: CONST.VIOLATIONS.CATEGORY_OUT_OF_POLICY,
6417+ data: {},
6418+ showInReview: true,
6419+ },
6420+ ]);
6421+ await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
6422+ await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {reportID: transactionThreadReportID});
6423+
6424+ // When updating a money request category
6425+ updateMoneyRequestCategory({
6426+ transactionID,
6427+ transactionThreadReportID,
6428+ category,
6429+ policy: fakePolicy,
6430+ policyTagList: undefined,
6431+ policyCategories: undefined,
6432+ policyRecentlyUsedCategories: [],
6433+ currentUserAccountIDParam: 123,
6434+ currentUserEmailParam: 'existing@example.com',
6435+ isASAPSubmitBetaEnabled: false,
6436+ });
6437+
6438+ await waitForBatchedUpdates();
6439+
6440+ // Any existing category violations will be removed, leaving only the MISSING_CATEGORY violation in the end
6441+ await new Promise<void>((resolve) => {
6442+ const connection = Onyx.connect({
6443+ key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`,
6444+ callback: (transactionViolations) => {
6445+ Onyx.disconnect(connection);
6446+ expect(transactionViolations).toHaveLength(1);
6447+ expect(transactionViolations?.at(0)?.name).toEqual(CONST.VIOLATIONS.MISSING_CATEGORY);
6448+ resolve();
6449+ },
6450+ });
6451+ });
6452+ });
63996453 });
64006454
64016455 describe('setDraftSplitTransaction', () => {
0 commit comments