Skip to content

Commit

Permalink
fix: fixed slashPathType()
Browse files Browse the repository at this point in the history
  • Loading branch information
dereekb committed Jul 5, 2022
1 parent 5bae759 commit 180f2d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion packages/util/src/lib/path/path.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { replaceInvalidFilePathTypeSeparatorsInSlashPath, slashPathFactory, slashPathName, slashPathValidationFactory } from './path';
import { replaceInvalidFilePathTypeSeparatorsInSlashPath, slashPathFactory, slashPathName, slashPathValidationFactory, SlashPathFolder, slashPathType, SlashPathTypedFile, SlashPathFile } from './path';

describe('slashPathName', () => {
it('should return the file name', () => {
Expand All @@ -14,6 +14,26 @@ describe('slashPathName', () => {
});
});

describe('slashPathType', () => {
it('should identify a typed file', () => {
const typedFilePath: SlashPathTypedFile = 'wMNzlhSlp6Gb93V8u4Rs/CCCC_KGML3FKTP.pdf';
const type = slashPathType(typedFilePath);
expect(type).toBe('typedfile');
});

it('should identify a file', () => {
const path: SlashPathFile = 'wMNzlhSlp6Gb93V8u4Rs/CCCC_KGML3FKTP';
const type = slashPathType(path);
expect(type).toBe('file');
});

it('should identify a folder', () => {
const folderPath: SlashPathFolder = 'wMNzlhSlp6Gb93V8u4Rs/';
const type = slashPathType(folderPath);
expect(type).toBe('folder');
});
});

describe('replaceInvalidFilePathTypeSeparatorsInSlashPath()', () => {
it('should replace all extra file path type separators', () => {
const value = '/path/to/file.who.thought.about.it.test.png';
Expand Down
4 changes: 2 additions & 2 deletions packages/util/src/lib/path/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type SlashPathType = 'folder' | 'file' | 'typedfile' | 'invalid';
* @returns
*/
export function slashPathType(input: SlashPath): SlashPathType {
const dotCount = input.split(SLASH_PATH_FILE_TYPE_SEPARATOR, 2).length;
const dotCount = input.split(SLASH_PATH_FILE_TYPE_SEPARATOR, 2).length - 1;
let type: SlashPathType;

switch (dotCount) {
Expand All @@ -76,7 +76,7 @@ export function slashPathType(input: SlashPath): SlashPathType {
}
break;
case 1:
type = 'file';
type = 'typedfile';
break;
default:
type = 'invalid';
Expand Down

0 comments on commit 180f2d6

Please sign in to comment.