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-7609 ensure that changing the status of a disposition file generates a note #3726

Merged
merged 1 commit into from
Jan 22, 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
35 changes: 34 additions & 1 deletion source/backend/api/Services/DispositionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DispositionFileService : IDispositionFileService
private readonly IPropertyService _propertyService;
private readonly ILookupRepository _lookupRepository;
private readonly IDispositionFileChecklistRepository _checklistRepository;
private readonly IEntityNoteRepository _entityNoteRepository;

public DispositionFileService(
ClaimsPrincipal user,
Expand All @@ -41,7 +42,8 @@ public DispositionFileService(
IPropertyRepository propertyRepository,
IPropertyService propertyService,
ILookupRepository lookupRepository,
IDispositionFileChecklistRepository checklistRepository)
IDispositionFileChecklistRepository checklistRepository,
IEntityNoteRepository entityNoteRepository)
{
_user = user;
_logger = logger;
Expand All @@ -52,6 +54,7 @@ public DispositionFileService(
_propertyService = propertyService;
_lookupRepository = lookupRepository;
_checklistRepository = checklistRepository;
_entityNoteRepository = entityNoteRepository;
}

public PimsDispositionFile Add(PimsDispositionFile dispositionFile, IEnumerable<UserOverrideCode> userOverrides)
Expand Down Expand Up @@ -111,6 +114,7 @@ public PimsDispositionFile Update(long id, PimsDispositionFile dispositionFile,
}

_dispositionFileRepository.Update(id, dispositionFile);
AddNoteIfStatusChanged(dispositionFile);
_dispositionFileRepository.CommitTransaction();

return _dispositionFileRepository.GetById(id);
Expand Down Expand Up @@ -380,6 +384,35 @@ public List<DispositionFileExportModel> GetDispositionFileExport(DispositionFilt
}).ToList();
}

private void AddNoteIfStatusChanged(PimsDispositionFile updateDispositionFile)
{
var currentDispositionFile = _dispositionFileRepository.GetById(updateDispositionFile.Internal_Id);
bool statusChanged = currentDispositionFile.DispositionFileStatusTypeCode != updateDispositionFile.DispositionFileStatusTypeCode;
if (!statusChanged)
{
return;
}

var newStatus = _lookupRepository.GetAllDispositionFileStatusTypes()
.FirstOrDefault(x => x.DispositionFileStatusTypeCode == updateDispositionFile.DispositionFileStatusTypeCode);

PimsDispositionFileNote fileNoteInstance = new()
{
DispositionFileId = updateDispositionFile.Internal_Id,
AppCreateTimestamp = DateTime.Now,
AppCreateUserid = _user.GetUsername(),
Note = new PimsNote()
{
IsSystemGenerated = true,
NoteTxt = $"Disposition File status changed from {currentDispositionFile.DispositionFileStatusTypeCodeNavigation.Description} to {newStatus.Description}",
AppCreateTimestamp = DateTime.Now,
AppCreateUserid = this._user.GetUsername(),
},
};

_entityNoteRepository.Add(fileNoteInstance);
}

private static decimal CalculateNetProceedsBeforeSpp(PimsDispositionSale sale)
{
if (sale != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,42 @@ public void Update_Success()
Assert.NotNull(result);
repository.Verify(x => x.Update(It.IsAny<long>(), It.IsAny<PimsDispositionFile>()), Times.Once);
}

[Fact]
public void Update_Success_AddsNote()
{
// Arrange
var service = this.CreateDispositionServiceWithPermissions(Permissions.DispositionEdit);

var dspFile = EntityHelper.CreateDispositionFile();
dspFile.ConcurrencyControlNumber = 1;
dspFile.AppCreateUserid = "TESTER";

var repository = this._helper.GetService<Mock<IDispositionFileRepository>>();
var noteRepository = this._helper.GetService<Mock<IEntityNoteRepository>>();
var lookupRepository = this._helper.GetService<Mock<ILookupRepository>>();

repository.Setup(x => x.Update(It.IsAny<long>(), It.IsAny<PimsDispositionFile>())).Returns(dspFile);
repository.Setup(x => x.GetRowVersion(It.IsAny<long>())).Returns(1);
repository.Setup(x => x.GetById(It.IsAny<long>())).Returns(new PimsDispositionFile()
{
DispositionFileStatusTypeCode = "CLOSED",
DispositionFileStatusTypeCodeNavigation = new PimsDispositionFileStatusType() { Description = "Closed" },
});
lookupRepository.Setup(x => x.GetAllRegions()).Returns(new List<PimsRegion>() { new PimsRegion() { Code = 4, RegionName = "Cannot determine" } });
lookupRepository.Setup(x => x.GetAllDispositionFileStatusTypes()).Returns(new PimsDispositionFileStatusType[]{ new PimsDispositionFileStatusType() {
Id = dspFile.DispositionFileStatusTypeCodeNavigation.Id,
Description = dspFile.DispositionFileStatusTypeCodeNavigation.Description,
},});

// Act
var result = service.Update(dspFile.Internal_Id, dspFile, new List<UserOverrideCode>() { UserOverrideCode.UpdateRegion });

// Assert
repository.Verify(x => x.Update(It.IsAny<long>(), It.IsAny<PimsDispositionFile>()), Times.Once);
noteRepository.Verify(x => x.Add(It.Is<PimsDispositionFileNote>(x => x.DispositionFileId == 1
&& x.Note.NoteTxt == "Disposition File status changed from Closed to Active")), Times.Once);
}
#endregion

#region GetTeamMembers
Expand Down
Loading