From b2dc453b44393185db0cf200051026cada1c8174 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 2 Feb 2023 11:39:00 -0500 Subject: [PATCH] fix occupant name test --- helpers/functions.sqlFilters.js | 3 +-- helpers/functions.sqlFilters.ts | 3 +-- test/functions.js | 3 ++- test/functions.ts | 4 +++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/helpers/functions.sqlFilters.js b/helpers/functions.sqlFilters.js index 56f91264..883b8c47 100644 --- a/helpers/functions.sqlFilters.js +++ b/helpers/functions.sqlFilters.js @@ -76,8 +76,7 @@ export function getOccupantNameWhereClause(occupantName = '', tableAlias = 'o') if (occupantNamePiece === '') { continue; } - sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) - or instr(lower(${tableAlias}.occupantFamilyName), ?))`; + sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) or instr(lower(${tableAlias}.occupantFamilyName), ?))`; sqlParameters.push(occupantNamePiece, occupantNamePiece); } } diff --git a/helpers/functions.sqlFilters.ts b/helpers/functions.sqlFilters.ts index 8c96caed..356f7ae1 100644 --- a/helpers/functions.sqlFilters.ts +++ b/helpers/functions.sqlFilters.ts @@ -108,8 +108,7 @@ export function getOccupantNameWhereClause( continue } - sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) - or instr(lower(${tableAlias}.occupantFamilyName), ?))` + sqlWhereClause += ` and (instr(lower(${tableAlias}.occupantName), ?) or instr(lower(${tableAlias}.occupantFamilyName), ?))` sqlParameters.push(occupantNamePiece, occupantNamePiece) } } diff --git a/test/functions.js b/test/functions.js index 5d2ab285..4f4fbcf8 100644 --- a/test/functions.js +++ b/test/functions.js @@ -200,7 +200,8 @@ describe('functions.sqlFilters', () => { describe('OccupantName filter', () => { it('returns filter', () => { const filter = sqlFilterFunctions.getOccupantNameWhereClause('TEST1 TEST2', 'o'); - assert.strictEqual(filter.sqlWhereClause, ' and instr(lower(o.occupantName), ?) and instr(lower(o.occupantName), ?)'); + assert.strictEqual(filter.sqlWhereClause, ' and (instr(lower(o.occupantName), ?) or instr(lower(o.occupantFamilyName), ?)) and (instr(lower(o.occupantName), ?) or instr(lower(o.occupantFamilyName), ?))'); + assert.ok(filter.sqlParameters.length === 4); assert.ok(filter.sqlParameters.includes('test1')); assert.ok(filter.sqlParameters.includes('test2')); }); diff --git a/test/functions.ts b/test/functions.ts index 54334b56..c06186ac 100644 --- a/test/functions.ts +++ b/test/functions.ts @@ -346,9 +346,11 @@ describe('functions.sqlFilters', () => { assert.strictEqual( filter.sqlWhereClause, - ' and instr(lower(o.occupantName), ?) and instr(lower(o.occupantName), ?)' + ' and (instr(lower(o.occupantName), ?) or instr(lower(o.occupantFamilyName), ?)) and (instr(lower(o.occupantName), ?) or instr(lower(o.occupantFamilyName), ?))' ) + assert.ok(filter.sqlParameters.length === 4) + assert.ok(filter.sqlParameters.includes('test1')) assert.ok(filter.sqlParameters.includes('test2')) })