Skip to content

Commit

Permalink
feat(FilesTotalDownloadSize): implement using js-dataverse
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Oct 4, 2023
1 parent 48e1529 commit 15e1ffb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@faker-js/faker": "7.6.0",
"@iqss/dataverse-client-javascript": "2.0.0-pr88.9d7ced6",
"@iqss/dataverse-client-javascript": "2.0.0-pr92.3fbf381",
"@iqss/dataverse-design-system": "*",
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@tanstack/react-table": "8.9.2",
Expand Down
15 changes: 11 additions & 4 deletions src/files/infrastructure/FileJSDataverseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { FilesCountInfo } from '../domain/models/FilesCountInfo'
import { FilePaginationInfo } from '../domain/models/FilePaginationInfo'
import { FileUserPermissions } from '../domain/models/FileUserPermissions'
import {
FileDownloadSizeMode,
getDatasetFileCounts,
getDatasetFiles,
getDatasetFilesTotalDownloadSize,
getFileDownloadCount,
getFileUserPermissions,
WriteError
Expand All @@ -15,6 +17,8 @@ import { DomainFileMapper } from './mappers/DomainFileMapper'
import { JSFileMapper } from './mappers/JSFileMapper'
import { DatasetVersion } from '../../dataset/domain/models/Dataset'

const includeDeaccessioned = true

export class FileJSDataverseRepository implements FileRepository {
getAllByDatasetPersistentId(
datasetPersistentId: string,
Expand All @@ -28,6 +32,7 @@ export class FileJSDataverseRepository implements FileRepository {
.execute(
datasetPersistentId,
datasetVersion.toString(),
includeDeaccessioned,
jsPagination.limit,
jsPagination.offset,
DomainFileMapper.toJSFileCriteria(criteria)
Expand Down Expand Up @@ -68,7 +73,7 @@ export class FileJSDataverseRepository implements FileRepository {
): Promise<FilesCountInfo> {
// TODO - Take into account the FileCriteria https://github.com/IQSS/dataverse-frontend/issues/172
return getDatasetFileCounts
.execute(datasetPersistentId, datasetVersion.toString())
.execute(datasetPersistentId, datasetVersion.toString(), includeDeaccessioned)
.then((jsFilesCountInfo) => {
return JSFileMapper.toFilesCountInfo(jsFilesCountInfo)
})
Expand All @@ -78,12 +83,14 @@ export class FileJSDataverseRepository implements FileRepository {
}

getFilesTotalDownloadSizeByDatasetPersistentId(
// eslint-disable-next-line unused-imports/no-unused-vars
datasetPersistentId: string,
// eslint-disable-next-line unused-imports/no-unused-vars
datasetVersion: DatasetVersion
): Promise<number> {
return Promise.resolve(0)
return getDatasetFilesTotalDownloadSize
.execute(datasetPersistentId, datasetVersion.toString(), FileDownloadSizeMode.ARCHIVAL)
.catch((error: WriteError) => {
throw new Error(error.message)
})
}

getUserPermissionsById(id: number): Promise<FileUserPermissions> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,37 +569,29 @@ describe('File JSDataverse Repository', () => {
description: 'Some description',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
tabIngest: 'false'
}),
FileHelper.create('txt', {
description: 'Some description',
categories: ['category_1']
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category_1'],
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('txt', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
})
]
const dataset = await DatasetHelper.createWithFiles(files).then((datasetResponse) =>
datasetRepository.getByPersistentId(datasetResponse.persistentId)
)
if (!dataset) throw new Error('Dataset not found')

await TestsUtils.wait(2500) // wait for the files to be ingested

const expectedTotalDownloadSize = await fileRepository
.getAllByDatasetPersistentId(dataset.persistentId, dataset.version)
.then((files) => {
return files.reduce((totalDownloadSize, file) => {
return totalDownloadSize + file.size.toBytes()
}, 0)
})
await fileRepository
.getFilesTotalDownloadSizeByDatasetPersistentId(dataset.persistentId, dataset.version)
.then((totalDownloadSize) => {
expect(totalDownloadSize).to.deep.equal(3037)
expect(totalDownloadSize).to.deep.equal(expectedTotalDownloadSize)
})
})
})
Expand Down

0 comments on commit 15e1ffb

Please sign in to comment.