Skip to content

Commit

Permalink
Merge pull request #743 from ministryofjustice/fix/1693-dtr-whitespace
Browse files Browse the repository at this point in the history
(1693) Strip whitespace from DtR date
  • Loading branch information
libuk authored Nov 15, 2023
2 parents f724253 + 325eb84 commit 85b728f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
16 changes: 14 additions & 2 deletions server/utils/applications/reportDataFromApplication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,23 @@ describe('reportDataFromApplication', () => {
data: {
'accommodation-referral-details': {
'dtr-submitted': { dtrSubmitted: 'yes' },
'dtr-details': { date: 'Duty of care submission date' },
'dtr-details': { date: '2023-05-24' },
},
},
})
expect(dutyToReferSubmissionDateFromApplication(application)).toEqual('Duty of care submission date')
expect(dutyToReferSubmissionDateFromApplication(application)).toEqual('2023-05-24')
})

it('strips the date if it contains whitespace', () => {
const application = applicationFactory.build({
data: {
'accommodation-referral-details': {
'dtr-submitted': { dtrSubmitted: 'yes' },
'dtr-details': { date: ' 2023 - 05 - 24 ' },
},
},
})
expect(dutyToReferSubmissionDateFromApplication(application)).toEqual('2023-05-24')
})
})

Expand Down
3 changes: 2 additions & 1 deletion server/utils/applications/reportDataFromApplication.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { eligibilityReasons } from '../../form-pages/apply/accommodation-need/eligibility/eligibilityReason'
import { TemporaryAccommodationApplication as Application } from '../../@types/shared'
import { SessionDataError } from '../errors'
import { stripWhitespace } from '../utils'

const isDutyToReferSubmittedFromApplication = (application: Application): boolean => {
const isDutyToReferSubmitted: string = (application.data as Record<string, unknown>)?.[
Expand Down Expand Up @@ -29,7 +30,7 @@ const dutyToReferSubmissionDateFromApplication = (application: Application): str
throw new SessionDataError('No duty to refer submitted date')
}

return dutyToReferSubmissionDate
return stripWhitespace(dutyToReferSubmissionDate)
}

const needsAccessiblePropertyFromApplication = (application: Application): boolean => {
Expand Down
7 changes: 7 additions & 0 deletions server/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
pascalCase,
removeBlankSummaryListItems,
sentenceCase,
stripWhitespace,
unique,
} from './utils'

Expand Down Expand Up @@ -231,3 +232,9 @@ describe('unique', () => {
)
})
})

describe('stripWhitespace', () => {
it('removes whitespace from a string', () => {
expect(stripWhitespace(' 2034 - 05 - 25 ')).toEqual('2034-05-25')
})
})
4 changes: 4 additions & 0 deletions server/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ export const appendQueryString = (
}
return `${path}${queryString ? `?${queryString}` : ''}`
}

export const stripWhitespace = (text: string): string => {
return text.replace(/\s+/g, '')
}

0 comments on commit 85b728f

Please sign in to comment.