Skip to content

Commit

Permalink
psp-7609 ensure that changing the status of an acq file generates a n…
Browse files Browse the repository at this point in the history
…ote. (#3726)
  • Loading branch information
devinleighsmith authored Jan 22, 2024
1 parent bf7543b commit fce3358
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
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

0 comments on commit fce3358

Please sign in to comment.