|
| 1 | +import { |
| 2 | + RegexWordScript, |
| 3 | + RegexSubdomain, |
| 4 | + RegexSanitize, |
| 5 | + RegexObjectID, |
| 6 | + RegexContentTypeImage, |
| 7 | +} from './regex' |
| 8 | + |
| 9 | +describe('RegexWordScript', () => { |
| 10 | + test('should not match "script"', () => { |
| 11 | + expect(RegexWordScript.test('script')).toBe(false) |
| 12 | + }) |
| 13 | + |
| 14 | + test('should match valid words', () => { |
| 15 | + expect(RegexWordScript.test('validWord')).toBe(true) |
| 16 | + expect(RegexWordScript.test('anotherWord')).toBe(true) |
| 17 | + }) |
| 18 | +}) |
| 19 | + |
| 20 | +describe('RegexSubdomain', () => { |
| 21 | + test('should match valid subdomains', () => { |
| 22 | + expect(RegexSubdomain.test('example')).toBe(true) |
| 23 | + expect(RegexSubdomain.test('sub-domain')).toBe(true) |
| 24 | + expect(RegexSubdomain.test('123')).toBe(true) |
| 25 | + }) |
| 26 | + |
| 27 | + test('should not match invalid subdomains', () => { |
| 28 | + expect(RegexSubdomain.test('Invalid Subdomain')).toBe(false) |
| 29 | + expect(RegexSubdomain.test('sub_domain')).toBe(false) |
| 30 | + expect(RegexSubdomain.test('invalid@subdomain')).toBe(false) |
| 31 | + }) |
| 32 | +}) |
| 33 | + |
| 34 | +describe('RegexSanitize', () => { |
| 35 | + test('should match valid sanitized strings', () => { |
| 36 | + expect(RegexSanitize.test('Valid String 123,.-()\'"&')).toBe(true) |
| 37 | + expect(RegexSanitize.test('Another String')).toBe(true) |
| 38 | + }) |
| 39 | + |
| 40 | + test('should not match invalid sanitized strings', () => { |
| 41 | + expect(RegexSanitize.test('Invalid_String@123')).toBe(false) |
| 42 | + expect(RegexSanitize.test('Invalid!@#String')).toBe(false) |
| 43 | + }) |
| 44 | +}) |
| 45 | + |
| 46 | +describe('RegexObjectID Test', () => { |
| 47 | + test('Valid ObjectID should match the regex', () => { |
| 48 | + const validObjectID = '5f63a32b49ce3c4a8c4d8d1a' |
| 49 | + expect(validObjectID).toMatch(RegexObjectID) |
| 50 | + }) |
| 51 | + |
| 52 | + test('Invalid ObjectID should not match the regex', () => { |
| 53 | + const invalidObjectID = 'invalidObjectID' |
| 54 | + expect(invalidObjectID).not.toMatch(RegexObjectID) |
| 55 | + }) |
| 56 | + |
| 57 | + test('Empty string should not match the regex', () => { |
| 58 | + const emptyString = '' |
| 59 | + expect(emptyString).not.toMatch(RegexObjectID) |
| 60 | + }) |
| 61 | +}) |
| 62 | + |
| 63 | +describe('RegexContentTypeImage', () => { |
| 64 | + it('should match valid image content type', () => { |
| 65 | + const validContentTypes = [ |
| 66 | + 'image/jpeg', |
| 67 | + 'image/png', |
| 68 | + 'image/gif', |
| 69 | + 'image/svg+xml', |
| 70 | + ] |
| 71 | + |
| 72 | + validContentTypes.forEach((contentType) => { |
| 73 | + expect(RegexContentTypeImage.test(contentType)).toBe(true) |
| 74 | + }) |
| 75 | + }) |
| 76 | + |
| 77 | + it('should not match invalid content types', () => { |
| 78 | + const invalidContentTypes = [ |
| 79 | + 'text/plain', |
| 80 | + 'application/json', |
| 81 | + 'image', |
| 82 | + '', |
| 83 | + ] |
| 84 | + |
| 85 | + invalidContentTypes.forEach((contentType) => { |
| 86 | + expect(RegexContentTypeImage.test(contentType)).toBe(false) |
| 87 | + }) |
| 88 | + }) |
| 89 | +}) |
0 commit comments