Skip to content

Commit

Permalink
added comments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FitseTLT committed Dec 9, 2024
1 parent ae7dd9e commit 50392ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Policy> | null, currentUserLogin: string | undefined): Policy[] {
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/PolicyUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -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<Policy>(
(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);
Expand Down

0 comments on commit 50392ae

Please sign in to comment.