32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import {
|
|
describe,
|
|
expect,
|
|
it
|
|
} from 'vitest';
|
|
|
|
import { buildAttachmentExportFileName } from './attachment-export.rules';
|
|
|
|
describe('buildAttachmentExportFileName', () => {
|
|
it('appends the timestamp before the extension so exports never collide', () => {
|
|
expect(buildAttachmentExportFileName('report.pdf', 1_720_900_000_000)).toBe('report-1720900000000.pdf');
|
|
});
|
|
|
|
it('appends the timestamp at the end when there is no extension', () => {
|
|
expect(buildAttachmentExportFileName('README', 42)).toBe('README-42');
|
|
});
|
|
|
|
it('keeps dotfiles intact instead of treating the leading dot as an extension', () => {
|
|
expect(buildAttachmentExportFileName('.env', 42)).toBe('.env-42');
|
|
});
|
|
|
|
it('strips directory components from the filename', () => {
|
|
expect(buildAttachmentExportFileName('../secret/../../etc/passwd.txt', 7)).toBe('passwd-7.txt');
|
|
expect(buildAttachmentExportFileName('folder\\file.bin', 7)).toBe('file-7.bin');
|
|
});
|
|
|
|
it('falls back to a generic name when the filename is empty after sanitising', () => {
|
|
expect(buildAttachmentExportFileName(' ', 7)).toBe('attachment-7');
|
|
expect(buildAttachmentExportFileName('a/b/', 7)).toBe('attachment-7');
|
|
});
|
|
});
|