Skip to content

Commit

Permalink
test(patientrepository.test.ts): add test for search string clean regex
Browse files Browse the repository at this point in the history
Added a test to pass a search string including all prohibited chars, expects cleaned version of
string to be used for search.

re HospitalRun#1999
  • Loading branch information
JDarke committed Apr 25, 2020
1 parent 0ffef66 commit fccc145
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"i18next": "~19.4.0",
"i18next-browser-languagedetector": "~4.1.0",
"i18next-xhr-backend": "~3.2.2",
"mocha": "~7.1.1",
"node-sass": "~4.13.0",
"pouchdb": "~7.2.1",
"pouchdb-adapter-memory": "~7.2.1",
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/clients/db/PatientRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('patient repository', () => {
await removeAllDocs()
})

it('should remove all breaking special chars from search text', async () => {
await patients.put({ _id: 'id9999', code: 'P00001', fullName: 'test test' })

const result = await PatientRepository.search(']?t}e(s){t** te[\\st')

expect(result).toHaveLength(1)
expect(result[0].id).toEqual('id9999')
})

it('should return all records that patient code matches search text', async () => {
// same full name to prove that it is finding by patient code
const expectedPatientCode = 'P00001'
Expand Down
2 changes: 1 addition & 1 deletion src/clients/db/PatientRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class PatientRepository extends Repository<Patient> {
}

async search(text: string): Promise<Patient[]> {
const cleanText = text.replace(/[\\[()?*]+/g, '')
const cleanText = text.replace(/[\\[\](){}?*]+/g, '')
return super.search({
selector: {
$or: [
Expand Down

0 comments on commit fccc145

Please sign in to comment.