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
4 changes: 2 additions & 2 deletions src/libs/Violations/ViolationsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import reject from 'lodash/reject';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import {getDecodedCategoryName} from '@libs/CategoryUtils';
import {getDecodedCategoryName, isCategoryMissing} from '@libs/CategoryUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import DateUtils from '@libs/DateUtils';
import {isReceiptError} from '@libs/ErrorUtils';
Expand Down Expand Up @@ -264,7 +264,7 @@ const ViolationsUtils = {
const isCategoryInPolicy = categoryKey ? policyCategories?.[categoryKey]?.enabled : false;

// Add 'categoryOutOfPolicy' violation if category is not in policy
if (!hasCategoryOutOfPolicyViolation && categoryKey && !isCategoryInPolicy) {
if (!hasCategoryOutOfPolicyViolation && !isCategoryMissing(categoryKey) && !isCategoryInPolicy) {
newTransactionViolations.push({name: 'categoryOutOfPolicy', type: CONST.VIOLATION_TYPES.VIOLATION});
}

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/ViolationUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ describe('getViolationsOnyxData', () => {
expect(result.value).not.toContainEqual(missingCategoryViolation);
});

it('should not add categoryOutOfPolicy violation when category is Uncategorized', () => {
transaction.category = 'Uncategorized';
const result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policy, policyTags, policyCategories, false, false);
expect(result.value).not.toContainEqual(categoryOutOfPolicyViolation);
});

it('should not add categoryOutOfPolicy violation when category is none', () => {
transaction.category = 'none';
const result = ViolationsUtils.getViolationsOnyxData(transaction, transactionViolations, policy, policyTags, policyCategories, false, false);
expect(result.value).not.toContainEqual(categoryOutOfPolicyViolation);
});

it('should add categoryOutOfPolicy violation to existing violations if they exist', () => {
transaction.category = 'Bananas';
transaction.amount = 1000000;
Expand Down
Loading