Skip to content

Commit

Permalink
Merge pull request #1559 from digitalfabrik/1381-comparison-applicant…
Browse files Browse the repository at this point in the history
…-contact

1381: Make name comparison more robust
  • Loading branch information
steffenkleinle committed Aug 5, 2024
2 parents 6f67277 + b2716ab commit b7b2ef0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions administration/@types/normalize-strings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'normalize-strings' {
export default function normalize(str: string, customCharmap?: Record<string, string>): string
}
1 change: 1 addition & 0 deletions administration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"date-fns": "^2.30.0",
"graphql": "^16.8.1",
"localforage": "^1.10.0",
"normalize-strings": "^1.1.1",
"notistack": "^3.0.1",
"pdf-lib": "^1.17.1",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alert, Typography, styled } from '@mui/material'

import { OrganizationInput } from '../../../generated/graphql'
import { normalizeName } from '../../../util/normalizeString'
import { useUpdateStateCallback } from '../hooks/useUpdateStateCallback'
import CheckboxForm from '../primitive-inputs/CheckboxForm'
import EmailForm from '../primitive-inputs/EmailForm'
Expand Down Expand Up @@ -98,7 +99,7 @@ const OrganizationForm: Form<State, Options, ValidatedInput, AdditionalProps> =
<Typography>
Bitte geben Sie hier die Daten der Person an, die ihr ehrenamtliches Engagement bestätigen kann.
</Typography>
{applicantName === state.contactName.shortText && (
{normalizeName(applicantName) === normalizeName(state.contactName.shortText) && (
<WarningContactPersonSamePerson severity='warning'>
Die Kontaktperson der Organisation und die antragsstellende Person scheinen identisch zu sein. Bitte beachten
Sie, dass Anträge auf dieser Grundlage nicht bewilligt werden können.
Expand Down
19 changes: 19 additions & 0 deletions administration/src/util/__tests__/normalizeString.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import normalizeString, { normalizeName } from '../normalizeString'

describe('normalizeString', () => {
it('should normalize search string', () => {
expect(normalizeString('Donauwörth')).toBe('donauworth')
expect(normalizeString('äöUEJJ')).toBe('aouejj')
})

it('should trim whitespaces', () => {
expect(normalizeString(' test ')).toBe('test')
})
})

describe('normalizeName', () => {
it('should normalize search string', () => {
expect(normalizeName('Dr. Hans-Peter Müller Lüdenscheid ')).toBe('drhanspetermullerludenscheid')
expect(normalizeName('Dr. Hans Peter Müller Lüdenscheid')).toBe('drhanspetermullerludenscheid')
})
})
6 changes: 6 additions & 0 deletions administration/src/util/normalizeString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import normalizeStrings from 'normalize-strings'

const normalizeString = (str: string): string => normalizeStrings(str).toLowerCase().trim()
export const normalizeName = (name: string) => normalizeString(name).replaceAll(/[^a-zA-Z0-9]/g, '')

export default normalizeString
1 change: 1 addition & 0 deletions administration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"types": ["node", "jest"]
},
"include": [
"@types",
"src",
"scripts",
"jest.config.ts",
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7b2ef0

Please sign in to comment.