Skip to content

Commit

Permalink
Merge pull request #7423 from uktrade/fix/TET-934-create-company-error
Browse files Browse the repository at this point in the history
Fix postcode field.
  • Loading branch information
elcct authored Dec 20, 2024
2 parents 9450f2c + 6f3c43c commit c295b78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ describe('Postcode to region mapping', () => {
const invalidPostcode3 = 'A12'
const invalidPostcode4 = undefined
const invalidPostcode5 = null
const invalidPostcode6 = 'SW11'
expect(mapPostcodeToRegion(invalidPostcode1)).to.equal('')
expect(mapPostcodeToRegion(invalidPostcode2)).to.equal('')
expect(mapPostcodeToRegion(invalidPostcode3)).to.equal('')
expect(mapPostcodeToRegion(invalidPostcode4)).to.equal('')
expect(mapPostcodeToRegion(invalidPostcode5)).to.equal('')
expect(mapPostcodeToRegion(invalidPostcode6)).to.equal('')
})
})

Expand Down
6 changes: 5 additions & 1 deletion src/apps/companies/apps/add-company/client/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ export const mapPostcodeToRegion = (postcode) => {
) {
return postcode
}
const area = outcode.split(outcode.match(/\d+/)[0])[0]
const numericMatch = outcode.match(/\d+/)
if (!numericMatch) {
return ''
}
const area = outcode.split(numericMatch[0])[0]
return POSTCODE_AREA_TO_REGION[area]
}
}

0 comments on commit c295b78

Please sign in to comment.