Auth.constants.test.ts52 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { urlRegex } from '@/components/interfaces/Auth/Auth.constants' |
| 4 | |
| 5 | describe('Auth.constants: urlRegex', () => { |
| 6 | it('should match valid URLs', () => { |
| 7 | const validUrls = [ |
| 8 | 'http://domain.com', |
| 9 | 'https://supabase.io', |
| 10 | 'https://new-domain-vercel.com', |
| 11 | 'www.test-domain.com', |
| 12 | 'exp://exp.host/some-app', |
| 13 | 'exp://exp.host/some-app?release-channel=default', |
| 14 | 'https://supabase.com/dashboard', |
| 15 | 'http://localhost:3000', |
| 16 | 'https://supabase.com?name=test', |
| 17 | 'https://supabase.com?name=test&description=hello&page=2', |
| 18 | 'https://briven*.com', |
| 19 | 'https://supabase.com/*', |
| 20 | 'https://new-*-domain.com/*', |
| 21 | 'https://new-*-domain.com/*/*/*', |
| 22 | 'https://sub-*-domain.new-*-domain.com/*/*/*', |
| 23 | ] |
| 24 | |
| 25 | validUrls.forEach((url) => { |
| 26 | expect(urlRegex().test(url)).toBe(true) |
| 27 | }) |
| 28 | }) |
| 29 | |
| 30 | it('should not match invalid URLs', () => { |
| 31 | const invalidUrls = ['briven', 'mailto:test@gmail.com', 'hello world.com', 'email@domain.com'] |
| 32 | |
| 33 | const failingInvalidUrls = invalidUrls.filter((url) => urlRegex().test(url)) |
| 34 | if (failingInvalidUrls.length > 0) { |
| 35 | console.log('Failing invalid URLs:', failingInvalidUrls) |
| 36 | } |
| 37 | |
| 38 | invalidUrls.forEach((url) => { |
| 39 | expect(urlRegex().test(url)).toBe(false) |
| 40 | }) |
| 41 | }) |
| 42 | |
| 43 | it('should not match simple domain URLs when excludeSimpleDomains is true', () => { |
| 44 | const simpleDomainUrl = 'smtp-pulse.com' |
| 45 | expect(urlRegex({ excludeSimpleDomains: true }).test(simpleDomainUrl)).toBe(false) |
| 46 | }) |
| 47 | |
| 48 | it('should match simple domain URLs when excludeSimpleDomains is false', () => { |
| 49 | const simpleDomainUrl = 'smtp-pulse.com' |
| 50 | expect(urlRegex({ excludeSimpleDomains: false }).test(simpleDomainUrl)).toBe(true) |
| 51 | }) |
| 52 | }) |