Skip to content

Commit 45be75b

Browse files
committed
fix: make params an object
1 parent bbb0ea8 commit 45be75b

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/libs/PolicyUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,14 @@ function getCustomUnitsForDuplication(
308308
policy: Policy,
309309
isDistanceRatesOptionSelected: boolean,
310310
isPerDiemOptionSelected: boolean,
311-
distanceCustomUnitID: string,
312-
perDiemCustomUnitID: string,
311+
customUnit: {
312+
distanceCustomUnitID: string,
313+
perDiemCustomUnitID: string
314+
},
313315
): Record<string, CustomUnit> | undefined {
314316
const customUnits = policy?.customUnits;
317+
const {distanceCustomUnitID, perDiemCustomUnitID} = customUnit ?? {};
318+
315319
if ((!isDistanceRatesOptionSelected && !isPerDiemOptionSelected) || !customUnits || Object.keys(customUnits).length === 0) {
316320
return undefined;
317321
}

src/libs/actions/Policy/Policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3063,7 +3063,7 @@ function buildDuplicatePolicyData(policy: Policy, options: DuplicatePolicyDataOp
30633063
name: policyName,
30643064
fieldList: isReportsOptionSelected ? policy?.fieldList : undefined,
30653065
connections: isConnectionsOptionSelected ? policy?.connections : undefined,
3066-
customUnits: getCustomUnitsForDuplication(policy, isDistanceRatesOptionSelected, isPerDiemOptionSelected, distanceCustomUnitID, perDiemCustomUnitID),
3066+
customUnits: getCustomUnitsForDuplication(policy, isDistanceRatesOptionSelected, isPerDiemOptionSelected, {distanceCustomUnitID, perDiemCustomUnitID}),
30673067
taxRates: isTaxesOptionSelected ? policy?.taxRates : undefined,
30683068
rules: isCodingRulesOptionSelected ? {codingRules: policy?.rules?.codingRules} : undefined,
30693069
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,

tests/unit/PolicyUtilsTest.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,25 +324,25 @@ describe('PolicyUtils', () => {
324324
};
325325

326326
it('returns undefined if neither option is selected', () => {
327-
expect(getCustomUnitsForDuplication(policy, false, false, otherUnit.customUnitID, perDiemUnit.customUnitID)).toBeUndefined();
327+
expect(getCustomUnitsForDuplication(policy, false, false, {distanceCustomUnitID: otherUnit.customUnitID, perDiemCustomUnitID: perDiemUnit.customUnitID})).toBeUndefined();
328328
});
329329

330330
it('returns all custom units if both options are selected', () => {
331-
const result = getCustomUnitsForDuplication(policy, true, true, otherUnit.customUnitID, perDiemUnit.customUnitID);
331+
const result = getCustomUnitsForDuplication(policy, true, true, {distanceCustomUnitID: otherUnit.customUnitID, perDiemCustomUnitID: perDiemUnit.customUnitID});
332332
expect(result).toEqual(policy.customUnits);
333333
});
334334
it('returns only non-per-diem units if only custom units option is selected', () => {
335-
const result = getCustomUnitsForDuplication(policy, true, false, otherUnit.customUnitID, perDiemUnit.customUnitID);
335+
const result = getCustomUnitsForDuplication(policy, true, false, {distanceCustomUnitID: otherUnit.customUnitID, perDiemCustomUnitID: perDiemUnit.customUnitID});
336336
expect(result).toEqual({[otherUnit.customUnitID]: otherUnit});
337337
});
338338

339339
it('returns only per diem unit if only per diem option is selected', () => {
340-
const result = getCustomUnitsForDuplication(policy, false, true, otherUnit.customUnitID, perDiemUnit.customUnitID);
340+
const result = getCustomUnitsForDuplication(policy, false, true, {distanceCustomUnitID: otherUnit.customUnitID, perDiemCustomUnitID: perDiemUnit.customUnitID});
341341
expect(result).toEqual({[perDiemUnit.customUnitID]: perDiemUnit});
342342
});
343343

344344
it('returns undefined if customUnits is empty', () => {
345-
expect(getCustomUnitsForDuplication(policyWithoutCustomUnits, true, true, otherUnit.customUnitID, perDiemUnit.customUnitID)).toBeUndefined();
345+
expect(getCustomUnitsForDuplication(policyWithoutCustomUnits, true, true, {distanceCustomUnitID: otherUnit.customUnitID, perDiemCustomUnitID: perDiemUnit.customUnitID})).toBeUndefined();
346346
});
347347
});
348348
describe('getRateDisplayValue', () => {

0 commit comments

Comments
 (0)