- Add double-click handler to make file names editable in UI - Remove duplicate IPC handler for rename-file in renderer.js - Fix checkEpisodeCountMatch to properly validate sequential episodes - Fix begin-mapping to handle both season folder and show folder cases - Improve open-file-in-player handler to properly log results
125 lines
4.9 KiB
JavaScript
125 lines
4.9 KiB
JavaScript
// Test file movement business logic
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Test folder name validation
|
|
test('File movement - should validate folder names', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify valid folder names
|
|
const validFolders = ['extra', 'behind-the-scenes', 'commentary', 'delete'];
|
|
validFolders.forEach(folder => {
|
|
assert.ok(mainJs.includes(folder), `Should validate ${folder} as valid folder`);
|
|
});
|
|
});
|
|
|
|
test('File movement - should map extra to extras', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes("actualFolderName = 'extras'"), 'Should map extra to extras');
|
|
assert.ok(mainJs.includes("folderName === 'extra'"), 'Should check for extra folder');
|
|
});
|
|
|
|
test('File movement - should map behind-the-scenes to behind the scenes', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes("actualFolderName = 'behind the scenes'"), 'Should map behind-the-scenes to behind the scenes');
|
|
assert.ok(mainJs.includes("folderName === 'behind-the-scenes'"), 'Should check for behind-the-scenes folder');
|
|
});
|
|
|
|
test('File movement - should handle delete folder', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify delete is in valid folders list
|
|
assert.ok(mainJs.includes("'delete'"), 'Should include delete in valid folders');
|
|
|
|
// Verify it's handled (either mapped or passed through as-is)
|
|
const deleteSection = mainJs.substring(
|
|
mainJs.indexOf('folderName === \'delete\''),
|
|
mainJs.indexOf('folderName === \'delete\'') + 200
|
|
);
|
|
assert.ok(deleteSection.length > 0, 'Delete folder handling should exist');
|
|
});
|
|
|
|
// Test folder creation
|
|
test('File movement - should create target folder if not exists', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('mkdirSync'), 'Should create directories');
|
|
assert.ok(mainJs.includes('recursive: true'), 'Should create recursively');
|
|
});
|
|
|
|
test('File movement - should handle existing folders', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify it checks if folder exists before creating
|
|
assert.ok(mainJs.includes('existsSync'), 'Should check if folder exists');
|
|
});
|
|
|
|
// Test file renaming
|
|
test('File movement - should preserve file extension', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('extname'), 'Should extract file extension');
|
|
assert.ok(mainJs.includes('basename'), 'Should preserve filename');
|
|
});
|
|
|
|
test('File movement - should check for existing file', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('existsSync'), 'Should check if file exists in target');
|
|
assert.ok(mainJs.includes('error'), 'Should return error if file exists');
|
|
});
|
|
|
|
// Test audit logging
|
|
test('File movement - should write audit log', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('writeAuditLog'), 'Should write audit log');
|
|
assert.ok(mainJs.includes('move_file'), 'Audit action should be move_file');
|
|
assert.ok(mainJs.includes('originalPath'), 'Should log original path');
|
|
assert.ok(mainJs.includes('newPath'), 'Should log new path');
|
|
});
|
|
|
|
// Test error handling in file movement
|
|
test('File movement - should handle file not found', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('existsSync'), 'Should check if file exists');
|
|
assert.ok(mainJs.includes('File does not exist'), 'Should return proper error message');
|
|
});
|
|
|
|
test('File movement - should handle permission errors', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('try'), 'Should use try-catch');
|
|
assert.ok(mainJs.includes('catch'), 'Should handle errors');
|
|
});
|
|
|
|
// Test file movement with quality suffix
|
|
test('Begin mapping - should include quality in filename', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('quality'), 'Should include quality information');
|
|
assert.ok(mainJs.includes('1080p') || mainJs.includes('720p'), 'Should handle quality formats');
|
|
});
|
|
|
|
test('Begin mapping - should handle missing quality', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
// Verify it handles cases where quality is not available
|
|
assert.ok(mainJs.includes('N/A'), 'Should handle N/A quality');
|
|
});
|
|
|
|
// Test episode range validation
|
|
test('Begin mapping - should validate episode range', () => {
|
|
const mainJs = fs.readFileSync('./main.js', 'utf8');
|
|
|
|
assert.ok(mainJs.includes('episodeStart'), 'Should handle episode start');
|
|
assert.ok(mainJs.includes('episodeEnd'), 'Should handle episode end');
|
|
assert.ok(mainJs.includes('episodeEnd > episodeStart'), 'Should handle ranges');
|
|
});
|
|
|
|
console.log('\n✅ All file movement business logic tests passed!'); |