From 75dd1d43a924a3ccf19ea987dab31b4f56c18862 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 25 Nov 2024 17:43:00 +0100 Subject: [PATCH] fix(test): Refactor trash test to improve metadata and deletion validation --- changelog.md | 6 ++++++ test/test.trash.ts | 16 +++++++++++++++- ts/00_commitinfo_data.ts | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 856b3cb..dea5892 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-11-25 - 3.3.5 - fix(test) +Refactor trash test to improve metadata validation + +- Added new checks in trash tests to ensure metadata files are correctly moved to trash. +- Validated the presence and integrity of metadata within trashed files. + ## 2024-11-25 - 3.3.4 - fix(core) Minor refactoring and cleanup of TypeScript source files for improved readability and maintainability. diff --git a/test/test.trash.ts b/test/test.trash.ts index c29a267..2f71370 100644 --- a/test/test.trash.ts +++ b/test/test.trash.ts @@ -52,7 +52,21 @@ tap.test('should put a file into the trash', async () => { console.log(fileMetadata.toString()); expect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({}); await file.delete({ mode: 'trash' }); - jestExpect(await file.getMetaData().then((meta) => meta.metadataFile.getJsonData())).toEqual({ + + const getTrashContents = async () => { + const trash = await myBucket.getTrash(); + const trashDir = await trash.getTrashDir(); + return await trashDir.listFiles(); + } + + const trashedFiles = await getTrashContents(); + expect(trashedFiles.length).toEqual(2); + + const trashedMetaFile = trashedFiles.find(file => file.name.endsWith('.metadata')); + expect(trashedMetaFile).toBeDefined(); + expect(trashedMetaFile).toBeInstanceOf(smartbucket.File); + + jestExpect(await trashedMetaFile!.getJsonData()).toEqual({ custom_recycle: { deletedAt: jestExpect.any(Number), originalPath: "trashtest/trashme.txt", diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 55dd476..798fd97 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartbucket', - version: '3.3.4', + version: '3.3.5', description: 'A TypeScript library providing a cloud-agnostic interface for managing object storage with functionalities like bucket management, file and directory operations, and advanced features such as metadata handling and file locking.' }