Skip to content

Commit

Permalink
PSP-9451 : Lease/ Licence- Filters section-Separate PID and PIN in th… (
Browse files Browse the repository at this point in the history
#4472)

Co-authored-by: Herrera <[email protected]>
  • Loading branch information
eddherrera and Herrera authored Nov 19, 2024
1 parent 2d5c064 commit 288dcf8
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 69 deletions.
18 changes: 13 additions & 5 deletions source/backend/api/Areas/Leases/Models/LeaseFilterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ public class LeaseFilterModel : PageFilter
#region Properties

/// <summary>
/// get/set - The unique identifier for titled property, either pid or pin.
/// get/set - The unique PID identifier for titled property.
/// </summary>
public string PinOrPid { get; set; }
public string Pid { get; set; }

/// <summary>
/// get/set - The unique PIN identifier for titled property.
/// </summary>
public string Pin { get; set; }

/// <summary>
/// get/set - The LIS L File #.
Expand Down Expand Up @@ -84,7 +89,8 @@ public LeaseFilterModel(Dictionary<string, Microsoft.Extensions.Primitives.Strin
// We want case-insensitive query parameter properties.
var filter = new Dictionary<string, Microsoft.Extensions.Primitives.StringValues>(query, StringComparer.OrdinalIgnoreCase);

this.PinOrPid = filter.GetStringValue(nameof(this.PinOrPid));
this.Pid = filter.GetStringValue(nameof(this.Pid));
this.Pin = filter.GetStringValue(nameof(this.Pin));
this.LFileNo = filter.GetStringValue(nameof(this.LFileNo));
this.Address = filter.GetStringValue(nameof(this.Address));
this.Historical = filter.GetStringValue(nameof(this.Historical));
Expand Down Expand Up @@ -112,7 +118,8 @@ public static explicit operator LeaseFilter(LeaseFilterModel model)
Page = model.Page,
Quantity = model.Quantity,

PinOrPid = model.PinOrPid,
Pid = model.Pid,
Pin = model.Pin,
LFileNo = model.LFileNo,
Address = model.Address,
Historical = model.Historical,
Expand Down Expand Up @@ -142,7 +149,8 @@ public override bool IsValid()
}

return base.IsValid()
|| !string.IsNullOrWhiteSpace(PinOrPid)
|| !string.IsNullOrWhiteSpace(Pid)
|| !string.IsNullOrWhiteSpace(Pin)
|| !string.IsNullOrWhiteSpace(LFileNo)
|| !string.IsNullOrWhiteSpace(Address)
|| !string.IsNullOrWhiteSpace(Historical)
Expand Down
17 changes: 12 additions & 5 deletions source/backend/dal/Models/LeaseFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ public class LeaseFilter : PageFilter
#region Properties

/// <summary>
/// get/set - The unique identifier for titled property, either pid or pin.
/// get/set - The unique PID identifier for titled property.
/// </summary>
public string PinOrPid { get; set; }
public string Pid { get; set; }

/// <summary>
/// get/set - The unique PIN identifier for titled property.
/// </summary>
public string Pin { get; set; }

/// <summary>
/// get/set - The LIS L File #.
Expand Down Expand Up @@ -75,11 +80,12 @@ public class LeaseFilter : PageFilter
/// </summary>
public DateOnly? ExpiryEndDate { get; set; }

public LeaseFilter(string lFileNo, string tenantName, string pinOrPid, string historical, string[] sort)
public LeaseFilter(string lFileNo, string tenantName, string pid, string pin, string historical, string[] sort)
{
this.LFileNo = lFileNo;
this.TenantName = tenantName;
this.PinOrPid = pinOrPid;
this.Pid = pid;
this.Pin = pin;
this.Historical = historical;
this.Sort = sort;
}
Expand Down Expand Up @@ -119,7 +125,8 @@ public override bool IsValid()
}

return base.IsValid()
|| !string.IsNullOrWhiteSpace(PinOrPid)
|| !string.IsNullOrWhiteSpace(Pid)
|| !string.IsNullOrWhiteSpace(Pin)
|| !string.IsNullOrWhiteSpace(LFileNo)
|| !string.IsNullOrWhiteSpace(Address)
|| !string.IsNullOrWhiteSpace(Historical)
Expand Down
12 changes: 9 additions & 3 deletions source/backend/dal/Repositories/LeaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,16 @@ private static ExpressionStarter<PimsLease> GenerateCommonLeaseQuery(LeaseFilter
|| l.PimsLeaseStakeholders.Any(stakeholder => stakeholder.Organization != null && EF.Functions.Like(stakeholder.Organization.OrganizationName, $"%{filter.TenantName}%")));
}

