more tests

This commit is contained in:
Tykayn 2023-07-19 11:11:43 +02:00 committed by tykayn
parent 217d9de761
commit d9cbbb9076
5 changed files with 148 additions and 120 deletions

12
babel.config.cjs Normal file
View File

@ -0,0 +1,12 @@
const presets = [
[
"@babel/preset-env",
{
targets: {
node: 'current'
}
}
]
];
module.exports = { presets };

View File

@ -1,7 +0,0 @@
const presets = [
[
"@babel/preset-env",
]
];
module.exports = { presets };

View File

@ -44,24 +44,20 @@ describe('detection in file name', () => {
describe('modification 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', () => { 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') let modifiedProperties = finder.appendFileName(properties, 'ajouté à la fin du texte libre')
expect( expect(
modifiedProperties.freeText modifiedProperties.freeText
) )
.toBe('mon texte ajouté à la fin du texte libre') .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', () => { test('should replace text in file name', () => {
let fileNameOriginal = 'mon texte -- famille vacances plage.jpg'
let searchString = 'vacances', replaceString = 'machin' let searchString = 'vacances', replaceString = 'machin'
let replacedString = finder.searchAndReplaceInFileName(searchString, replaceString, fileNameOriginal) let replacedString = finder.searchAndReplaceInFileName(searchString, replaceString, fileNameOriginal)
expect( expect(
@ -70,6 +66,25 @@ describe('modification in file name', () => {
.toBe('mon texte -- famille machin plage.jpg') .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', () => { describe('modifications with tags', () => {
@ -84,6 +99,7 @@ describe('modifications with tags', () => {
.toStrictEqual([]) .toStrictEqual([])
}) })
test('should list existing tags in file name', () => { test('should list existing tags in file name', () => {
let fileNameOriginal = 'mon nom -- carte bidule.jpg' let fileNameOriginal = 'mon nom -- carte bidule.jpg'
let otherProperties = finder.destructurateFileName(fileNameOriginal) let otherProperties = finder.destructurateFileName(fileNameOriginal)
@ -91,11 +107,11 @@ describe('modifications with tags', () => {
expect( expect(
otherProperties.tags 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 newTag = 'illustration'
let newName = finder.addTagInFileName(newTag, fileNameOriginal) let newName = finder.addTagInFileName(newTag, fileNameOriginal)

View File

@ -114,7 +114,7 @@ export default class finder {
} }
static cleanSpaces (inputString) { static cleanSpaces (inputString) {
return inputString.trim().replace(/ *g/, ' ') return inputString.trim().replace(/ *g/, ' ').replace(/ /, ' ')
} }
static searchAndReplaceInFileName (searchString, replaceString, fileName) { 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) { static appendFileName (fileProperties, newText) {
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText) fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)

View File

@ -8,119 +8,128 @@ import fs from 'node-fs'
--------------------------------------------------------------------- ---------------------------------------------------------------------
**/ **/
function LogActionRun(){ class notReadyFunctions {
// get file which contains logs
// add an entry
// persist log file
}
function ListActions(idOfAction){ static LogActionRun () {
// retrieve log of actions from file // get file which contains logs
} // add an entry
function RevertAction(idOfAction){ // persist log file
// 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
} }
return false
}
function moveToArchive (targetDirectory, fileFullPath) { static ListActions (idOfAction) {
// find current directory, // retrieve log of actions from file
// rename file to move it
}
function getStatisticsOnArchiveFolder (fileFullPath) {
return {
foldersCount: 'TODO',
filesWithoutSemanticName: 'TODO'
} }
}
/** static RevertAction (idOfAction) {
* list all tags // select action and run all renames in the other way
* @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 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
}
/** static TestDownloadedTelegramPictureRename (fileName) {
* obtenir une liste des dossiers uniquement dans le dossier courant let fileProperties = destructurateFileName(fileName)
* @param path }
* @returns {*}
*/
function getDirectories (path) {
return fs.readdirSync(path).filter(function (file) {
return fs.statSync(path + '/' + file).isDirectory()
})
}
static hasDifferentDateInNameThanExif (fileName) {
let foundDate = finder.findFormattedDate(fileName)
function convertDateToTimeInFileName (inputDate) { if (foundDate && foundDate != getExifCreationDate(fileName)) {
return inputDate.replace(' ', 'T') return true
} }
return false
}
function testthings(){ static moveToArchive (targetDirectory, fileFullPath) {
// let list = getDirectories(pathFolder) // 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) // console.log('list', list)
let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg' let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg'
let formattedDatePIMBefore = finder.findFormattedDate(originalFileName) let formattedDatePIMBefore = finder.findFormattedDate(originalFileName)
console.log('formattedDatePIMBefore', formattedDatePIMBefore) console.log('formattedDatePIMBefore', formattedDatePIMBefore)
let creationDateFound = finder.getExifCreationDate(pathFolder + '/' + originalFileName) let creationDateFound = finder.getExifCreationDate(pathFolder + '/' + originalFileName)
let convertedToName = '' let convertedToName = ''
if (creationDateFound) { if (creationDateFound) {
convertedToName = convertDateToTimeInFileName(creationDateFound) convertedToName = convertDateToTimeInFileName(creationDateFound)
}
console.log('convertedToName', convertedToName)
} }
console.log('convertedToName', convertedToName)
} }
export default notReadyFunctions