Skip to content

Commit 55c5e3b

Browse files
committed
fix: integration and unit test
1 parent 10702d9 commit 55c5e3b

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

test/integration/files/FilesRepository.test.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,13 @@ describe('FilesRepository', () => {
501501
})
502502

503503
describe('getFile with deaccessioned dataset', () => {
504-
test('should return file if dataset is deaccessioned, and includeDeaccessioned is true', async () => {
505-
const testTextFile1Name = 'test-file-1.txt'
504+
const testTextFile1Name = 'test-file-1.txt'
505+
506+
let deaccessionedFileTestDatasetIds: CreatedDatasetIdentifiers
507+
let deaccessionedTestFileId: number
506508

507-
const deaccessionedFileTestDatasetIds = await createDataset.execute(
509+
beforeAll(async () => {
510+
deaccessionedFileTestDatasetIds = await createDataset.execute(
508511
TestConstants.TEST_NEW_DATASET_DTO
509512
)
510513

@@ -513,9 +516,11 @@ describe('FilesRepository', () => {
513516
throw new Error(`Error while uploading file ${testTextFile1Name}`)
514517
}
515518
)
519+
516520
await publishDatasetViaApi(deaccessionedFileTestDatasetIds.numericId).catch(() => {
517521
throw new Error('Error while publishing test Dataset')
518522
})
523+
519524
await waitForNoLocks(deaccessionedFileTestDatasetIds.numericId, 10).catch(() => {
520525
throw new Error('Error while waiting for no locks')
521526
})
@@ -526,14 +531,37 @@ describe('FilesRepository', () => {
526531
false,
527532
FileOrderCriteria.NAME_AZ
528533
)
529-
const deaccessionedTestFileId = datasetFiles.files[0].id
534+
deaccessionedTestFileId = datasetFiles.files[0].id
535+
536+
await deaccessionDatasetViaApi(deaccessionedFileTestDatasetIds.numericId, '1.0').catch(
537+
() => {
538+
throw new Error('Error while deaccessioning the dataset')
539+
}
540+
)
541+
})
530542

531-
await deaccessionDatasetViaApi(deaccessionedFileTestDatasetIds.numericId, '1.0')
543+
afterAll(async () => {
544+
await deletePublishedDatasetViaApi(deaccessionedFileTestDatasetIds.persistentId).catch(
545+
() => {
546+
throw new Error('Error while deleting the test dataset')
547+
}
548+
)
549+
})
532550

551+
test('should return file if dataset is deaccessioned, and includeDeaccessioned is true', async () => {
533552
const actual = (await sut.getFile(deaccessionedTestFileId, '1.0', false, true)) as FileModel
534553

535554
expect(actual.name).toBe(testTextFile1Name)
536-
deletePublishedDatasetViaApi(deaccessionedFileTestDatasetIds.persistentId)
555+
})
556+
557+
test('should throw error if dataset is deaccessioned, and includeDeaccessioned is false', async () => {
558+
const expectedError = new ReadError(
559+
`[404] "File metadata for file with id ${deaccessionedTestFileId} in dataset version 1.0 not found"`
560+
)
561+
562+
await expect(sut.getFile(deaccessionedTestFileId, '1.0', false, false)).rejects.toThrow(
563+
expectedError
564+
)
537565
})
538566
})
539567

test/unit/files/FilesRepository.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ describe('FilesRepository', () => {
10161016
}
10171017

10181018
const expectedRequestParams = {
1019+
includeDeaccessioned: false,
10191020
returnDatasetVersion: false,
10201021
returnOwners: true
10211022
}

0 commit comments

Comments
 (0)