|
1 |
| -import { calculateInitialUtilisation } from '@ukef/dtfs2-common'; |
| 1 | +import * as dtfsCommon from '@ukef/dtfs2-common'; |
2 | 2 | import { calculateInitialUtilisationAndFixedFee, parseDate, hasRequiredValues, RequiredParams } from './calculate-initial-utilisation-and-fixed-fee';
|
3 | 3 | import { TfmFacilitiesRepo } from '../../../../../repositories/tfm-facilities-repo';
|
4 | 4 | import { aTfmFacility } from '../../../../../../test-helpers';
|
5 |
| -import { calculateInitialFixedFee } from './calculate-initial-fixed-fee'; |
6 |
| -import { calculateUkefShareOfUtilisation } from '../../../../../helpers'; |
| 5 | +import * as fixedFeeHelpers from './calculate-initial-fixed-fee'; |
| 6 | + |
| 7 | +jest.mock('./calculate-initial-fixed-fee'); |
| 8 | +// eslint-disable-next-line @typescript-eslint/no-unsafe-return |
| 9 | +jest.mock('@ukef/dtfs2-common', () => ({ |
| 10 | + ...jest.requireActual('@ukef/dtfs2-common'), |
| 11 | + calculateDrawnAmount: jest.fn(), |
| 12 | +})); |
7 | 13 |
|
8 | 14 | describe('helpers/calculate-initial-utilisation-and-fixed-fee', () => {
|
9 | 15 | describe('parseDate', () => {
|
@@ -145,26 +151,40 @@ describe('helpers/calculate-initial-utilisation-and-fixed-fee', () => {
|
145 | 151 | findOneByUkefFacilityIdSpy.mockResolvedValue(facility);
|
146 | 152 | });
|
147 | 153 |
|
148 |
| - it('should return a value for utilisation and fixed fee', async () => { |
| 154 | + it('should set initial utilisation to drawn amount rounded to 2 decimal places', async () => { |
| 155 | + // Arrange |
| 156 | + const drawnAmount = 12345.678; |
| 157 | + const drawnAmountRoundedToTwoDecimalPlaces = 12345.68; |
| 158 | + const calculateDrawnAmountSpy = jest.spyOn(dtfsCommon, 'calculateDrawnAmount').mockReturnValue(drawnAmount); |
| 159 | + jest.mocked(fixedFeeHelpers.calculateInitialFixedFee).mockReturnValue(999.99); |
| 160 | + |
| 161 | + // Act |
149 | 162 | const result = await calculateInitialUtilisationAndFixedFee(facilityId);
|
150 | 163 |
|
151 |
| - const { value, coverStartDate, coverEndDate, interestPercentage, dayCountBasis } = facility.facilitySnapshot; |
| 164 | + // Assert |
| 165 | + expect(calculateDrawnAmountSpy).toHaveBeenCalledWith(facility.facilitySnapshot.value, facility.facilitySnapshot.coverPercentage); |
| 166 | + expect(result.utilisation).toEqual(drawnAmountRoundedToTwoDecimalPlaces); |
| 167 | + }); |
152 | 168 |
|
153 |
| - const utilisation = calculateInitialUtilisation(value); |
154 |
| - const ukefShareOfUtilisation = calculateUkefShareOfUtilisation(utilisation, facility.facilitySnapshot.coverPercentage); |
| 169 | + it('should calculate and return the initial fixed fee', async () => { |
| 170 | + // Arrange |
| 171 | + const drawnAmount = 12345.678; |
| 172 | + const drawnAmountRoundedToTwoDecimalPlaces = 12345.68; |
| 173 | + jest.mocked(dtfsCommon.calculateDrawnAmount).mockReturnValue(drawnAmount); |
| 174 | + const calculateInitialFixedFeeSpy = jest.spyOn(fixedFeeHelpers, 'calculateInitialFixedFee').mockReturnValue(999.99); |
155 | 175 |
|
156 |
| - const expected = { |
157 |
| - fixedFee: calculateInitialFixedFee({ |
158 |
| - ukefShareOfUtilisation, |
159 |
| - coverStartDate: parseDate(coverStartDate), |
160 |
| - coverEndDate: parseDate(coverEndDate), |
161 |
| - interestPercentage, |
162 |
| - dayCountBasis, |
163 |
| - }), |
164 |
| - utilisation, |
165 |
| - }; |
| 176 | + // Act |
| 177 | + const result = await calculateInitialUtilisationAndFixedFee(facilityId); |
166 | 178 |
|
167 |
| - expect(result).toEqual(expected); |
| 179 | + // Assert |
| 180 | + expect(calculateInitialFixedFeeSpy).toHaveBeenCalledWith({ |
| 181 | + ukefShareOfUtilisation: drawnAmountRoundedToTwoDecimalPlaces, |
| 182 | + coverStartDate: facility.facilitySnapshot.coverStartDate, |
| 183 | + coverEndDate: facility.facilitySnapshot.coverEndDate, |
| 184 | + interestPercentage: facility.facilitySnapshot.interestPercentage, |
| 185 | + dayCountBasis: facility.facilitySnapshot.dayCountBasis, |
| 186 | + }); |
| 187 | + expect(result.fixedFee).toEqual(999.99); |
168 | 188 | });
|
169 | 189 | });
|
170 | 190 | });
|
|
0 commit comments