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 tagSectionSeparator = '--'
export const enableTestsLocally = true

View File

@ -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
}
/**

View File

@ -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 -----------------------