Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSP-9740 HOTFIX: User is not able to update the Acquisition Files #4548

Merged
merged 5 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/backend/api/Pims.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>0ef6255f-9ea0-49ec-8c65-c172304b4926</UserSecretsId>
<Version>5.7.0-95.20</Version>
<AssemblyVersion>5.7.0.95</AssemblyVersion>
<Version>5.7.1-95.20</Version>
<AssemblyVersion>5.7.1.95</AssemblyVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProjectGuid>{16BC0468-78F6-4C91-87DA-7403C919E646}</ProjectGuid>
<TargetFramework>net8.0</TargetFramework>
Expand Down
3 changes: 3 additions & 0 deletions source/backend/api/Services/AcquisitionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AcquisitionFileModel : FileWithChecklistModel
/// <summary>
/// The assigned date.
/// </summary>
public DateTime? AssignedDate { get; set; }
public DateOnly? AssignedDate { get; set; }

/// <summary>
/// The date for delivery of the property to the project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,62 @@ public void Add_Success()
repository.Verify(x => x.Add(It.IsAny<PimsAcquisitionFile>()), 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<Mock<IAcquisitionFileRepository>>();
repository.Setup(x => x.Add(It.IsAny<PimsAcquisitionFile>())).Returns(acqFile);

var lookupRepository = this._helper.GetService<Mock<ILookupRepository>>();
lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List<PimsRegion>() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } });

var userRepository = this._helper.GetService<Mock<IUserRepository>>();
userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny<Guid>())).Returns(EntityHelper.CreateUser(1, Guid.NewGuid(), "Test", regionCode: 1));

// Act
var result = service.Add(acqFile, new List<UserOverrideCode>());

// Assert
repository.Verify(x => x.Add(It.IsAny<PimsAcquisitionFile>()), 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<Mock<IAcquisitionFileRepository>>();
repository.Setup(x => x.Add(It.IsAny<PimsAcquisitionFile>())).Returns(acqFile);

var lookupRepository = this._helper.GetService<Mock<ILookupRepository>>();
lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List<PimsRegion>() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } });

var userRepository = this._helper.GetService<Mock<IUserRepository>>();
userRepository.Setup(x => x.GetUserInfoByKeycloakUserId(It.IsAny<Guid>())).Returns(EntityHelper.CreateUser(1, Guid.NewGuid(), "Test", regionCode: 1));

// Act
var result = service.Add(acqFile, new List<UserOverrideCode>());

// Assert
repository.Verify(x => x.Add(It.IsAny<PimsAcquisitionFile>()), Times.Once);
result.AssignedDate.Should().Be(customDate);
result.AcquisitionFileStatusTypeCode.Should().Be(AcquisitionStatusTypes.ACTIVE.ToString());
}

[Fact]
public void Add_CannotDetermineRegion_Error()
{
Expand Down
2 changes: 1 addition & 1 deletion source/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion source/frontend/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ exports[`AcquisitionFileTabs component > matches snapshot 1`] = `
class="c7 text-left col"
data-testid="assigned-date"
>
Dec 17, 2024
Dec 18, 2024
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('AcquisitionSummaryView component', () => {
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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -94,7 +94,7 @@ const AcquisitionSummaryView: React.FC<IAcquisitionSummaryViewProps> = ({
</Section>
<Section header="Schedule">
<SectionField label="Assigned date" valueTestId="assigned-date">
{prettyFormatUTCDate(detail.assignedDate)}
{prettyFormatDate(detail.assignedDate)}
</SectionField>
<SectionField
label="Delivery date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ 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');
expect(getAssignedDatePicker()).toHaveValue('Dec 17, 2024');
expect(getAssignedDatePicker()).toHaveValue('Dec 18, 2024');
});

it('displays Individual type Owner with data', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
</div>
</div>
Expand Down Expand Up @@ -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"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ApiGen_Concepts_AcquisitionFile } from '@/models/api/generated/ApiGen_C
import { ApiGen_Concepts_AcquisitionFileOwner } from '@/models/api/generated/ApiGen_Concepts_AcquisitionFileOwner';
import { ApiGen_Concepts_InterestHolder } from '@/models/api/generated/ApiGen_Concepts_InterestHolder';
import { getEmptyBaseAudit } from '@/models/defaultInitializers';
import { formatUTCDateTime } from '@/utils';
import { fromTypeCode, toTypeCodeNullable } from '@/utils/formUtils';
import { exists, isValidId, isValidIsoDateTime } from '@/utils/utils';

Expand Down Expand Up @@ -121,7 +120,7 @@ export class UpdateAcquisitionSummaryFormModel
newForm.legacyFileNumber = model.legacyFileNumber ?? undefined;
newForm.fileName = model.fileName || '';
newForm.rowVersion = model.rowVersion ?? undefined;
newForm.assignedDate = model.assignedDate ? formatUTCDateTime(model.assignedDate) : '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't his going to bring back the issue of the time zone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope because if you see the changes in the backend will generate the current date in the server timezone (DateTime.Today) - we have configured our API servers to run in PST timezone so we don't get the issue anymore.
The original issue happened because when this field is not populated, the DB was assigning the current UTC date.
By having the backend put a value always (either what comes from the frontend or the current date (non-UTC)) we fix this and do not need to format as UTC in the frontend.

This is consistent with the other dates you see on the acquisition details screen - none of those are formatted as UTC.

newForm.assignedDate = model.assignedDate ?? undefined;
newForm.deliveryDate = model.deliveryDate ?? undefined;
newForm.estimatedCompletionDate = model.estimatedCompletionDate ?? undefined;
newForm.possessionDate = model.possessionDate ?? undefined;
Expand Down
Loading