From d9cbbb9076f19b479932bf8deaf4d024bc1fd20b Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 19 Jul 2023 11:11:43 +0200 Subject: [PATCH] more tests --- babel.config.cjs | 12 ++ babel.config.js | 7 - tests/finder.test.js | 38 +++- utils/finder.mjs | 6 +- utils/workInProgress/not_ready_functions.mjs | 205 ++++++++++--------- 5 files changed, 148 insertions(+), 120 deletions(-) create mode 100644 babel.config.cjs delete mode 100644 babel.config.js diff --git a/babel.config.cjs b/babel.config.cjs new file mode 100644 index 0000000..246d56b --- /dev/null +++ b/babel.config.cjs @@ -0,0 +1,12 @@ +const presets = [ + [ + "@babel/preset-env", + { + targets: { + node: 'current' + } + } + ] +]; + +module.exports = { presets }; \ No newline at end of file diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index fbeebd3..0000000 --- a/babel.config.js +++ /dev/null @@ -1,7 +0,0 @@ -const presets = [ - [ - "@babel/preset-env", - ] -]; - -module.exports = { presets }; \ No newline at end of file diff --git a/tests/finder.test.js b/tests/finder.test.js index af40e3f..f6eca2f 100644 --- a/tests/finder.test.js +++ b/tests/finder.test.js @@ -44,24 +44,20 @@ describe('detection in file name', () => { describe('modification in file name', () => { - let fileNameOriginal = 'mon texte -- famille vacances plage.jpg' - let properties = finder.destructurateFileName(fileNameOriginal) + test('should append to file name in the right place', () => { + let fileNameOriginal = 'mon texte -- famille vacances plage.jpg' + let properties = finder.destructurateFileName(fileNameOriginal) let modifiedProperties = finder.appendFileName(properties, 'ajouté à la fin du texte libre') expect( modifiedProperties.freeText ) .toBe('mon texte ajouté à la fin du texte libre') }) - test('should prepend to file name in the right place', () => { - let modifiedProperties = finder.prependFileName(properties, 'ajouté au début du texte libre ') - expect( - modifiedProperties.freeText - ) - .toBe('ajouté au début du texte libre mon texte') - }) + test('should replace text in file name', () => { + let fileNameOriginal = 'mon texte -- famille vacances plage.jpg' let searchString = 'vacances', replaceString = 'machin' let replacedString = finder.searchAndReplaceInFileName(searchString, replaceString, fileNameOriginal) expect( @@ -70,6 +66,25 @@ describe('modification in file name', () => { .toBe('mon texte -- famille machin plage.jpg') }) + test('should prepend to file name in the right place', () => { + let fileNameOriginal = 'mon texte.jpg' + let properties = finder.destructurateFileName(fileNameOriginal) + let modifiedProperties = finder.prependFileName(properties, 'au début') + expect( + modifiedProperties.freeText + ) + .toBe('au début mon texte') + }) + + test('should clean spaces', () => { + let fileNameOriginal = ' mon texte - - -- bidule un truc ' + + expect( + finder.cleanSpaces(fileNameOriginal) + ) + .toBe('mon texte - - -- bidule un truc') + }) + }) describe('modifications with tags', () => { @@ -84,6 +99,7 @@ describe('modifications with tags', () => { .toStrictEqual([]) }) + test('should list existing tags in file name', () => { let fileNameOriginal = 'mon nom -- carte bidule.jpg' let otherProperties = finder.destructurateFileName(fileNameOriginal) @@ -91,11 +107,11 @@ describe('modifications with tags', () => { expect( otherProperties.tags ) - .toStrictEqual(['carte','bidule']) + .toStrictEqual(['carte', 'bidule']) }) - test('should add tag in file name', () => { + test('should add tag in file name', () => { let newTag = 'illustration' let newName = finder.addTagInFileName(newTag, fileNameOriginal) diff --git a/utils/finder.mjs b/utils/finder.mjs index 730ccbc..55224f1 100644 --- a/utils/finder.mjs +++ b/utils/finder.mjs @@ -114,7 +114,7 @@ export default class finder { } static cleanSpaces (inputString) { - return inputString.trim().replace(/ *g/, ' ') + return inputString.trim().replace(/ *g/, ' ').replace(/ /, ' ') } static searchAndReplaceInFileName (searchString, replaceString, fileName) { @@ -269,9 +269,7 @@ export default class finder { } } - static findTemplateInFileName (fileName) { - // test all templates from configuration - } + static appendFileName (fileProperties, newText) { fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText) diff --git a/utils/workInProgress/not_ready_functions.mjs b/utils/workInProgress/not_ready_functions.mjs index 0b9ce7e..229bb60 100644 --- a/utils/workInProgress/not_ready_functions.mjs +++ b/utils/workInProgress/not_ready_functions.mjs @@ -8,119 +8,128 @@ import fs from 'node-fs' --------------------------------------------------------------------- **/ -function LogActionRun(){ - // get file which contains logs - // add an entry - // persist log file -} +class notReadyFunctions { -function ListActions(idOfAction){ - // retrieve log of actions from file -} -function RevertAction(idOfAction){ - // select action and run all renames in the other way -} -function RevertMultipleActionsUntil(idOfAction){ - // select action and run all renames in the other way for each point in time -} - -function TestDownloadedTelegramPictureRename (fileName) { - let fileProperties = destructurateFileName(fileName) -} - -function hasDifferentDateInNameThanExif (fileName) { - let foundDate = finder.findFormattedDate(fileName) - - if (foundDate && foundDate != getExifCreationDate(fileName)) { - return true + static LogActionRun () { + // get file which contains logs + // add an entry + // persist log file } - return false -} -function moveToArchive (targetDirectory, fileFullPath) { - // find current directory, - // rename file to move it -} - -function getStatisticsOnArchiveFolder (fileFullPath) { - - return { - foldersCount: 'TODO', - filesWithoutSemanticName: 'TODO' + static ListActions (idOfAction) { + // retrieve log of actions from file } -} -/** - * list all tags - * @param fileFullPath - * @returns {[]} - */ -function getControlledVocabularyFromFiles (fileFullPath) { - - // find all tags - let listOfTags = [] - - return listOfTags; -} - -function moveToSortingFolder (fileFullPath) { - return 'TODO' -} - -/** - * écrit un nouveau nom de fichier formatté - * @param convertedToName - * @param originalFileName - * @returns {*} - */ -function mixDateNameWithFileName (convertedToName, originalFileName) { - // enlever l'ancien timestamp si il existe - // ajouter en début de nom le nouveau timestamp avec un espace et conserver le reste du nom - return originalFileName -} - -function TestMixingName () { - - let fileMixedNewName = mixDateNameWithFileName(convertedToName, originalFileName) - console.log('new name', fileMixedNewName) - - if (fileMixedNewName !== originalFileName) { - console.log('renommage =>', fileMixedNewName) - // renameFile(originalFileName, fileMixedNewName) + static RevertAction (idOfAction) { + // select action and run all renames in the other way } -} + static RevertMultipleActionsUntil (idOfAction) { + // select action and run all renames in the other way for each point in time + } + static findTemplateInFileName (fileName) { + // test all templates from configuration + } -/** - * obtenir une liste des dossiers uniquement dans le dossier courant - * @param path - * @returns {*} - */ -function getDirectories (path) { - return fs.readdirSync(path).filter(function (file) { - return fs.statSync(path + '/' + file).isDirectory() - }) -} + static TestDownloadedTelegramPictureRename (fileName) { + let fileProperties = destructurateFileName(fileName) + } + static hasDifferentDateInNameThanExif (fileName) { + let foundDate = finder.findFormattedDate(fileName) -function convertDateToTimeInFileName (inputDate) { - return inputDate.replace(' ', 'T') -} + if (foundDate && foundDate != getExifCreationDate(fileName)) { + return true + } + return false + } -function testthings(){ - // let list = getDirectories(pathFolder) + static moveToArchive (targetDirectory, fileFullPath) { + // find current directory, + // rename file to move it + } + + static getStatisticsOnArchiveFolder (fileFullPath) { + + return { + foldersCount: 'TODO', + filesWithoutSemanticName: 'TODO' + } + } + + /** + * list all tags + * @param fileFullPath + * @returns {[]} + */ + static getControlledVocabularyFromFiles (fileFullPath) { + + // find all tags + let listOfTags = [] + + return listOfTags + } + + static moveToSortingFolder (fileFullPath) { + return 'TODO' + } + + /** + * écrit un nouveau nom de fichier formatté + * @param convertedToName + * @param originalFileName + * @returns {*} + */ + static mixDateNameWithFileName (convertedToName, originalFileName) { + // enlever l'ancien timestamp si il existe + // ajouter en début de nom le nouveau timestamp avec un espace et conserver le reste du nom + return originalFileName + } + + static TestMixingName () { + + let fileMixedNewName = mixDateNameWithFileName(convertedToName, originalFileName) + console.log('new name', fileMixedNewName) + + if (fileMixedNewName !== originalFileName) { + console.log('renommage =>', fileMixedNewName) + // renameFile(originalFileName, fileMixedNewName) + } + } + + /** + * obtenir une liste des dossiers uniquement dans le dossier courant + * @param path + * @returns {*} + */ + static getDirectories (path) { + return fs.readdirSync(path).filter(function (file) { + return fs.statSync(path + '/' + file).isDirectory() + } + ) + } + + static convertDateToTimeInFileName (inputDate) { + return inputDate.replace(' ', 'T') + } + + static testthings () { + // let list = getDirectories(pathFolder) // console.log('list', list) - let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg' - let formattedDatePIMBefore = finder.findFormattedDate(originalFileName) - console.log('formattedDatePIMBefore', formattedDatePIMBefore) + let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg' + let formattedDatePIMBefore = finder.findFormattedDate(originalFileName) + console.log('formattedDatePIMBefore', formattedDatePIMBefore) - let creationDateFound = finder.getExifCreationDate(pathFolder + '/' + originalFileName) - let convertedToName = '' - if (creationDateFound) { - convertedToName = convertDateToTimeInFileName(creationDateFound) + let creationDateFound = finder.getExifCreationDate(pathFolder + '/' + originalFileName) + let convertedToName = '' + if (creationDateFound) { + convertedToName = convertDateToTimeInFileName(creationDateFound) + } + console.log('convertedToName', convertedToName) } - console.log('convertedToName', convertedToName) + } +export default notReadyFunctions \ No newline at end of file