From 6d699231fcce28484a6c8cb37e6a1d79b1597ebe Mon Sep 17 00:00:00 2001 From: Tykayn Date: Thu, 29 Jun 2023 18:13:46 +0200 Subject: [PATCH] testing config --- rangement/configs.mjs | 3 ++- rangement/finders.mjs | 27 ++++++++++++++++++--------- rangement/index.mjs | 33 +++++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/rangement/configs.mjs b/rangement/configs.mjs index 989e4837..dcac91c3 100644 --- a/rangement/configs.mjs +++ b/rangement/configs.mjs @@ -1,3 +1,4 @@ export const tagSeparator = ' ' -export const tagSectionSeparator = '--' \ No newline at end of file +export const tagSectionSeparator = '--' +export const enableTestsLocally = true \ No newline at end of file diff --git a/rangement/finders.mjs b/rangement/finders.mjs index 46ec0d4a..28714b00 100644 --- a/rangement/finders.mjs +++ b/rangement/finders.mjs @@ -6,8 +6,7 @@ import {tagSectionSeparator} from "./configs.mjs"; /** * finds patterns for file name */ -export default class finders{ - +export default class finders { patternsFiles = { @@ -17,18 +16,28 @@ export default class finders{ 'screenshot': /^Screenshot/i, // Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png } - static findScreenshot (inputString) { + static findScreenshot(inputString) { return inputString.match(/screenshot/i) || inputString.match(/capture d'écran/i) } static findFormattedDate(filepath) { - let found = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig) - console.log('found', found) - return found + let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig) + // console.log('match findFormattedDate', match) + let result = '' + if (match && match[0]) { + result = match[0] + } + return result } - static findFileExtension (inputString) { - let match = inputString.match(/\.\w{3,4}$/i) - return match + + static findFileExtension(inputString) { + let result = inputString.match(/\.\w{3,4}$/i) + // console.log('match findFileExtension', match) + // let result = '' + // if (match && match[0]) { + // result = match[0] + // } + return result } /** diff --git a/rangement/index.mjs b/rangement/index.mjs index a905329a..46f8a30c 100644 --- a/rangement/index.mjs +++ b/rangement/index.mjs @@ -6,10 +6,10 @@ import finders from './finders.mjs' // }) import exifr from 'exifr' import moment from 'moment' -import {tagSectionSeparator, tagSeparator} from "./configs.mjs"; +import {tagSectionSeparator, tagSeparator, enableTestsLocally} from "./configs.mjs"; const pathFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher/tout' -const sortingFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher' +const sortingFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher' // Replace with path to source directory @@ -125,7 +125,7 @@ function renameFile(originalFileName, fileMixedNewName) { // let list = getDirectories(pathFolder) // console.log('list', list) -let originalFileName = '2023-06-23T08.55.05.jpg' +let originalFileName = '2015-04-30T09.09.02 -- scan papier.jpg' let formattedDatePIMBefore = finders.findFormattedDate(originalFileName) console.log('formattedDatePIMBefore', formattedDatePIMBefore) @@ -239,16 +239,33 @@ TestScreenShotIsFoundAndRenamed() */ -function TestDateIsDetectedInFileName() { +function TestTagsAreDetectedInFileName() { + let mockFileName = '2023-06-15T10:11:12 -- screeenshot festival.png' + let expectedResult = ['screeenshot', 'festival'] + let found = findTagSectionInString(mockFileName) + if (found === expectedResult) { + console.info('Succès') + } +} + + +function TestFindFormattedDate() { let mockFileName = 'Capture d\'écran 2023-06-15T10:11:12.png' - let expectedFileNameAfterRename = '2023-06-15T10:11:12 -- screeenshot.png' - let foundDate = finders.findFormattedDate(mockFileName) - console.log('foundDate', foundDate) + let expectedResult = '2023-06-15T10:11:12' + let found = finders.findFormattedDate(mockFileName) + console.log('foundDate', found, expectedResult) + console.log('foundDate', found) + if (found === expectedResult) { + console.info('Succès') + } } // run tests -TestDateIsDetectedInFileName() +if (enableTestsLocally) { + TestTagsAreDetectedInFileName() + TestFindFormattedDate() +} /** ----------------------- parties non réalisées -----------------------