Add unit tests for data file rotation utility functions
- Implement tests for writing data files with rotation, ensuring backups are created only on changes. - Verify that old backups are rotated correctly and the maximum number of backups is maintained. - Test restoration of backups while preserving the current state as a backup. - Utilize Vitest for testing framework and manage temporary file storage during tests.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import { randomUUID } from 'crypto'
|
||||
import { writeDataFileWithRotation } from './data-file-rotation.js'
|
||||
|
||||
// Use internal server/data directory for Termine CSV to avoid writing to public/
|
||||
const getDataPath = (filename) => {
|
||||
@@ -89,7 +90,7 @@ export async function writeTermine(termine) {
|
||||
csv += `"${escapedDatum}","${escapedUhrzeit}","${escapedTitel}","${escapedBeschreibung}","${escapedKategorie}"\n`
|
||||
}
|
||||
|
||||
await fs.writeFile(TERMINE_FILE, csv, 'utf-8')
|
||||
await writeDataFileWithRotation(TERMINE_FILE, csv, { encoding: 'utf-8' })
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schreiben der Termine:', error)
|
||||
|
||||
Reference in New Issue
Block a user