Skip to content

Commit

Permalink
Fixed lease filter (#4289)
Browse files Browse the repository at this point in the history
  • Loading branch information
FuriousLlama authored Aug 27, 2024
1 parent 026a028 commit fbc2999
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 12 deletions.
4 changes: 1 addition & 3 deletions source/backend/dal/Repositories/PropertyRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,7 @@ public HashSet<long> GetMatchingIds(PropertyFilterCriteria filter)

if (filter.LeasePurposes != null && filter.LeasePurposes.Count > 0)
{
//predicate.And(p =>
// p.PimsPropertyLeases.Any(pl => filter.LeasePurposes.Contains(pl.Lease.LeasePurposeTypeCode)));
// TODO: Fix Mappings
predicate.And(p => p.PimsPropertyLeases.Any(pl => pl.Lease.PimsLeaseLeasePurposes.Any(plp => filter.LeasePurposes.Contains(plp.LeasePurposeTypeCode))));
}

if (!string.IsNullOrEmpty(filter.LeasePayRcvblType))
Expand Down
14 changes: 7 additions & 7 deletions source/backend/tests/core/Entities/LeaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static partial class EntityHelper
/// </summary>
/// <returns></returns>
public static PimsLease CreateLease(int pid, string lFileNo = null, string stakeholderFirstName = null, string stakeholderLastName = null, string motiFirstName = null, string motiLastName = null, PimsAddress address = null, bool addStakeholder = false, bool addProperty = true,
PimsLeaseProgramType pimsLeaseProgramType = null, PimsLeaseStatusType pimsLeaseStatusType = null, PimsLeasePayRvblType pimsLeasePayRvblType = null, PimsLeaseInitiatorType pimsLeaseInitiatorType = null, PimsLeaseResponsibilityType pimsLeaseResponsibilityType = null, PimsLeaseLicenseType pimsLeaseLicenseType = null, PimsRegion region = null)
PimsLeaseProgramType pimsLeaseProgramType = null, PimsLeaseStatusType pimsLeaseStatusType = null, PimsLeasePayRvblType pimsLeasePayRvblType = null, PimsLeaseInitiatorType pimsLeaseInitiatorType = null, PimsLeaseResponsibilityType pimsLeaseResponsibilityType = null, PimsLeaseLicenseType pimsLeaseLicenseType = null, PimsRegion region = null, bool generateTypeIds = false)
{
var lease = new PimsLease()
{
Expand All @@ -37,14 +37,14 @@ public static PimsLease CreateLease(int pid, string lFileNo = null, string stake
});
}
lease.MotiContact = $"{motiFirstName} {motiLastName}";
lease.LeaseProgramTypeCodeNavigation = pimsLeaseProgramType ?? new PimsLeaseProgramType() { Id = "testProgramType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseProgramTypeCodeNavigation = pimsLeaseProgramType ?? new PimsLeaseProgramType() { Id = generateTypeIds ? Guid.NewGuid().ToString() : "testProgramType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseProgramTypeCode = "testProgramType";
lease.LeaseStatusTypeCode = "testStatusType";
lease.LeaseStatusTypeCodeNavigation = pimsLeaseStatusType ?? new PimsLeaseStatusType() { Id = "testStatusType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeasePayRvblTypeCodeNavigation = pimsLeasePayRvblType ?? new PimsLeasePayRvblType() { Id = "testRvblType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseInitiatorTypeCodeNavigation = pimsLeaseInitiatorType ?? new PimsLeaseInitiatorType() { Id = "testInitiatorType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseResponsibilityTypeCodeNavigation = pimsLeaseResponsibilityType ?? new PimsLeaseResponsibilityType() { Id = "testResponsibilityType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseLicenseTypeCodeNavigation = pimsLeaseLicenseType ?? new PimsLeaseLicenseType() { Id = "testType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseStatusTypeCodeNavigation = pimsLeaseStatusType ?? new PimsLeaseStatusType() { Id = generateTypeIds ? Guid.NewGuid().ToString() : "testStatusType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeasePayRvblTypeCodeNavigation = pimsLeasePayRvblType ?? new PimsLeasePayRvblType() { Id = generateTypeIds ? Guid.NewGuid().ToString() : "testRvblType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseInitiatorTypeCodeNavigation = pimsLeaseInitiatorType ?? new PimsLeaseInitiatorType() { Id = generateTypeIds ? Guid.NewGuid().ToString() : "testInitiatorType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseResponsibilityTypeCodeNavigation = pimsLeaseResponsibilityType ?? new PimsLeaseResponsibilityType() { Id = generateTypeIds ? Guid.NewGuid().ToString() : "testResponsibilityType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
lease.LeaseLicenseTypeCodeNavigation = pimsLeaseLicenseType ?? new PimsLeaseLicenseType() { Id = generateTypeIds ? Guid.NewGuid().ToString() : "testType", DbCreateUserid = "test", DbLastUpdateUserid = "test", Description = "desc" };
if (region != null)
{
lease.RegionCodeNavigation = region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void GetMatchingIds_LeaseType_Success()
}

[Fact]
public void GetMatchingIds_LeasePurpose_Success()
public void GetMatchingIds_LeasePurpose_ZeroResults()
{
// Arrange
var repository = CreateRepositoryWithPermissions(Permissions.PropertyView);
Expand All @@ -400,13 +400,87 @@ public void GetMatchingIds_LeasePurpose_Success()
_helper.AddAndSaveChanges(property);

// Act
var result = repository.GetMatchingIds(new PropertyFilterCriteria() { LeasePurposes = new List<string>() { "test" } });
var result = repository.GetMatchingIds(new PropertyFilterCriteria() { LeasePurposes = new List<string>() { "something" } });

// Assert
result.Should().NotBeNull();
result.Should().HaveCount(0);
}

[Fact]
public void GetMatchingIds_LeasePurpose_OneResult()
{
// Arrange
var repository = CreateRepositoryWithPermissions(Permissions.PropertyView);
var propertyOne = EntityHelper.CreateProperty(100, isCoreInventory: true);
var lease = EntityHelper.CreateLease(1, addProperty: false);

lease.PimsLeaseLeasePurposes.Add(new PimsLeaseLeasePurpose()
{
LeaseLeasePurposeId = 100,
LeaseId = lease.LeaseId,
LeasePurposeTypeCode = "something",
});
propertyOne.PimsPropertyLeases.Add(new PimsPropertyLease() { PropertyId = propertyOne.Internal_Id, LeaseId = lease.Internal_Id, Lease = lease });
_helper.AddAndSaveChanges(propertyOne);

var propertyTwo = EntityHelper.CreateProperty(101, isCoreInventory: true);
var anotherLease = EntityHelper.CreateLease(2, addProperty: false, generateTypeIds: true);
anotherLease.PimsLeaseLeasePurposes.Add(new PimsLeaseLeasePurpose()
{
LeaseLeasePurposeId = 2,
LeaseId = anotherLease.LeaseId,
LeasePurposeTypeCode = "another",
});

propertyTwo.PimsPropertyLeases.Add(new PimsPropertyLease() { PropertyId = propertyTwo.Internal_Id, LeaseId = anotherLease.Internal_Id, Lease = anotherLease });
_helper.AddAndSaveChanges(propertyTwo);

// Act
var result = repository.GetMatchingIds(new PropertyFilterCriteria() { LeasePurposes = new List<string>() { "something" } });

// Assert
result.Should().NotBeNull();
result.Should().HaveCount(1);
}

[Fact]
public void GetMatchingIds_LeasePurpose_TwoResults()
{
// Arrange
var repository = CreateRepositoryWithPermissions(Permissions.PropertyView);
var propertyOne = EntityHelper.CreateProperty(100, isCoreInventory: true);
var lease = EntityHelper.CreateLease(1, addProperty: false);

lease.PimsLeaseLeasePurposes.Add(new PimsLeaseLeasePurpose()
{
LeaseLeasePurposeId = 100,
LeaseId = lease.LeaseId,
LeasePurposeTypeCode = "something",
});
propertyOne.PimsPropertyLeases.Add(new PimsPropertyLease() { PropertyId = propertyOne.Internal_Id, LeaseId = lease.Internal_Id, Lease = lease });
_helper.AddAndSaveChanges(propertyOne);

var propertyTwo = EntityHelper.CreateProperty(101, isCoreInventory: true);
var anotherLease = EntityHelper.CreateLease(2, addProperty: false, generateTypeIds: true);
anotherLease.PimsLeaseLeasePurposes.Add(new PimsLeaseLeasePurpose()
{
LeaseLeasePurposeId = 2,
LeaseId = anotherLease.LeaseId,
LeasePurposeTypeCode = "another",
});

propertyTwo.PimsPropertyLeases.Add(new PimsPropertyLease() { PropertyId = propertyTwo.Internal_Id, LeaseId = anotherLease.Internal_Id, Lease = anotherLease });
_helper.AddAndSaveChanges(propertyTwo);

// Act
var result = repository.GetMatchingIds(new PropertyFilterCriteria() { LeasePurposes = new List<string>() { "something", "another" } });

// Assert
result.Should().NotBeNull();
result.Should().HaveCount(2);
}

[Fact]
public void GetMatchingIds_Anomaly_Success()
{
Expand Down Expand Up @@ -493,6 +567,7 @@ public void GetMatchingIds_TenurePph_Success()
result.Should().NotBeNull();
result.Should().HaveCount(1);
}

#endregion

#region GetByPid
Expand Down

0 comments on commit fbc2999

Please sign in to comment.