From bcab55eb7e704e466bd7553a87f45afbeeb3a8d9 Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Sat, 21 Dec 2024 13:20:01 -0800 Subject: [PATCH 1/5] PSP-9740: Fix faulty logic for Acquisition assigned date value --- source/backend/api/Services/AcquisitionFileService.cs | 3 +++ .../Models/Concepts/AcquisitionFile/AcquisitionFileMap.cs | 4 ++-- .../Models/Concepts/AcquisitionFile/AcquisitionFileModel.cs | 2 +- .../tabs/fileDetails/detail/AcquisitionSummaryView.tsx | 4 ++-- .../mapSideBar/acquisition/tabs/fileDetails/update/models.ts | 3 +-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/backend/api/Services/AcquisitionFileService.cs b/source/backend/api/Services/AcquisitionFileService.cs index 8f23f5fdce..acd7df194a 100644 --- a/source/backend/api/Services/AcquisitionFileService.cs +++ b/source/backend/api/Services/AcquisitionFileService.cs @@ -229,7 +229,10 @@ public PimsAcquisitionFile Add(PimsAcquisitionFile acquisitionFile, IEnumerable< _propertyService.PopulateNewFileProperty(incomingAcquisitionProperty); } + // Set default values, according to business rules acquisitionFile.AcquisitionFileStatusTypeCode = AcquisitionStatusTypes.ACTIVE.ToString(); + acquisitionFile.AssignedDate ??= DateTime.Today; + var newAcqFile = _acqFileRepository.Add(acquisitionFile); _acqFileRepository.CommitTransaction(); diff --git a/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileMap.cs b/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileMap.cs index 5b54ba2d29..28a46032cf 100644 --- a/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileMap.cs +++ b/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileMap.cs @@ -26,7 +26,7 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.ProductId, src => src.ProductId) .Map(dest => dest.FundingTypeCode, src => src.AcquisitionFundingTypeCodeNavigation) .Map(dest => dest.FundingOther, src => src.FundingOther) - .Map(dest => dest.AssignedDate, src => src.AssignedDate) + .Map(dest => dest.AssignedDate, src => src.AssignedDate.ToNullableDateOnly()) .Map(dest => dest.DeliveryDate, src => src.DeliveryDate.ToNullableDateOnly()) .Map(dest => dest.EstimatedCompletionDate, src => src.EstCompletionDt.ToNullableDateOnly()) .Map(dest => dest.PossessionDate, src => src.PossessionDt.ToNullableDateOnly()) @@ -58,7 +58,7 @@ public void Register(TypeAdapterConfig config) .Map(dest => dest.ProductId, src => src.ProductId) .Map(dest => dest.AcquisitionFundingTypeCode, src => src.FundingTypeCode.Id) .Map(dest => dest.FundingOther, src => src.FundingOther) - .Map(dest => dest.AssignedDate, src => src.AssignedDate) + .Map(dest => dest.AssignedDate, src => src.AssignedDate.ToNullableDateTime()) .Map(dest => dest.DeliveryDate, src => src.DeliveryDate.ToNullableDateTime()) .Map(dest => dest.EstCompletionDt, src => src.EstimatedCompletionDate.ToNullableDateTime()) .Map(dest => dest.PossessionDt, src => src.PossessionDate.ToNullableDateTime()) diff --git a/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileModel.cs b/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileModel.cs index 36534e3d87..aadf35ac51 100644 --- a/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileModel.cs +++ b/source/backend/apimodels/Models/Concepts/AcquisitionFile/AcquisitionFileModel.cs @@ -36,7 +36,7 @@ public class AcquisitionFileModel : FileWithChecklistModel /// /// The assigned date. /// - public DateTime? AssignedDate { get; set; } + public DateOnly? AssignedDate { get; set; } /// /// The date for delivery of the property to the project. diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx index ab9b60622a..7e6e9b52d4 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/AcquisitionSummaryView.tsx @@ -14,7 +14,7 @@ import { InterestHolderType } from '@/constants/interestHolderTypes'; import { usePersonRepository } from '@/features/contacts/repositories/usePersonRepository'; import useKeycloakWrapper from '@/hooks/useKeycloakWrapper'; import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFile'; -import { exists, prettyFormatDate, prettyFormatUTCDate } from '@/utils'; +import { exists, prettyFormatDate } from '@/utils'; import { formatApiPersonNames } from '@/utils/personUtils'; import { cannotEditMessage } from '../../../common/constants'; @@ -94,7 +94,7 @@ const AcquisitionSummaryView: React.FC = ({
- {prettyFormatUTCDate(detail.assignedDate)} + {prettyFormatDate(detail.assignedDate)} Date: Sat, 21 Dec 2024 14:00:01 -0800 Subject: [PATCH 2/5] Lint fixes --- .../tabs/fileDetails/update/UpdateAcquisitionForm.test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/UpdateAcquisitionForm.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/UpdateAcquisitionForm.test.tsx index 980bfa4a4e..bad042a518 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/UpdateAcquisitionForm.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/UpdateAcquisitionForm.test.tsx @@ -167,7 +167,8 @@ describe('UpdateAcquisitionForm component', () => { }); it('displays estimated completion, assigned and possession dates', async () => { - const { getEstimatedCompletionDatePicker, getPossessionDatePicker, getAssignedDatePicker } = setup({ initialValues }); + const { getEstimatedCompletionDatePicker, getPossessionDatePicker, getAssignedDatePicker } = + setup({ initialValues }); await act(async () => {}); expect(getEstimatedCompletionDatePicker()).toHaveValue('Jul 10, 2024'); expect(getPossessionDatePicker()).toHaveValue('Jul 10, 2025'); From db03ff5c6830eb66e5d15c6166b728184c9f897a Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Sat, 21 Dec 2024 14:42:37 -0800 Subject: [PATCH 3/5] Test updates --- .../acquisition/__snapshots__/AcquisitionView.test.tsx.snap | 2 +- .../tabs/__snapshots__/AcquisitionFileTabs.test.tsx.snap | 2 +- .../tabs/fileDetails/detail/AcquisitionSummaryView.test.tsx | 2 +- .../detail/__snapshots__/AcquisitionSummaryView.test.tsx.snap | 2 +- .../tabs/fileDetails/update/UpdateAcquisitionForm.test.tsx | 2 +- .../update/__snapshots__/UpdateAcquisitionForm.test.tsx.snap | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/frontend/src/features/mapSideBar/acquisition/__snapshots__/AcquisitionView.test.tsx.snap b/source/frontend/src/features/mapSideBar/acquisition/__snapshots__/AcquisitionView.test.tsx.snap index 436212a8bd..72ffbca419 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/__snapshots__/AcquisitionView.test.tsx.snap +++ b/source/frontend/src/features/mapSideBar/acquisition/__snapshots__/AcquisitionView.test.tsx.snap @@ -1168,7 +1168,7 @@ exports[`AcquisitionView component > renders as expected 1`] = ` class="c35 text-left col" data-testid="assigned-date" > - Dec 17, 2024 + Dec 18, 2024
matches snapshot 1`] = ` class="c7 text-left col" data-testid="assigned-date" > - Dec 17, 2024 + Dec 18, 2024
{ await waitForEffects(); expect(getByText('Jan 10, 2030')).toBeVisible(); expect(getByText('Mar 10, 2035')).toBeVisible(); - expect(getByTestId('assigned-date')).toHaveTextContent('Dec 17, 2024'); + expect(getByTestId('assigned-date')).toHaveTextContent('Dec 18, 2024'); }); it('renders owner solicitor information with primary contact', async () => { diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/__snapshots__/AcquisitionSummaryView.test.tsx.snap b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/__snapshots__/AcquisitionSummaryView.test.tsx.snap index b6967b994d..c307bd449e 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/__snapshots__/AcquisitionSummaryView.test.tsx.snap +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/detail/__snapshots__/AcquisitionSummaryView.test.tsx.snap @@ -177,7 +177,7 @@ exports[`AcquisitionSummaryView component > matches snapshot 1`] = ` class="c5 text-left col" data-testid="assigned-date" > - Dec 17, 2024 + Dec 18, 2024
{ await act(async () => {}); expect(getEstimatedCompletionDatePicker()).toHaveValue('Jul 10, 2024'); expect(getPossessionDatePicker()).toHaveValue('Jul 10, 2025'); - expect(getAssignedDatePicker()).toHaveValue('Dec 17, 2024'); + expect(getAssignedDatePicker()).toHaveValue('Dec 18, 2024'); }); it('displays Individual type Owner with data', async () => { diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/__snapshots__/UpdateAcquisitionForm.test.tsx.snap b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/__snapshots__/UpdateAcquisitionForm.test.tsx.snap index 60042f1871..ce940393fe 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/__snapshots__/UpdateAcquisitionForm.test.tsx.snap +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/fileDetails/update/__snapshots__/UpdateAcquisitionForm.test.tsx.snap @@ -860,7 +860,7 @@ exports[`UpdateAcquisitionForm component > Sub-interest files > renders as expec name="assignedDate" placeholder="MMM DD, YYYY" type="text" - value="Dec 17, 2024" + value="Dec 18, 2024" />
@@ -4554,7 +4554,7 @@ exports[`UpdateAcquisitionForm component > renders as expected 1`] = ` name="assignedDate" placeholder="MMM DD, YYYY" type="text" - value="Dec 17, 2024" + value="Dec 18, 2024" /> From 719350a8454e1ea7ac44fa7f62e212d71ed8e03b Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Mon, 23 Dec 2024 12:35:28 -0800 Subject: [PATCH 4/5] Increment hotfix version --- source/backend/api/Pims.Api.csproj | 4 ++-- source/frontend/package-lock.json | 2 +- source/frontend/package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/backend/api/Pims.Api.csproj b/source/backend/api/Pims.Api.csproj index 79dcc9d373..55486ab240 100644 --- a/source/backend/api/Pims.Api.csproj +++ b/source/backend/api/Pims.Api.csproj @@ -2,8 +2,8 @@ 0ef6255f-9ea0-49ec-8c65-c172304b4926 - 5.7.0-95.20 - 5.7.0.95 + 5.7.1-95.20 + 5.7.1.95 true {16BC0468-78F6-4C91-87DA-7403C919E646} net8.0 diff --git a/source/frontend/package-lock.json b/source/frontend/package-lock.json index c7a32606b0..a0cd004462 100644 --- a/source/frontend/package-lock.json +++ b/source/frontend/package-lock.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "5.7.0-95.0", + "version": "5.7.1-95.20", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/source/frontend/package.json b/source/frontend/package.json index cf0713c1a2..ec84a89e2b 100644 --- a/source/frontend/package.json +++ b/source/frontend/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "5.7.0-95.20", + "version": "5.7.1-95.20", "private": true, "dependencies": { "@bcgov/bc-sans": "1.0.1", From eab9c8a413946488db8f636147d35d080385200a Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Mon, 23 Dec 2024 14:40:58 -0800 Subject: [PATCH 5/5] Test updates --- .../Services/AcquisitionFileServiceTest.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs index 5369e25725..4626d5cfc7 100644 --- a/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs +++ b/source/backend/tests/unit/api/Services/AcquisitionFileServiceTest.cs @@ -65,6 +65,62 @@ public void Add_Success() repository.Verify(x => x.Add(It.IsAny()), Times.Once); } + [Fact] + public void Add_Success_DefaultValues() + { + // Arrange + var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileAdd); + + var acqFile = EntityHelper.CreateAcquisitionFile(); + acqFile.AssignedDate = null; + + var repository = this._helper.GetService>(); + repository.Setup(x => x.Add(It.IsAny())).Returns(acqFile); + + var lookupRepository = this._helper.GetService>(); + lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + + var userRepository = this._helper.GetService>(); + userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser(1, Guid.NewGuid(), "Test", regionCode: 1)); + + // Act + var result = service.Add(acqFile, new List()); + + // Assert + repository.Verify(x => x.Add(It.IsAny()), Times.Once); + result.AssignedDate.Should().Be(DateTime.Today); + result.AcquisitionFileStatusTypeCode.Should().Be(AcquisitionStatusTypes.ACTIVE.ToString()); + } + + [Fact] + public void Add_Success_WithUserSuppliedAssignedDate() + { + // Arrange + var service = this.CreateAcquisitionServiceWithPermissions(Permissions.AcquisitionFileAdd); + + DateTime customDate = DateTime.Today.AddMonths(3); + + var acqFile = EntityHelper.CreateAcquisitionFile(); + acqFile.AssignedDate = customDate; + + var repository = this._helper.GetService>(); + repository.Setup(x => x.Add(It.IsAny())).Returns(acqFile); + + var lookupRepository = this._helper.GetService>(); + lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } }); + + var userRepository = this._helper.GetService>(); + userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny())).Returns(EntityHelper.CreateUser(1, Guid.NewGuid(), "Test", regionCode: 1)); + + // Act + var result = service.Add(acqFile, new List()); + + // Assert + repository.Verify(x => x.Add(It.IsAny()), Times.Once); + result.AssignedDate.Should().Be(customDate); + result.AcquisitionFileStatusTypeCode.Should().Be(AcquisitionStatusTypes.ACTIVE.ToString()); + } + [Fact] public void Add_CannotDetermineRegion_Error() {