feat: implement path based operations
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
import { KDrive } from '../src/nodes/KDrive/KDrive.node';
|
||||
import {
|
||||
kdriveApiRequest,
|
||||
handleApiError,
|
||||
resolvePathToId,
|
||||
parsePath,
|
||||
normalizePath,
|
||||
resolveIdToPath,
|
||||
clearPathCache
|
||||
} from '../src/nodes/KDrive/GenericFunctions';
|
||||
|
||||
describe('KDrive Node', () => {
|
||||
let kdriveNode: KDrive;
|
||||
|
||||
beforeEach(() => {
|
||||
kdriveNode = new KDrive();
|
||||
});
|
||||
|
||||
describe('Node Description', () => {
|
||||
it('should have correct node description', () => {
|
||||
expect(kdriveNode.description.displayName).toBe('kDrive');
|
||||
expect(kdriveNode.description.name).toBe('kDrive');
|
||||
expect(kdriveNode.description.group).toContain('transform');
|
||||
expect(kdriveNode.description.version).toBe(1);
|
||||
});
|
||||
|
||||
it('should have required credentials', () => {
|
||||
expect(kdriveNode.description.credentials).toBeDefined();
|
||||
if (kdriveNode.description.credentials) {
|
||||
expect(kdriveNode.description.credentials.length).toBe(1);
|
||||
expect(kdriveNode.description.credentials[0].name).toBe('kDriveApi');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Node Properties', () => {
|
||||
it('should have authentication property', () => {
|
||||
const authProperty = kdriveNode.description.properties.find(p => p.name === 'authentication');
|
||||
expect(authProperty).toBeDefined();
|
||||
if (authProperty) {
|
||||
expect(authProperty.type).toBe('options');
|
||||
}
|
||||
});
|
||||
|
||||
it('should have resource property', () => {
|
||||
const resourceProperty = kdriveNode.description.properties.find(p => p.name === 'resource');
|
||||
expect(resourceProperty).toBeDefined();
|
||||
if (resourceProperty) {
|
||||
expect(resourceProperty.type).toBe('options');
|
||||
}
|
||||
});
|
||||
|
||||
it('should have operation property', () => {
|
||||
const operationProperty = kdriveNode.description.properties.find(p => p.name === 'operation');
|
||||
expect(operationProperty).toBeDefined();
|
||||
if (operationProperty) {
|
||||
expect(operationProperty.type).toBe('options');
|
||||
}
|
||||
});
|
||||
|
||||
it('should have path-based operation options', () => {
|
||||
const operationProperty = kdriveNode.description.properties.find(p => p.name === 'operation') as any;
|
||||
expect(operationProperty).toBeDefined();
|
||||
if (operationProperty && operationProperty.options) {
|
||||
const operationValues = operationProperty.options.map((opt: any) => opt.value);
|
||||
expect(operationValues).toContain('getFileInfoByPath');
|
||||
expect(operationValues).toContain('uploadFileByPath');
|
||||
expect(operationValues).toContain('downloadFileByPath');
|
||||
expect(operationValues).toContain('deleteFileByPath');
|
||||
expect(operationValues).toContain('getFileVersionsByPath');
|
||||
}
|
||||
});
|
||||
|
||||
it('should have path-based parameters', () => {
|
||||
const filePathParam = kdriveNode.description.properties.find(p => p.name === 'filePath');
|
||||
expect(filePathParam).toBeDefined();
|
||||
|
||||
const directoryPathParam = kdriveNode.description.properties.find(p => p.name === 'directoryPath');
|
||||
expect(directoryPathParam).toBeDefined();
|
||||
|
||||
const uploadPathParam = kdriveNode.description.properties.find(p => p.name === 'uploadPath');
|
||||
expect(uploadPathParam).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Generic Functions', () => {
|
||||
describe('kdriveApiRequest', () => {
|
||||
it('should be a function', () => {
|
||||
expect(typeof kdriveApiRequest).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleApiError', () => {
|
||||
it('should be a function', () => {
|
||||
expect(typeof handleApiError).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Path Resolution Functions', () => {
|
||||
describe('normalizePath', () => {
|
||||
it('should normalize Windows paths', () => {
|
||||
expect(normalizePath('documents\\file.txt')).toBe('documents/file.txt');
|
||||
});
|
||||
|
||||
it('should handle leading/trailing slashes', () => {
|
||||
expect(normalizePath('/documents/file.txt/')).toBe('documents/file.txt');
|
||||
expect(normalizePath('///documents///file.txt///')).toBe('documents/file.txt');
|
||||
});
|
||||
|
||||
it('should handle empty path as root', () => {
|
||||
expect(normalizePath('')).toBe('root');
|
||||
expect(normalizePath('/')).toBe('root');
|
||||
expect(normalizePath('///')).toBe('root');
|
||||
});
|
||||
|
||||
it('should handle root path', () => {
|
||||
expect(normalizePath('root')).toBe('root');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parsePath', () => {
|
||||
it('should parse simple paths', () => {
|
||||
expect(parsePath('file.txt')).toEqual(['file.txt']);
|
||||
});
|
||||
|
||||
it('should parse nested paths', () => {
|
||||
expect(parsePath('documents/project/file.txt')).toEqual(['documents', 'project', 'file.txt']);
|
||||
});
|
||||
|
||||
it('should handle root path', () => {
|
||||
expect(parsePath('root')).toEqual(['root']);
|
||||
});
|
||||
|
||||
it('should normalize before parsing', () => {
|
||||
expect(parsePath('/documents//project///file.txt/')).toEqual(['documents', 'project', 'file.txt']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearPathCache', () => {
|
||||
it('should be a function', () => {
|
||||
expect(typeof clearPathCache).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolvePathToId and resolveIdToPath', () => {
|
||||
it('should be functions', () => {
|
||||
expect(typeof resolvePathToId).toBe('function');
|
||||
expect(typeof resolveIdToPath).toBe('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user