From 50392ae992232701ec93d8f01440c97a8cce0e75 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 9 Dec 2024 16:44:40 +0300 Subject: [PATCH] added comments and tests --- src/libs/PolicyUtils.ts | 1 + tests/unit/PolicyUtilsTest.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 641969ce1a6e..8faa0db3b7fc 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -69,6 +69,7 @@ Onyx.connect({ /** * Filter out the active policies, which will exclude policies with pending deletion + * and policies the current user doesn't belong to. * These are policies that we can use to create reports with in NewDot. */ function getActivePolicies(policies: OnyxCollection | null, currentUserLogin: string | undefined): Policy[] { diff --git a/tests/unit/PolicyUtilsTest.ts b/tests/unit/PolicyUtilsTest.ts index 71830443063a..c37d7970f1cf 100644 --- a/tests/unit/PolicyUtilsTest.ts +++ b/tests/unit/PolicyUtilsTest.ts @@ -1,10 +1,24 @@ import * as PolicyUtils from '@libs/PolicyUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {Policy} from '@src/types/onyx'; +import createCollection from '../utils/collections/createCollection'; +import createRandomPolicy from '../utils/collections/policies'; function toLocaleDigitMock(dot: string): string { return dot; } describe('PolicyUtils', () => { + describe('getActivePolicies', () => { + it("getActivePolicies should filter out policies that the current user doesn't belong to", () => { + const policies = createCollection( + (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, + (index) => ({...createRandomPolicy(index + 1), ...(!index && {role: null})} as Policy), + 2, + ); + expect(PolicyUtils.getActivePolicies(policies, undefined)).toHaveLength(1); + }); + }); describe('getRateDisplayValue', () => { it('should return an empty string for NaN', () => { const rate = PolicyUtils.getRateDisplayValue('invalid' as unknown as number, toLocaleDigitMock);