Skip to content

Commit

Permalink
FIX: Case Insensitive Name Matching for Applicants (#4021)
Browse files Browse the repository at this point in the history
* fix: case insensitive name matching for applicants

* fix: switch back to case sensitive ruleKey

* Revert "fix: switch back to case sensitive ruleKey"

This reverts commit 507b187.

* fix: migration to standardize rule keys
  • Loading branch information
mcgarrye committed Apr 18, 2024
1 parent 8da16c3 commit 2694a7d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Convert all rule keys to lowercase
-- Then correct nameAndDOB in lowercased rule_keys

UPDATE application_flagged_set
SET rule_key = LOWER(rule_key);

UPDATE application_flagged_set
SET rule_key = REPLACE(rule_key, 'nameanddob', 'nameAndDOB');
8 changes: 6 additions & 2 deletions api/src/services/application-flagged-set.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
return `${listingId}-email-${application.applicant.emailAddress}`;
} else {
return (
`${listingId}-nameAndDOB-${application.applicant.firstName}-${application.applicant.lastName}-${application.applicant.birthMonth}-` +
`${application.applicant.birthDay}-${application.applicant.birthYear}`
`${listingId}-nameAndDOB-${application.applicant.firstName.toLowerCase()}-${application.applicant.lastName.toLowerCase()}` +
`-${application.applicant.birthMonth}-${application.applicant.birthDay}-${application.applicant.birthYear}`
);
}
}
Expand Down Expand Up @@ -748,6 +748,7 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
some: {
firstName: {
in: firstNames,
mode: 'insensitive',
},
},
},
Expand All @@ -756,6 +757,7 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
applicant: {
firstName: {
in: firstNames,
mode: 'insensitive',
},
},
},
Expand All @@ -768,6 +770,7 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
some: {
lastName: {
in: lastNames,
mode: 'insensitive',
},
},
},
Expand All @@ -776,6 +779,7 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
applicant: {
lastName: {
in: lastNames,
mode: 'insensitive',
},
},
},
Expand Down
64 changes: 58 additions & 6 deletions api/test/integration/application-flagged-set.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Application flagged set Controller Tests', () => {
emailIndicator: string,
nameAndDOBIndicator: string,
listing: string,
dobIndicator?: string,
householdMember?: Prisma.HouseholdMemberCreateWithoutApplicationsInput,
) => {
return await prisma.applications.create({
Expand All @@ -70,9 +71,9 @@ describe('Application flagged set Controller Tests', () => {
emailAddress: `${listing}-email${emailIndicator}@email.com`,
firstName: `${listing}-firstName${nameAndDOBIndicator}`,
lastName: `${listing}-lastName${nameAndDOBIndicator}`,
birthDay: nameAndDOBIndicator,
birthMonth: nameAndDOBIndicator,
birthYear: nameAndDOBIndicator,
birthDay: dobIndicator || nameAndDOBIndicator,
birthMonth: dobIndicator || nameAndDOBIndicator,
birthYear: dobIndicator || nameAndDOBIndicator,
},
listingId: listing,
householdMember: [householdMember],
Expand Down Expand Up @@ -731,6 +732,28 @@ describe('Application flagged set Controller Tests', () => {
expect(afs[0].rule).toEqual(RuleEnum.nameAndDOB);
});

it('should create a new flagged set if applications match on nameAndDOB case insensitive', async () => {
const listing = await createListing();

await createComplexApplication('1', 'test', listing, '1');
await createComplexApplication('2', 'TEST', listing, '1');

await request(app.getHttpServer())
.put(`/applicationFlaggedSets/process`)
.set('Cookie', adminAccessToken)
.expect(200);

const afs = await prisma.applicationFlaggedSet.findMany({
where: {
listingId: listing,
},
});

expect(afs.length).toEqual(1);

expect(afs[0].rule).toEqual(RuleEnum.nameAndDOB);
});

it('should keep application in flagged set if email still matches', async () => {
const listing = await createListing();

Expand Down Expand Up @@ -1289,13 +1312,13 @@ describe('Application flagged set Controller Tests', () => {
let allApplicationCount = 0;
for (const flaggedSet of afs) {
expect(flaggedSet.rule).toEqual(RuleEnum.nameAndDOB);
if (flaggedSet.ruleKey.indexOf(`${listing}-firstName1`) >= 0) {
if (flaggedSet.ruleKey.indexOf(`${listing}-firstname1`) >= 0) {
const applications = flaggedSet.applications.map((app) => app.id);
expect(applications).toContain(appA.id);
allApplicationCount++;
expect(applications).toContain(appB.id);
allApplicationCount++;
} else if (flaggedSet.ruleKey.indexOf(`${listing}-firstName3`) >= 0) {
} else if (flaggedSet.ruleKey.indexOf(`${listing}-firstname3`) >= 0) {
const applications = flaggedSet.applications.map((app) => app.id);
expect(applications).toContain(appC.id);
allApplicationCount++;
Expand Down Expand Up @@ -1362,7 +1385,7 @@ describe('Application flagged set Controller Tests', () => {
const listing = await createListing();

await createComplexApplication('1', '1', listing);
await createComplexApplication('2', '2', listing, {
await createComplexApplication('2', '2', listing, '2', {
firstName: `${listing}-firstName1`,
lastName: `${listing}-lastName1`,
birthDay: '1',
Expand All @@ -1387,6 +1410,35 @@ describe('Application flagged set Controller Tests', () => {
expect(afs[0].rule).toEqual(RuleEnum.nameAndDOB);
});

it('should create nameAndDob flagged set on household member matches case insensitive', async () => {
const listing = await createListing();

await createComplexApplication('1', 'TEST', listing, '1');
await createComplexApplication('2', '2', listing, '2', {
firstName: `${listing}-firstNametest`,
lastName: `${listing}-lastNameTest`,
birthDay: '1',
birthMonth: '1',
birthYear: '1',
sameAddress: YesNoEnum.yes,
workInRegion: YesNoEnum.yes,
});

await request(app.getHttpServer())
.put(`/applicationFlaggedSets/process`)
.set('Cookie', adminAccessToken)
.expect(200);

const afs = await prisma.applicationFlaggedSet.findMany({
where: {
listingId: listing,
},
});

expect(afs.length).toEqual(1);
expect(afs[0].rule).toEqual(RuleEnum.nameAndDOB);
});

it('should remove from flagged set and create new flagged set when match moves from email -> nameAndDOB', async () => {
const listing = await createListing();

Expand Down
30 changes: 26 additions & 4 deletions api/test/unit/services/application-flagged-set.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('Testing application flagged set service', () => {
'household first name 1',
'household first name 2',
],
mode: 'insensitive',
},
},
},
Expand All @@ -95,6 +96,7 @@ describe('Testing application flagged set service', () => {
'household first name 1',
'household first name 2',
],
mode: 'insensitive',
},
},
},
Expand All @@ -111,6 +113,7 @@ describe('Testing application flagged set service', () => {
'household last name 1',
'household last name 2',
],
mode: 'insensitive',
},
},
},
Expand All @@ -123,6 +126,7 @@ describe('Testing application flagged set service', () => {
'household last name 1',
'household last name 2',
],
mode: 'insensitive',
},
},
},
Expand Down Expand Up @@ -357,6 +361,24 @@ describe('Testing application flagged set service', () => {
).toEqual('example id-nameAndDOB-first name-last name-5-6-2000');
});

it('should build rule key in lowercase when rule is nameAndDOB', async () => {
expect(
await service.buildRuleKey(
{
applicant: {
firstName: 'FIRST Name',
lastName: 'lAsT nAMe',
birthMonth: 5,
birthDay: 6,
birthYear: 2000,
},
} as unknown as Application,
RuleEnum.nameAndDOB,
'example id',
),
).toEqual('example id-nameAndDOB-first name-last name-5-6-2000');
});

it('should get a list of flagged sets when view is pendingEmail', async () => {
const mockCount = jest
.fn()
Expand Down Expand Up @@ -700,7 +722,7 @@ describe('Testing application flagged set service', () => {
id: 'example id 1',
},
{
id: 'example id 2',
id: 'Example id 2',
},
]);

Expand All @@ -714,7 +736,7 @@ describe('Testing application flagged set service', () => {
id: 'example id 1',
},
{
id: 'example id 2',
id: 'Example id 2',
},
]);

Expand Down Expand Up @@ -964,7 +986,7 @@ describe('Testing application flagged set service', () => {
id: 'example id 1',
},
{
id: 'example id 2',
id: 'Example id 2',
},
]);

Expand All @@ -979,7 +1001,7 @@ describe('Testing application flagged set service', () => {
id: 'example id 1',
},
{
id: 'example id 2',
id: 'Example id 2',
},
]);

Expand Down

0 comments on commit 2694a7d

Please sign in to comment.