From 8108448f70e8711bcf378635c5dd997c7521aab0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Tue, 17 May 2022 23:20:45 +0530 Subject: [PATCH] Updated handling for default noreply support address - with content api, site support address can have value of default `noreply` - adds the default site domain for support address in case of missing domain --- ghost/portal/src/utils/helpers.js | 7 +++++++ ghost/portal/src/utils/helpers.test.js | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/ghost/portal/src/utils/helpers.js b/ghost/portal/src/utils/helpers.js index d99af91c03..83dbbe1d22 100644 --- a/ghost/portal/src/utils/helpers.js +++ b/ghost/portal/src/utils/helpers.js @@ -588,6 +588,13 @@ export const getMemberName = ({member}) => { export const getSupportAddress = ({site}) => { const {members_support_address: supportAddress} = site || {}; + + if (supportAddress.indexOf('@') < 0) { + const siteDomain = getSiteDomain({site}); + const updatedDomain = siteDomain?.replace(/^(www)\.(?=[^/]*\..{2,5})/, '') || ''; + return `${supportAddress}@${updatedDomain}`; + } + if (supportAddress?.split('@')?.length > 1) { const [recipient, domain] = supportAddress?.split('@'); const updatedDomain = domain?.replace(/^(www)\.(?=[^/]*\..{2,5})/, '') || ''; diff --git a/ghost/portal/src/utils/helpers.test.js b/ghost/portal/src/utils/helpers.test.js index a2d7dc7014..84c33fa163 100644 --- a/ghost/portal/src/utils/helpers.test.js +++ b/ghost/portal/src/utils/helpers.test.js @@ -213,6 +213,16 @@ describe('Helpers - ', () => { expect(supportAddress).toBe('jamie@example.com'); }); + + test('returns expected support address for default noreply value', () => { + let site = { + members_support_address: 'noreply', + url: 'https://www.example.com' + }; + const supportAddress = getSupportAddress({site}); + + expect(supportAddress).toBe('noreply@example.com'); + }); }); describe('getPriceIdFromPageQuery - ', () => {