Skip to content

Commit

Permalink
psp-7095 add default status to new management activities, display sta…
Browse files Browse the repository at this point in the history
…tus as required field.
  • Loading branch information
devinleighsmith committed Oct 31, 2023
1 parent b857440 commit baed0e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions source/backend/api/Services/PropertyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public PimsPropertyActivity CreateActivity(PimsPropertyActivity propertyActivity
_logger.LogInformation("Creating property Activity...");
_user.ThrowIfNotAuthorized(Permissions.ManagementAdd, Permissions.PropertyEdit);

if (propertyActivity.PropMgmtActivityStatusTypeCode == null)
{
propertyActivity.PropMgmtActivityStatusTypeCode = "NOTSTARTED";
}

var propertyActivityResult = _propertyActivityRepository.Create(propertyActivity);
_propertyActivityRepository.CommitTransaction();

Expand Down
31 changes: 31 additions & 0 deletions source/backend/tests/unit/api/Services/PropertyServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,37 @@ public void Update_PropertyManagement_NoPermission()
repository.Verify(x => x.UpdatePropertyManagement(It.IsAny<PimsProperty>()), Times.Never);
}

[Fact]
public void Create_PropertyManagementActivity_NoPermission()
{
// Arrange
var service = this.CreatePropertyServiceWithPermissions();
var repository = this._helper.GetService<Mock<IPropertyActivityRepository>>();

// Act
Action act = () => service.CreateActivity(new PimsPropertyActivity());

// Assert
act.Should().Throw<NotAuthorizedException>();
repository.Verify(x => x.Create(It.IsAny<PimsPropertyActivity>()), Times.Never);
}

[Fact]
public void Create_PropertyManagementActivity_Success()
{
// Arrange
var service = this.CreatePropertyServiceWithPermissions(Permissions.ManagementAdd, Permissions.PropertyEdit);
var repository = this._helper.GetService<Mock<IPropertyActivityRepository>>();
var activity = new PimsPropertyActivity();

// Act
var result = service.CreateActivity(activity);

// Assert
activity.PropMgmtActivityStatusTypeCode.Should().Be("NOTSTARTED");
repository.Verify(x => x.Create(It.IsAny<PimsPropertyActivity>()), Times.Once);
}


[Fact]
public void Get_PropertyManagement_Activities_NoPermission()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const PropertyActivityEditForm: React.FunctionComponent<
placeholder="Select subtype"
/>
</SectionField>
<SectionField label="Activity status" contentWidth="7">
<SectionField label="Activity status" contentWidth="7" required>
<Select
field="activityStatusCode"
options={activityStatusOptions}
Expand Down

0 comments on commit baed0e0

Please sign in to comment.