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:
@@ -2,6 +2,7 @@ import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import { randomUUID } from 'crypto'
|
||||
import { encrypt, decrypt, encryptObject, decryptObject } from './encryption.js'
|
||||
import { writeDataFileWithRotation } from './data-file-rotation.js'
|
||||
|
||||
// Handle both dev and production paths
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
@@ -192,7 +193,7 @@ export async function writeMembers(members) {
|
||||
try {
|
||||
const encryptionKey = getEncryptionKey()
|
||||
const encryptedData = encryptObject(members, encryptionKey)
|
||||
await fs.writeFile(MEMBERS_FILE, encryptedData, 'utf-8')
|
||||
await writeDataFileWithRotation(MEMBERS_FILE, encryptedData, { encoding: 'utf-8' })
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Schreiben der Mitgliederdaten:', error)
|
||||
|
||||
Reference in New Issue
Block a user