if (!string.IsNullOrWhiteSpace(filter.PinOrPid))
if (!string.IsNullOrWhiteSpace(filter.Pid))
{
var pinOrPidValue = filter.PinOrPid.Replace("-", string.Empty).Trim().TrimStart('0');
predicateBuilder = predicateBuilder.And(l => l.PimsPropertyLeases.Any(pl => pl != null && (EF.Functions.Like(pl.Property.Pid.ToString(), $"%{pinOrPidValue}%") || EF.Functions.Like(pl.Property.Pin.ToString(), $"%{pinOrPidValue}%"))));
var pidValue = filter.Pid.Replace("-", string.Empty).Trim().TrimStart('0');
predicateBuilder = predicateBuilder.And(l => l.PimsPropertyLeases.Any(pl => pl != null && EF.Functions.Like(pl.Property.Pid.ToString(), $"%{pidValue}%")));
}

if (!string.IsNullOrWhiteSpace(filter.Pin))
{
var pinValue = filter.Pin.Replace("-", string.Empty).Trim().TrimStart('0');
predicateBuilder = predicateBuilder.And(l => l.PimsPropertyLeases.Any(pl => pl != null && EF.Functions.Like(pl.Property.Pin.ToString(), $"%{pinValue}%")));
}

if (!string.IsNullOrWhiteSpace(filter.LFileNo))
Expand Down
8 changes: 4 additions & 4 deletions source/backend/tests/core/Entities/LeaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static partial class EntityHelper
/// Create a new instance of a Lease.
/// </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,
public static PimsLease CreateLease(int pid, int? pin = null, 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, bool generateTypeIds = false)
{
var lease = new PimsLease()
Expand All @@ -32,7 +32,7 @@ public static PimsLease CreateLease(int pid, string lFileNo = null, string stake
{
lease.PimsPropertyLeases.Add(new PimsPropertyLease()
{
Property = CreateProperty(pid: pid),
Property = CreateProperty(pid: pid, pin: pin),
Lease = lease,
});
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public static PimsLease CreateLease(int pid, string lFileNo = null, string stake
/// Create a new instance of a Lease.
/// </summary>
/// <returns></returns>
public static PimsLease CreateLease(this PimsContext context, 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)
public static PimsLease CreateLease(this PimsContext context, int pid, int? pin = null, string lFileNo = null, string stakeholderFirstName = null, string stakeholderLastName = null, string motiFirstName = null, string motiLastName = null, PimsAddress address = null, bool addStakeholder = false, bool addProperty = true)
{
var programType = context.PimsLeaseProgramTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease program type.");
var leaseStatusType = context.PimsLeaseStatusTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease status type.");
Expand All @@ -69,7 +69,7 @@ public static PimsLease CreateLease(this PimsContext context, int pid, string lF
var leaseResponsibilityType = context.PimsLeaseResponsibilityTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease reponsibility type.");
var leaseLicenseType = context.PimsLeaseLicenseTypes.FirstOrDefault() ?? throw new InvalidOperationException("Unable to find lease license type.");

var lease = CreateLease(pid, lFileNo, stakeholderFirstName, stakeholderLastName, motiFirstName, motiLastName, address, addStakeholder, addProperty, programType, leaseStatusType, leasePayRvblType, leaseInitiatorType, leaseResponsibilityType, leaseLicenseType);
var lease = CreateLease(pid, pin, lFileNo, stakeholderFirstName, stakeholderLastName, motiFirstName, motiLastName, address, addStakeholder, addProperty, programType, leaseStatusType, leasePayRvblType, leaseInitiatorType, leaseResponsibilityType, leaseLicenseType);
context.PimsLeases.Add(lease);

return lease;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public SearchControllerTest()
{
new object [] { new SModel.LeaseFilterModel() { TenantName = "test" } },
new object [] { new SModel.LeaseFilterModel() { LFileNo = "1234" } },
new object [] { new SModel.LeaseFilterModel() { PinOrPid = "123" } },
new object [] { new SModel.LeaseFilterModel() { Pid = "123" } },
};

public readonly static IEnumerable<object[]> LeaseQueryFilters = new List<object[]>()
{
new object [] { "?TenantName=test" },
new object [] { "?LFileNo=1" },
new object [] { "?PinOrPid=2" },
new object [] { "?Pid=2" },
};
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public class LeaseControllerTest
{
new object [] { new LeaseFilterModel() },
new object [] { new LeaseFilterModel() { LFileNo = "L-000-001" } },
new object [] { new LeaseFilterModel() { PinOrPid = "999999" } },
new object [] { new LeaseFilterModel() { Pid = "999999" } },
new object [] { new LeaseFilterModel() { Pin = "888888" } },
new object [] { new LeaseFilterModel() { TenantName = "George" } },
};

public static IEnumerable<object[]> LeaseQueryFilters = new List<object[]>()
{
new object [] { new Uri("http://host/api/leases?LFileNo=L-000-001") },
new object [] { new Uri("http://host/api/leases?PinOrPid=999999") },
new object [] { new Uri("http://host/api/leases?Pid=999999") },
new object [] { new Uri("http://host/api/leases?Pin=888888") },
new object [] { new Uri("http://host/api/leases?TenantName=George") },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class LeaseRepositoryTest
new object[] { new LeaseFilter() { TenantName = "fake" }, 0 },
new object[] { new LeaseFilter() { LFileNo = "123" }, 1 },
new object[] { new LeaseFilter() { LFileNo = "fake" }, 0 },
new object[] { new LeaseFilter() { PinOrPid = "456" }, 1 },
new object[] { new LeaseFilter() { PinOrPid = "789" }, 0 },
new object[] { new LeaseFilter() { Pid = "456" }, 1 },
new object[] { new LeaseFilter() { Pin = "789" }, 1 },
new object[] { new LeaseFilter() { Historical = "111" }, 1 },
new object[] { new LeaseFilter() { Historical = "222" }, 0 },
new object[] { new LeaseFilter() { Address = "1234 St" }, 1 },
Expand All @@ -61,7 +61,8 @@ public class LeaseRepositoryTest
new object[] { new LeaseFilter() { NotInStatus = new List<string>() { "someOtherValue" } }, 1 },
new object[] { new LeaseFilter() { IsReceivable = true }, 0 },
new object[] { new LeaseFilter() { IsReceivable = false }, 1 },
new object[] { new LeaseFilter() { PinOrPid = "789" }, 0 },
new object[] { new LeaseFilter() { Pin = "999" }, 0 },
new object[] { new LeaseFilter() { Pid = "999" }, 0 },
new object[] { new LeaseFilter(), 1 },
new object[] { new LeaseFilter() { Sort = new string[] {"ExpiryDate"} }, 1 },
};
Expand Down Expand Up @@ -94,7 +95,7 @@ public void Get_Leases_Paged(LeaseFilter filter, int expectedCount)
// Arrange
var helper = new TestHelper();
var user = PrincipalHelper.CreateForPermission(Permissions.LeaseView);
var elease = EntityHelper.CreateLease(456, lFileNo: "123", stakeholderLastName: "tenant", addStakeholder: true);
var elease = EntityHelper.CreateLease(456, 789, lFileNo: "123", stakeholderLastName: "tenant", addStakeholder: true);
elease.LeaseId = 1;
elease.OrigExpiryDate = new DateTime(2000, 1, 1);
elease.OrigStartDate = new DateTime(2000, 1, 1);
Expand Down Expand Up @@ -154,7 +155,7 @@ public void Get_Leases_Filter(LeaseFilter filter, int expectedCount)
// Arrange
var helper = new TestHelper();
var user = PrincipalHelper.CreateForPermission(Permissions.LeaseView);
var elease = EntityHelper.CreateLease(456, lFileNo: "123", stakeholderLastName: "tenant", addStakeholder: true);
var elease = EntityHelper.CreateLease(456, 789, lFileNo: "123", stakeholderLastName: "tenant", addStakeholder: true);
elease.LeaseId = 1;
elease.OrigExpiryDate = new DateTime(2000, 1, 1);
elease.OrigStartDate = new DateTime(2000, 1, 1);
Expand Down
6 changes: 4 additions & 2 deletions source/frontend/src/features/leases/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface ILeaseFilter {
pinOrPid: string;
pid: string;
pin: string;
lFileNo: string;
searchBy: string;
leaseStatusTypes: string[];
Expand All @@ -12,7 +13,8 @@ export interface ILeaseFilter {
}

export interface ILeaseSearchBy {
pinOrPid: string;
pin: string;
pid: string;
address: string;
lFileNo: string;
historical: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,43 @@ describe('Lease Filter', () => {
expect(asFragment()).toMatchSnapshot();
});

it('searches by pid/pin', async () => {
it('searches by pid', async () => {
const { container, searchButton, setFilter } = setup();

fillInput(container, 'searchBy', 'pinOrPid', 'select');
fillInput(container, 'pinOrPid', '123');
fillInput(container, 'searchBy', 'pid', 'select');
fillInput(container, 'pid', '123');
await act(async () => userEvent.click(searchButton));

expect(setFilter).toHaveBeenCalledWith(
expect.objectContaining<ILeaseFilter>({
lFileNo: '',
pinOrPid: '123',
searchBy: 'pinOrPid',
pid: '123',
pin: '',
searchBy: 'pid',
tenantName: '',
programs: [],
leaseStatusTypes: ['ACTIVE'],
expiryStartDate: '',
expiryEndDate: '',
regionType: '',
details: '',
}),
);
});

it('searches by pin', async () => {
const { container, searchButton, setFilter } = setup();

fillInput(container, 'searchBy', 'pin', 'select');
fillInput(container, 'pin', '123');
await act(async () => userEvent.click(searchButton));

expect(setFilter).toHaveBeenCalledWith(
expect.objectContaining<ILeaseFilter>({
lFileNo: '',
pid: '',
pin: '123',
searchBy: 'pin',
tenantName: '',
programs: [],
leaseStatusTypes: ['ACTIVE'],
Expand All @@ -78,7 +103,8 @@ describe('Lease Filter', () => {
expect(setFilter).toHaveBeenCalledWith(
expect.objectContaining<ILeaseFilter>({
lFileNo: '123',
pinOrPid: '',
pid: '',
pin: '',
searchBy: 'lFileNo',
tenantName: '',
programs: [],
Expand All @@ -94,15 +120,16 @@ describe('Lease Filter', () => {
it('searches tenant name', async () => {
const { container, searchButton, setFilter } = setup();

fillInput(container, 'searchBy', 'pinOrPid', 'select');
fillInput(container, 'searchBy', 'pid', 'select');
fillInput(container, 'tenantName', 'Chester');
await act(async () => userEvent.click(searchButton));

expect(setFilter).toHaveBeenCalledWith(
expect.objectContaining<ILeaseFilter>({
lFileNo: '',
pinOrPid: '',
searchBy: 'pinOrPid',
pid: '',
pin: '',
searchBy: 'pid',
tenantName: 'Chester',
programs: [],
leaseStatusTypes: ['ACTIVE'],
Expand All @@ -117,14 +144,15 @@ describe('Lease Filter', () => {
it('resets the filter when reset button is clicked', async () => {
const { container, resetButton, setFilter } = setup();

fillInput(container, 'searchBy', 'pinOrPid', 'select');
fillInput(container, 'pinOrPid', 'foo-bar-baz');
fillInput(container, 'searchBy', 'pid', 'select');
fillInput(container, 'pid', 'foo-bar-baz');
await act(async () => userEvent.click(resetButton));

expect(setFilter).toHaveBeenCalledWith(
expect.objectContaining<ILeaseFilter>({
lFileNo: '',
pinOrPid: '',
pid: '',
pin: '',
searchBy: 'lFileNo',
tenantName: '',
programs: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ interface MultiSelectOption {
}

export const defaultFilter: ILeaseFilter = {
pinOrPid: '',
pid: '',
pin: '',
lFileNo: '',
searchBy: 'lFileNo',
leaseStatusTypes: ['ACTIVE'],
Expand Down Expand Up @@ -118,10 +119,11 @@ export const LeaseFilter: React.FunctionComponent<React.PropsWithChildren<ILease
<Col xl="7">
<SelectInput<ILeaseSearchBy, ILeaseFilter>
field="searchBy"
defaultKey="pinOrPid"
defaultKey="pid"
defaultValue={''}
selectOptions={[
{ label: 'PID/PIN', key: 'pinOrPid', placeholder: 'Enter a PID or PIN' },
{ label: 'PID', key: 'pid', placeholder: 'Enter a PID' },
{ label: 'PIN', key: 'pin', placeholder: 'Enter a PIN' },
{ label: 'Address', key: 'address', placeholder: 'Enter an address' },
{
label: 'L-File #',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,17 @@ exports[`Lease Filter > matches snapshot 1`] = `
>
<option
class="option"
data-testid="select-option-pinOrPid"
value="pinOrPid"
data-testid="select-option-pid"
value="pid"
>
PID/PIN
PID
</option>
<option
class="option"
data-testid="select-option-pin"
value="pin"
>
PIN
</option>
<option
class="option"
Expand Down
Loading

0 comments on commit 288dcf8

Please sign in to comment.