From 9e6eb80ff1cd3cbec2293cc50e3707925e54bf1e Mon Sep 17 00:00:00 2001 From: Paul Dempsey <76729591+paul-daniel-dempsey@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:34:45 +0100 Subject: [PATCH] localLanguage object undefined cases and tests --- packages/server/src/api/epicRouter.ts | 6 +-- packages/shared/src/lib/localLanguage.test.ts | 44 ++++++++++++++++++- packages/shared/src/lib/localLanguage.ts | 6 ++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/packages/server/src/api/epicRouter.ts b/packages/server/src/api/epicRouter.ts index 3eb9b16a4..3e733677e 100644 --- a/packages/server/src/api/epicRouter.ts +++ b/packages/server/src/api/epicRouter.ts @@ -141,9 +141,9 @@ export const buildEpicRouter = ( const propsVariant = { ...variant, - heading: localLanguage.epicHeader ?? variant.heading, - paragraphs: localLanguage.epicParagraphs ?? variant.paragraphs, - highlightedText: localLanguage.epicHighlightedText ?? variant.highlightedText, + heading: localLanguage?.epicHeader ?? variant.heading, + paragraphs: localLanguage?.epicParagraphs ?? variant.paragraphs, + highlightedText: localLanguage?.epicHighlightedText ?? variant.highlightedText, tickerSettings, showReminderFields, choiceCardAmounts: variantAmounts, diff --git a/packages/shared/src/lib/localLanguage.test.ts b/packages/shared/src/lib/localLanguage.test.ts index 0e6ee2961..1796f3498 100644 --- a/packages/shared/src/lib/localLanguage.test.ts +++ b/packages/shared/src/lib/localLanguage.test.ts @@ -47,6 +47,24 @@ describe('getCountryCodeToLocalLanguage', () => { epicHighlightedText: `Highlight (Dutch)`, }, }, + { + inputCountryCode: 'NL', + inputTestName: 'LOCAL-LANGUAGE1', + inputVariant: 'CONTROL', + output: undefined, + }, + { + inputCountryCode: 'NL', + inputTestName: 'LOCAL-LANGUAGE', + inputVariant: 'CONTROL1', + output: undefined, + }, + { + inputCountryCode: 'NL', + inputTestName: '', + inputVariant: '', + output: undefined, + }, { inputCountryCode: 'SE', inputTestName: 'LOCAL-LANGUAGE', @@ -67,7 +85,13 @@ describe('getCountryCodeToLocalLanguage', () => { inputCountryCode: 'GB', inputTestName: 'LOCAL-LANGUAGE', inputVariant: 'CONTROL', - output: {}, + output: undefined, + }, + { + inputCountryCode: 'GB', + inputTestName: '', + inputVariant: '', + output: undefined, }, { inputCountryCode: 'US', @@ -103,6 +127,24 @@ describe('getCountryCodeToLocalLanguage', () => { epicHighlightedText: `Highlight`, }, }, + { + inputCountryCode: '', + inputTestName: '', + inputVariant: '', + output: undefined, + }, + { + inputCountryCode: '', + inputTestName: '', + inputVariant: '', + inputDefaultLocalLanguage: { + bannerHeader: 'BannerHeaderTest', + epicHeader: 'EpicHeaderTest', + epicParagraphs: ['1', '2', '3', '4', '5'], + epicHighlightedText: `Highlight`, + }, + output: undefined, + }, ]; countries.forEach( diff --git a/packages/shared/src/lib/localLanguage.ts b/packages/shared/src/lib/localLanguage.ts index e5cfcdbed..fa83b6448 100644 --- a/packages/shared/src/lib/localLanguage.ts +++ b/packages/shared/src/lib/localLanguage.ts @@ -51,10 +51,12 @@ export const countryCodeToVerfiedLocalLanguage = ( variantName: string, countryCode?: string, dfltLocalLanguage?: LocalLanguage, -): LocalLanguage => { +): LocalLanguage | undefined => { + const hasCountryLanguageOrDefault = localLanguages[countryCode] || dfltLocalLanguage; if ( testName === (LocalLanguageEpicTestName || LocalLanguageBannerTestName) && - variantName === (LocalLanguageEpicVariant || LocalLanguageBannerVariant) + variantName === (LocalLanguageEpicVariant || LocalLanguageBannerVariant) && + hasCountryLanguageOrDefault ) { return ( localLanguages[countryCode] ?? {