testing config

This commit is contained in:
Tykayn 2023-06-29 18:13:46 +02:00 committed by tykayn
parent 64cfe271ca
commit 6d699231fc
3 changed files with 45 additions and 18 deletions

View File

@ -1,3 +1,4 @@
export const tagSeparator = ' '
export const tagSectionSeparator = '--'
export const enableTestsLocally = true

View File

@ -9,7 +9,6 @@ import {tagSectionSeparator} from "./configs.mjs";
export default class finders {
patternsFiles = {
'downloaded_pic': /^\-\w{15}\.jpg/, // FyB8cZnWIAc21rw.jpg
'telegram_pic': /^\-\d{19}_\d{4}/, // -4900281569878475578_1109.jpg
@ -22,13 +21,23 @@ export default class finders{
}
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
let result = inputString.match(/\.\w{3,4}$/i)
// console.log('match findFileExtension', match)
// let result = ''
// if (match && match[0]) {
// result = match[0]
// }
return result
}
/**

View File

@ -6,7 +6,7 @@ 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'
@ -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 -----------------------