diff --git a/src/lib/storage/checks.test.ts b/src/lib/storage/checks.test.ts index c6b97ca2..af5a7e24 100644 --- a/src/lib/storage/checks.test.ts +++ b/src/lib/storage/checks.test.ts @@ -1,10 +1,30 @@ -import { hasMarkdownFileName } from './checks'; +import { hasMarkdownFileName, isPotentialZipFile } from './checks'; + +const FILE_MD = 'abc.md'; +const FILE_TXT = 'def.txt'; +const FILE_MD_UPPER = 'cool.MD'; + +const NO_EXTENSION = 'file'; +const ENDS_WITH_PERIOD = 'file.'; +const HAS_EXTENSION_ZIP = 'file.zip'; +const HAS_EXTENSION_TXT = 'file.txt'; +const HAS_EXTENSION_TAR_GZ = 'file.tar.gz'; +const ENDS_WITH_DOUBLE_PERIOD = 'file..'; test('hasMarkdownFileName returns true', () => { - expect(hasMarkdownFileName(['abc.md', 'def.txt'])).toBe(true); - expect(hasMarkdownFileName(['cool.MD'])).toBe(true); + expect(hasMarkdownFileName([FILE_MD, FILE_TXT])).toBe(true); + expect(hasMarkdownFileName([FILE_MD_UPPER])).toBe(true); }); test('hasMarkdownFileName returns false', () => { - expect(hasMarkdownFileName(['abc.txt', 'def.txt'])).toBe(false); + expect(hasMarkdownFileName([FILE_TXT, FILE_TXT])).toBe(false); +}); + +test('isPotentialZipFile identifies potential zip files', () => { + expect(isPotentialZipFile(NO_EXTENSION)).toBe(true); + expect(isPotentialZipFile(ENDS_WITH_PERIOD)).toBe(true); + expect(isPotentialZipFile(HAS_EXTENSION_ZIP)).toBe(false); + expect(isPotentialZipFile(HAS_EXTENSION_TXT)).toBe(false); + expect(isPotentialZipFile(HAS_EXTENSION_TAR_GZ)).toBe(false); + expect(isPotentialZipFile(ENDS_WITH_DOUBLE_PERIOD)).toBe(true); }); diff --git a/src/lib/storage/checks.ts b/src/lib/storage/checks.ts index 723477f9..5b7aafca 100644 --- a/src/lib/storage/checks.ts +++ b/src/lib/storage/checks.ts @@ -32,5 +32,6 @@ export const isPDFFile = (fileName: string) => /.pdf$/i.exec(fileName); * @param filename * @returns */ -export const isPotentialZipFile = (filename: string): boolean => - !filename.includes('.'); +export const isPotentialZipFile = (filename: string): boolean => { + return filename.trim().endsWith('.') || !filename.includes('.'); +};