diff --git a/dtfs-central-api/src/services/portal/facility-amendment.service.ts b/dtfs-central-api/src/services/portal/facility-amendment.service.ts index e7356c22bbc..9023b34df20 100644 --- a/dtfs-central-api/src/services/portal/facility-amendment.service.ts +++ b/dtfs-central-api/src/services/portal/facility-amendment.service.ts @@ -74,7 +74,7 @@ export class PortalFacilityAmendmentService { } /** - * Updates a portal facility amendment with the provided details. + * Updates a portal facility amendment * * @param params * @param params.amendmentId - The amendment id @@ -114,7 +114,7 @@ export class PortalFacilityAmendmentService { } /** - * Updates a portal facility amendment with the provided details. + * Updates a portal facility amendment with user provided values. * * @param params * @param params.amendmentId - The amendment id diff --git a/dtfs-central-api/src/services/portal/facility-amendment.submitPortalFacilityAmendmentToChecker.service.test.ts b/dtfs-central-api/src/services/portal/facility-amendment.submitPortalFacilityAmendmentToChecker.service.test.ts index a32dcdd8856..e027a3ee2d9 100644 --- a/dtfs-central-api/src/services/portal/facility-amendment.submitPortalFacilityAmendmentToChecker.service.test.ts +++ b/dtfs-central-api/src/services/portal/facility-amendment.submitPortalFacilityAmendmentToChecker.service.test.ts @@ -8,6 +8,7 @@ import { TfmFacilitiesRepo } from '../../repositories/tfm-facilities-repo'; const mockUpdatePortalFacilityAmendmentByAmendmentId = jest.fn(); const mockFindOneAmendmentByFacilityIdAndAmendmentId = jest.fn(); +const mockValidateAmendmentIsComplete = jest.fn(); const amendmentId = new ObjectId().toString(); const facilityId = new ObjectId().toString(); @@ -27,6 +28,8 @@ describe('PortalFacilityAmendmentService', () => { jest.spyOn(TfmFacilitiesRepo, 'updatePortalFacilityAmendmentByAmendmentId').mockImplementation(mockUpdatePortalFacilityAmendmentByAmendmentId); jest.spyOn(TfmFacilitiesRepo, 'findOneAmendmentByFacilityIdAndAmendmentId').mockImplementation(mockFindOneAmendmentByFacilityIdAndAmendmentId); + jest.spyOn(PortalFacilityAmendmentService, 'validateAmendmentIsComplete').mockImplementation(mockValidateAmendmentIsComplete); + mockUpdatePortalFacilityAmendmentByAmendmentId.mockResolvedValue({}); mockFindOneAmendmentByFacilityIdAndAmendmentId.mockResolvedValue(updatedAmendment); }); @@ -36,6 +39,23 @@ describe('PortalFacilityAmendmentService', () => { }); describe('submitPortalFacilityAmendmentToChecker', () => { + it('should call PortalFacilityAmendmentService.validateAmendmentIsComplete', async () => { + // Act + await PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ + amendmentId, + facilityId, + dealId, + auditDetails, + }); + + // Assert + expect(mockValidateAmendmentIsComplete).toHaveBeenCalledTimes(1); + expect(mockValidateAmendmentIsComplete).toHaveBeenCalledWith({ + facilityId, + amendmentId, + }); + }); + it('should call TfmFacilitiesRepo.updatePortalFacilityAmendmentByAmendmentId with the correct params', async () => { // Act await PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ @@ -56,66 +76,67 @@ describe('PortalFacilityAmendmentService', () => { facilityId: new ObjectId(facilityId), amendmentId: new ObjectId(amendmentId), auditDetails, + allowedStatuses: [PORTAL_AMENDMENT_STATUS.DRAFT], }); }); - }); - it('should call TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId with the correct params', async () => { - // Act - await PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ - amendmentId, - facilityId, - dealId, - auditDetails, + it('should call TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId with the correct params', async () => { + // Act + await PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ + amendmentId, + facilityId, + dealId, + auditDetails, + }); + + // Assert + expect(mockFindOneAmendmentByFacilityIdAndAmendmentId).toHaveBeenCalledTimes(1); + expect(mockFindOneAmendmentByFacilityIdAndAmendmentId).toHaveBeenCalledWith(new ObjectId(facilityId), new ObjectId(amendmentId)); }); - // Assert - expect(mockFindOneAmendmentByFacilityIdAndAmendmentId).toHaveBeenCalledTimes(1); - expect(mockFindOneAmendmentByFacilityIdAndAmendmentId).toHaveBeenCalledWith(new ObjectId(facilityId), new ObjectId(amendmentId)); - }); + it('should return the result of TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId', async () => { + // Act + const expected = await PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ + amendmentId, + facilityId, + dealId, + auditDetails, + }); - it('should return the result of TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId', async () => { - // Act - const expected = await PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ - amendmentId, - facilityId, - dealId, - auditDetails, + // Assert + expect(expected).toEqual(updatedAmendment); }); - // Assert - expect(expected).toEqual(updatedAmendment); - }); + it('should throw an error if no amendment is found when calling TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId', async () => { + // Arrange + mockFindOneAmendmentByFacilityIdAndAmendmentId.mockResolvedValueOnce(null); - it('should throw an error if no amendment is found when calling TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId', async () => { - // Arrange - mockFindOneAmendmentByFacilityIdAndAmendmentId.mockResolvedValueOnce(null); + // Act + const returned = PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ + amendmentId, + facilityId, + dealId, + auditDetails, + }); - // Act - const returned = PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ - amendmentId, - facilityId, - dealId, - auditDetails, + // Assert + await expect(returned).rejects.toThrow(new Error('Could not find amendment to return')); }); - // Assert - await expect(returned).rejects.toThrow(new Error('Could not find amendment to return')); - }); + it(`should throw an error if an amendment without a ${AMENDMENT_TYPES.PORTAL} amendment type is returned from TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId`, async () => { + // Arrange + mockFindOneAmendmentByFacilityIdAndAmendmentId.mockResolvedValueOnce({ ...updatedAmendment, type: AMENDMENT_TYPES.TFM }); - it(`should throw an error if an amendment without a ${AMENDMENT_TYPES.PORTAL} amendment type is returned from TfmFacilitiesRepo.findOneAmendmentByFacilityIdAndAmendmentId`, async () => { - // Arrange - mockFindOneAmendmentByFacilityIdAndAmendmentId.mockResolvedValueOnce({ ...updatedAmendment, type: AMENDMENT_TYPES.TFM }); + // Act + const returned = PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ + amendmentId, + facilityId, + dealId, + auditDetails, + }); - // Act - const returned = PortalFacilityAmendmentService.submitPortalFacilityAmendmentToChecker({ - amendmentId, - facilityId, - dealId, - auditDetails, + // Assert + await expect(returned).rejects.toThrow(new Error('Could not find amendment to return')); }); - - // Assert - await expect(returned).rejects.toThrow(new Error('Could not find amendment to return')); }); }); diff --git a/dtfs-central-api/src/services/portal/facility-amendment.updatePortalFacilityAmendmentUserValues.service.test.ts b/dtfs-central-api/src/services/portal/facility-amendment.updatePortalFacilityAmendmentUserValues.service.test.ts index f78ec52517e..fddb340f0f6 100644 --- a/dtfs-central-api/src/services/portal/facility-amendment.updatePortalFacilityAmendmentUserValues.service.test.ts +++ b/dtfs-central-api/src/services/portal/facility-amendment.updatePortalFacilityAmendmentUserValues.service.test.ts @@ -1,4 +1,4 @@ -import { AMENDMENT_TYPES } from '@ukef/dtfs2-common'; +import { AMENDMENT_TYPES, PORTAL_AMENDMENT_STATUS } from '@ukef/dtfs2-common'; import { ObjectId } from 'mongodb'; import { getUnixTime } from 'date-fns'; import { generatePortalAuditDetails } from '@ukef/dtfs2-common/change-stream'; @@ -13,9 +13,10 @@ const mockFindOneAmendmentByFacilityIdAndAmendmentId = jest.fn(); const amendmentId = new ObjectId().toString(); const facilityId = new ObjectId().toString(); const update = { - changeCoverStartDate: true, isUsingFacilityEndDate: true, facilityEndDate: new Date(), + bankReviewDate: null, + changeCoverEndDate: true, }; const updatedAmendment = { ...aPortalFacilityAmendment(), ...update }; const auditDetails = generatePortalAuditDetails(aPortalUser()._id); @@ -61,6 +62,7 @@ describe('PortalFacilityAmendmentService', () => { facilityId: new ObjectId(facilityId), amendmentId: new ObjectId(amendmentId), auditDetails, + allowedStatuses: [PORTAL_AMENDMENT_STATUS.DRAFT], }); }); });