Skip to content

Commit

Permalink
localLanguage object undefined cases and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-daniel-dempsey committed Aug 31, 2023
1 parent 954f037 commit 9e6eb80
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/server/src/api/epicRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 43 additions & 1 deletion packages/shared/src/lib/localLanguage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -67,7 +85,13 @@ describe('getCountryCodeToLocalLanguage', () => {
inputCountryCode: 'GB',
inputTestName: 'LOCAL-LANGUAGE',
inputVariant: 'CONTROL',
output: {},
output: undefined,
},
{
inputCountryCode: 'GB',
inputTestName: '',
inputVariant: '',
output: undefined,
},
{
inputCountryCode: 'US',
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions packages/shared/src/lib/localLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] ?? {
Expand Down

0 comments on commit 9e6eb80

Please sign in to comment.