From 661d81dadf59ff8d9862a242ce0ae22d82cbade2 Mon Sep 17 00:00:00 2001 From: Cheng Shi Date: Mon, 24 Feb 2025 10:39:15 -0500 Subject: [PATCH] feat: update file update metadata test --- .../integration/files/FilesRepository.test.ts | 110 ++++++------------ 1 file changed, 37 insertions(+), 73 deletions(-) diff --git a/test/integration/files/FilesRepository.test.ts b/test/integration/files/FilesRepository.test.ts index 8f3d86bf..262e1d9f 100644 --- a/test/integration/files/FilesRepository.test.ts +++ b/test/integration/files/FilesRepository.test.ts @@ -534,41 +534,6 @@ describe('FilesRepository', () => { }) }) - describe('updateFileMetadata', () => { - test('should return error when file does not exist', async () => { - const testFileMetadata = { - description: 'My description bbb.', - categories: ['Data'], - restrict: false - } - const errorExpected = new WriteError(`[400] Error attempting get the requested data file.`) - - await expect(sut.updateFileMetadata(nonExistentFiledId, testFileMetadata)).rejects.toThrow( - errorExpected - ) - }) - - test('should update file metadata when file exists', async () => { - const getDatasetFilesResponse = await sut.getDatasetFiles( - testDatasetIds.numericId, - latestDatasetVersionId, - false, - FileOrderCriteria.NAME_AZ - ) - - const fileId = getDatasetFilesResponse.files[0].id - const testFileMetadata = { - description: 'My description bbb.', - categories: ['Data'], - restrict: false - } - - const actual = await sut.updateFileMetadata(fileId, testFileMetadata) - - expect(actual).toBeUndefined() - }) - }) - describe('getFileCitation', () => { test('should return citation when file exists', async () => { const actualFileCitation = await sut.getFileCitation( @@ -682,6 +647,43 @@ describe('FilesRepository', () => { }) }) + describe('updateFileMetadata', () => { + test('should update file metadata when file exists', async () => { + const testFileMetadata = { + description: 'My description test.', + categories: ['Data'], + restrict: false + } + + const actual = await sut.updateFileMetadata(testFileId, testFileMetadata) + + expect(actual).toBeUndefined() + + const fileInfo: FileModel = (await sut.getFile( + testFileId, + DatasetNotNumberedVersion.LATEST, + false + )) as FileModel + + expect(fileInfo.description).toBe(testFileMetadata.description) + expect(fileInfo.categories).toEqual(testFileMetadata.categories) + expect(fileInfo.restricted).toBe(testFileMetadata.restrict) + }) + + test('should return error when file does not exist', async () => { + const testFileMetadata = { + description: 'My description test.', + categories: ['Data'], + restrict: false + } + const errorExpected = new WriteError(`[400] Error attempting get the requested data file.`) + + await expect(sut.updateFileMetadata(nonExistentFiledId, testFileMetadata)).rejects.toThrow( + errorExpected + ) + }) + }) + describe('deleteFile', () => { let deleFileTestDatasetIds: CreatedDatasetIdentifiers const testTextFile1Name = 'test-file-1.txt' @@ -889,42 +891,4 @@ describe('FilesRepository', () => { await expect(setFileToRestricted(nonExistentFiledId)).rejects.toThrow(expectedError) }) }) - - describe('updateFileMetadata', () => { - test('should return error when file does not exist', async () => { - const nonExistentFiledId = 4000 - const testFileMetadata = { - description: 'My description bbb.', - categories: ['Data'], - restrict: false - } - const errorExpected = new WriteError(`[400] Error attempting get the requested data file.`) - - await expect(sut.updateFileMetadata(nonExistentFiledId, testFileMetadata)).rejects.toThrow( - errorExpected - ) - }) - - test('should update file metadata when file exists', async () => { - const getDatasetFilesResponse = await sut.getDatasetFiles( - testDatasetIds.numericId, - latestDatasetVersionId, - false, - FileOrderCriteria.NAME_AZ - ) - - console.log('fileInfo', getDatasetFilesResponse) - - const fileId = getDatasetFilesResponse.files[0].id - const testFileMetadata = { - description: 'My description bbb.', - categories: ['Data'], - restrict: false - } - - const actual = await sut.updateFileMetadata(fileId, testFileMetadata) - - expect(actual).toBeUndefined() - }) - }) })