From 0972223318bc7448109b46c422d2805bf9b265f9 Mon Sep 17 00:00:00 2001 From: Nikunj Maniya Date: Fri, 27 Sep 2024 11:03:16 +0530 Subject: [PATCH] fix: test cases added for the new patterns --- src/types/Patterns.test.ts | 27 +++++++++++++++++++++++++++ src/types/Patterns.ts | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/types/Patterns.test.ts b/src/types/Patterns.test.ts index 601842341..3040fdf3b 100644 --- a/src/types/Patterns.test.ts +++ b/src/types/Patterns.test.ts @@ -29,6 +29,7 @@ import { isCountryCode, isClientID, isPersonName, + isSearchUserEmail, } from './Patterns' const TESTDATA = { @@ -214,6 +215,23 @@ const TESTDATA = { valid: ['sa-12', 'JSSS', 'Julia12'], invalid: ['&^%#@', '!', 'hash &*^#$'], }, + EMAIL_SEARCH: { + valid: [ + 'john.doe@example.com', + 'jane_doe123@example.com', + 'user+tag@example.com', + 'email@sub.domain.com', + 'first.last@another-domain.org', + 'name-with-dash@example-company.com', + 'name.surname@domain.travel', + 'name123@domain.ac', + 'firstname+lastname@example.com', + 'very.common@example.com', + 'disposable.style.email.with+symbol@example.com', + 'admin@admin-portal.co.uk', + ], + invalid: ['()*&^%$#/\\?><,`~'], + }, } describe('Input Pattern Tests', () => { @@ -304,4 +322,13 @@ describe('Input Pattern Tests', () => { expect(isClientID(expr)).toBe(false) }) }) + + it('Validate email search for users', () => { + TESTDATA.EMAIL_SEARCH.valid.forEach((expr) => { + expect(isSearchUserEmail(expr)).toBe(true) + }) + TESTDATA.EMAIL_SEARCH.invalid.forEach((expr) => { + expect(isSearchUserEmail(expr)).toBe(false) + }) + }) }) diff --git a/src/types/Patterns.ts b/src/types/Patterns.ts index 9191d27f6..8bf6a0ff8 100644 --- a/src/types/Patterns.ts +++ b/src/types/Patterns.ts @@ -209,5 +209,7 @@ export const isCompanyVies = (expr: string) => Patterns.companyData.VIES.test(expr) export const isPostalCode = (expr: string) => Patterns.companyData.POSTAL_CODE.test(expr) +export const isSearchUserEmail = (expr: string) => + Patterns.EMAIL_SEARCH.test(expr) export default Patterns