Skip to content

Commit

Permalink
Merge pull request #155 from DEFRA/DSFAAP-745_firstname_lastname_char…
Browse files Browse the repository at this point in the history
…acter_limit

Limiting the length of first and last name to 50 characters
  • Loading branch information
hughfdjackson authored Jan 24, 2025
2 parents 753b021 + 9057aa3 commit 24c2a70
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/server/common/model/answer/fullName/fullName.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Joi from 'joi'
import { AnswerModel } from '../answer-model.js'
import { validateAnswerAgainstSchema } from '../validation.js'

const maxLength = 255
const maxLength = 50

export const fullNamePayloadSchema = Joi.object({
firstName: Joi.string()
Expand Down
14 changes: 10 additions & 4 deletions src/server/common/model/answer/fullName/fullName.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FullNameAnswer } from './fullName.js'

const maxLength = 50

const validFullNamePayload = {
firstName: 'Jean-Luc',
lastName: 'Picard'
Expand Down Expand Up @@ -34,19 +36,23 @@ describe('#FullName.validate', () => {

it('should return false for input that is too long', () => {
const fullName = new FullNameAnswer({
firstName: Array(256).fill('a').join(''),
lastName: Array(256).fill('a').join('')
firstName: Array(maxLength + 1)
.fill('a')
.join(''),
lastName: Array(maxLength + 1)
.fill('a')
.join('')
})

const { isValid, errors } = fullName.validate()

expect(isValid).toBe(false)
expect(errors.firstName.text).toBe(
'First name must be no longer than 255 characters'
`First name must be no longer than ${maxLength} characters`
)

expect(errors.lastName.text).toBe(
'Last name must be no longer than 255 characters'
`Last name must be no longer than ${maxLength} characters`
)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class EmailPage extends Page {

lastNameError = 'Enter the last name of the County Parish Holding (CPH) owner'

firstNameLengthError = 'First name must be no longer than 255 characters'
firstNameLengthError = 'First name must be no longer than 50 characters'

lastNameLengthError = 'Last name must be no longer than 255 characters'
lastNameLengthError = 'Last name must be no longer than 50 characters'

firstNameInput() {
return super.getInputField(firstNameId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ownerNamePage from '../../page-objects/receiving-the-licence/ownerNamePage.js'
import receiveMethodPage from '../../page-objects/receiving-the-licence/receiveMethodPage.js'

const longString = 'a'.repeat(300)
const longString = 'a'.repeat(51)

describe('County parish owner name test', () => {
beforeEach('Reset browser state and navigate to page', async () => {
Expand Down

0 comments on commit 24c2a70

Please sign in to comment.