|
| 1 | +/* eslint-disable i18nhelper/no-jp-string */ |
| 2 | +import { convertToSafeFilename } from '../../../lambda/utils/fileNameUtils'; |
| 3 | + |
| 4 | +describe('convertToSafeFilename', () => { |
| 5 | + it('should return filename without hash when only ASCII characters', () => { |
| 6 | + const result = convertToSafeFilename('document.pdf'); |
| 7 | + expect(result).toBe('document'); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should return filename without hash for ASCII with allowed special chars', () => { |
| 11 | + const result = convertToSafeFilename('report-2024 (final)[v1].pdf'); |
| 12 | + expect(result).toBe('report-2024 (final)[v1]'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should add hash when Japanese characters are present', () => { |
| 16 | + const result = convertToSafeFilename('θ³ζ.pdf'); |
| 17 | + expect(result).toBe('___46a890b2'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should add hash when mixed Japanese and ASCII characters', () => { |
| 21 | + const result = convertToSafeFilename('reportθ³ζ2024.pdf'); |
| 22 | + expect(result).toBe('report__2024_f3805637'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should generate different hashes for different Japanese filenames with same length', () => { |
| 26 | + const result1 = convertToSafeFilename('θ³ζ.pdf'); |
| 27 | + const result2 = convertToSafeFilename('ζΈι‘.pdf'); |
| 28 | + expect(result1).toBe('___46a890b2'); |
| 29 | + expect(result2).toBe('___5c4aa342'); |
| 30 | + expect(result1).not.toBe(result2); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should generate consistent hash for same filename', () => { |
| 34 | + const result1 = convertToSafeFilename('θ³ζ.pdf'); |
| 35 | + const result2 = convertToSafeFilename('θ³ζ.pdf'); |
| 36 | + expect(result1).toBe('___46a890b2'); |
| 37 | + expect(result2).toBe('___46a890b2'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should handle filename without extension', () => { |
| 41 | + const result = convertToSafeFilename('document'); |
| 42 | + expect(result).toBe('document'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should handle filename with multiple dots', () => { |
| 46 | + const result = convertToSafeFilename('report.final.pdf'); |
| 47 | + expect(result).toBe('report_final_8d101382'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should replace special characters with underscore and add hash', () => { |
| 51 | + const result = convertToSafeFilename('file@#$.pdf'); |
| 52 | + expect(result).toBe('file____cf25ced4'); |
| 53 | + }); |
| 54 | +}); |
0 commit comments