From d388eef59f117f6f6e099e1c1408ddd73f827272 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Fri, 19 Jun 2020 10:42:34 -0400 Subject: [PATCH] renamed lookupCountryInfo and lookupCountryName functions --- src/components/registration/steps.jsx | 4 ++-- src/lib/country-data.js | 4 ++-- test/unit/lib/country-data.test.js | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/registration/steps.jsx b/src/components/registration/steps.jsx index f90b0f637..a6c6e9d08 100644 --- a/src/components/registration/steps.jsx +++ b/src/components/registration/steps.jsx @@ -456,7 +456,7 @@ class DemographicsStep extends React.Component { // look up country name using user's country code selection ('us' -> 'United States') getCountryName (values) { if (values.countryCode) { - const countryInfo = countryData.lookupCountryInfo(values.countryCode); + const countryInfo = countryData.lookupCountryByCode(values.countryCode); if (countryInfo) { return countryInfo.name; } @@ -466,7 +466,7 @@ class DemographicsStep extends React.Component { // look up country code from country label ('United States' -> 'us') // if `countryName` is not found, including if it's null or undefined, then this function will return undefined. getCountryCode (countryName) { - const country = countryData.lookupCountryName(countryName); + const country = countryData.lookupCountryByName(countryName); return country && country.code; } handleValidSubmit (formData) { diff --git a/src/lib/country-data.js b/src/lib/country-data.js index ce2405e58..b88d0a2d3 100644 --- a/src/lib/country-data.js +++ b/src/lib/country-data.js @@ -1036,11 +1036,11 @@ const countryOptions = module.exports.countryOptions = (startingCountryInfo, val )) ); -module.exports.lookupCountryInfo = countryCode => ( +module.exports.lookupCountryByCode = countryCode => ( countryInfo.find(country => country.code === countryCode) ); -module.exports.lookupCountryName = countryName => ( +module.exports.lookupCountryByName = countryName => ( countryInfo.find(country => country.name === countryName) ); diff --git a/test/unit/lib/country-data.test.js b/test/unit/lib/country-data.test.js index 5768e62dd..4b7ebecd6 100644 --- a/test/unit/lib/country-data.test.js +++ b/test/unit/lib/country-data.test.js @@ -1,7 +1,8 @@ const { countryInfo, countryOptions, - lookupCountryInfo, + lookupCountryByCode, + lookupCountryByName, dupeCommonCountries, registrationCountryCodeOptions, registrationCountryNameOptions, @@ -45,9 +46,17 @@ describe('unit test lib/country-data.js', () => { expect(szInfo.label).toEqual('Eswatini'); }); - test('lookupCountryInfo() will find country info', () => { - expect(typeof lookupCountryInfo).toBe('function'); - const eswatiniInfo = lookupCountryInfo('sz'); + test('lookupCountryByCode() will find country info', () => { + expect(typeof lookupCountryByCode).toBe('function'); + const eswatiniInfo = lookupCountryByCode('sz'); + expect(eswatiniInfo.name).toEqual('Swaziland'); + expect(eswatiniInfo.display).toEqual('Eswatini'); + expect(eswatiniInfo.code).toEqual('sz'); + }); + + test('lookupCountryByName() will find country info', () => { + expect(typeof lookupCountryByName).toBe('function'); + const eswatiniInfo = lookupCountryByName('Swaziland'); expect(eswatiniInfo.name).toEqual('Swaziland'); expect(eswatiniInfo.display).toEqual('Eswatini'); expect(eswatiniInfo.code).toEqual('sz');