Skip to content

Commit 1fb78a0

Browse files
@W-19143871 Fix for email validation on marketing consent capture: TLD must be more than 1 character.
1 parent 3b73293 commit 1fb78a0

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

packages/commerce-sdk-react/src/hooks/ShopperConsents/mutation.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import {act} from '@testing-library/react'
7+
import {act, waitFor} from '@testing-library/react'
88
import {ShopperConsentsTypes} from 'commerce-sdk-isomorphic'
99
import nock from 'nock'
1010
import {
@@ -95,6 +95,7 @@ describe('Cache update behavior', () => {
9595
test('invalidates `getSubscriptions` query', async () => {
9696
mockQueryEndpoint(consentsEndpoint, baseSubscriptionResponse)
9797
mockMutationEndpoints(consentsEndpoint, {})
98+
mockQueryEndpoint(consentsEndpoint, baseSubscriptionResponse)
9899
const {result} = renderHookWithProviders(() => {
99100
return {
100101
query: queries.useSubscriptions(queryOptions),
@@ -169,6 +170,7 @@ describe('Cache update behavior', () => {
169170
test('invalidates `getSubscriptions` query', async () => {
170171
mockQueryEndpoint(consentsEndpoint, baseSubscriptionResponse)
171172
mockMutationEndpoints(consentsEndpoint, {})
173+
mockQueryEndpoint(consentsEndpoint, baseSubscriptionResponse)
172174
const {result} = renderHookWithProviders(() => {
173175
return {
174176
query: queries.useSubscriptions(queryOptions),
@@ -259,10 +261,10 @@ describe('Cache update behavior', () => {
259261
)
260262
await waitAndExpectSuccess(() => result.current.mutation)
261263

262-
// Wait for automatic refetch
263-
await waitAndExpectSuccess(() => result.current.query)
264-
// Should have fresh data, not stale
265-
expect(result.current.query.data?.data).toHaveLength(2)
264+
// Wait for refetch to complete with fresh data
265+
await waitFor(() => {
266+
expect(result.current.query.data?.data).toHaveLength(2)
267+
})
266268
expect(result.current.query.data).toEqual(freshResponse)
267269
})
268270
})

packages/template-retail-react-app/app/utils/email-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
export const isValidEmail = (email) => {
1515
const emailRegex =
16-
/^[\p{L}\p{N}._!#$%&'*+/=?^`{|}~-]+@(?:[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?\.)+[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?$/u
16+
/^[\p{L}\p{N}._!#$%&'*+/=?^`{|}~-]+@(?:[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?\.)+[\p{L}\p{N}][\p{L}\p{N}-]{0,61}[\p{L}\p{N}]$/u
1717

1818
return emailRegex.test(email)
1919
}

packages/template-retail-react-app/app/utils/email-utils.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ describe('isValidEmail', () => {
150150
test('should return false for email with hyphen at end of domain part', () => {
151151
expect(isValidEmail('test@example-.com')).toBe(false)
152152
})
153+
154+
test('should return false for single-character TLD', () => {
155+
expect(isValidEmail('test@example.o')).toBe(false)
156+
expect(isValidEmail('test@example.c')).toBe(false)
157+
})
158+
})
159+
160+
describe('TLD length', () => {
161+
test('should accept two-character TLDs', () => {
162+
expect(isValidEmail('test@example.co')).toBe(true)
163+
expect(isValidEmail('test@example.uk')).toBe(true)
164+
})
165+
166+
test('should accept longer TLDs', () => {
167+
expect(isValidEmail('test@example.com')).toBe(true)
168+
expect(isValidEmail('test@example.museum')).toBe(true)
169+
expect(isValidEmail('test@example.travel')).toBe(true)
170+
})
153171
})
154172
})
155173

0 commit comments

Comments
 (0)