-
Notifications
You must be signed in to change notification settings - Fork 10
Dataset Upload Limits Use Case #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jp-tosca
merged 5 commits into
develop
from
409-create-use-case-for-getting-storage-quota-on-dataset
Mar 19, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f48695f
feat: use case of dataset uploadlimit
ChengShi-1 468e3f4
feat: add more tests
ChengShi-1 6d795bb
chore: copilot review
ChengShi-1 dfc608d
Merge remote-tracking branch 'origin/develop' into 409-create-use-cas…
jp-tosca af1ab54
fix: update package dependencies for dataverse-client-javascript
jp-tosca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export interface DatasetUploadLimits { | ||
| numberOfFilesRemaining?: number | ||
| storageQuotaRemaining?: number | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
| import { IDatasetsRepository } from '../repositories/IDatasetsRepository' | ||
| import { DatasetUploadLimits } from '../models/DatasetUploadLimits' | ||
|
|
||
| export class GetDatasetUploadLimits implements UseCase<DatasetUploadLimits> { | ||
| private datasetsRepository: IDatasetsRepository | ||
|
|
||
| constructor(datasetsRepository: IDatasetsRepository) { | ||
| this.datasetsRepository = datasetsRepository | ||
| } | ||
|
|
||
| /** | ||
| * Returns the remaining dataset storage and/or file upload quotas (if present). | ||
| * | ||
| * @param {number | string} datasetId - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers). | ||
| * @returns {Promise<DatasetUploadLimits>} | ||
| */ | ||
| async execute(datasetId: number | string): Promise<DatasetUploadLimits> { | ||
| return this.datasetsRepository.getDatasetUploadLimits(datasetId) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,9 @@ import { | |||||
| waitForDatasetsIndexedInSolr, | ||||||
| deletePublishedDatasetViaApi, | ||||||
| deaccessionDatasetViaApi, | ||||||
| createDatasetLicenseModel | ||||||
| createDatasetLicenseModel, | ||||||
| setDatasetStorageSizeViaApi, | ||||||
| setUseStorageQuotasViaApi | ||||||
| } from '../../testHelpers/datasets/datasetHelper' | ||||||
| import { ReadError } from '../../../src/core/domain/repositories/ReadError' | ||||||
| import { | ||||||
|
|
@@ -2229,4 +2231,49 @@ describe('DatasetsRepository', () => { | |||||
| expect(typeof storageDriver.uploadOutOfBand).toBe('boolean') | ||||||
| }) | ||||||
| }) | ||||||
|
|
||||||
| describe('getDatasetUploadLimits', () => { | ||||||
| const testCollectionAlias = 'UploadLimitsQuotaDataset' | ||||||
| let testDatasetIds: CreatedDatasetIdentifiers | ||||||
| const testCollectionStorageQuotaInBytes = 1000 | ||||||
|
|
||||||
| beforeAll(async () => { | ||||||
| await createCollectionViaApi(testCollectionAlias) | ||||||
| await publishCollectionViaApi(testCollectionAlias) | ||||||
| testDatasetIds = await createDataset.execute( | ||||||
| TestConstants.TEST_NEW_DATASET_DTO, | ||||||
| testCollectionAlias | ||||||
| ) | ||||||
| await setUseStorageQuotasViaApi(true) | ||||||
| await publishDatasetViaApi(testDatasetIds.numericId) | ||||||
| await waitForNoLocks(testDatasetIds.numericId, 10) | ||||||
| }) | ||||||
|
|
||||||
| afterAll(async () => { | ||||||
| await deletePublishedDatasetViaApi(testDatasetIds.persistentId).catch(() => undefined) | ||||||
| await deleteCollectionViaApi(testCollectionAlias).catch(() => undefined) | ||||||
| }) | ||||||
|
|
||||||
| test('should return empty for dataset (if DatasetStorageSize is not set)', async () => { | ||||||
| const uploadLimits = await sut.getDatasetUploadLimits(testDatasetIds.numericId) | ||||||
|
|
||||||
| expect(uploadLimits).toEqual({}) | ||||||
| }) | ||||||
|
|
||||||
| test('should return upload limits for dataset (if DatasetStorageSize is set)', async () => { | ||||||
|
||||||
| test('should return upload limits for dataset (if DatasetStorageSize is set)', async () => { | |
| test('should return upload limits for dataset (if DatasetStorageSize is set)', async () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { GetDatasetUploadLimits } from '../../../src/datasets/domain/useCases/GetDatasetUploadLimits' | ||
| import { IDatasetsRepository } from '../../../src/datasets/domain/repositories/IDatasetsRepository' | ||
| import { DatasetUploadLimits } from '../../../src/datasets/domain/models/DatasetUploadLimits' | ||
| import { ReadError } from '../../../src/core/domain/repositories/ReadError' | ||
|
|
||
| describe('GetDatasetUploadLimits (unit)', () => { | ||
| const testUploadLimits: DatasetUploadLimits = { | ||
| numberOfFilesRemaining: 25, | ||
| storageQuotaRemaining: 21474836480 | ||
| } | ||
|
|
||
| test('should return upload limits on repository success', async () => { | ||
| const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository | ||
| datasetsRepositoryStub.getDatasetUploadLimits = jest.fn().mockResolvedValue(testUploadLimits) | ||
| const sut = new GetDatasetUploadLimits(datasetsRepositoryStub) | ||
|
|
||
| const actual = await sut.execute(1) | ||
|
|
||
| expect(actual).toEqual(testUploadLimits) | ||
| expect(actual.numberOfFilesRemaining).toBe(25) | ||
| expect(actual.storageQuotaRemaining).toBe(21474836480) | ||
| }) | ||
|
|
||
| test('should return upload limits when using persistent id', async () => { | ||
| const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository | ||
| datasetsRepositoryStub.getDatasetUploadLimits = jest.fn().mockResolvedValue(testUploadLimits) | ||
| const sut = new GetDatasetUploadLimits(datasetsRepositoryStub) | ||
|
|
||
| const actual = await sut.execute('doi:10.77777/FK2/AAAAAA') | ||
|
|
||
| expect(actual).toEqual(testUploadLimits) | ||
| }) | ||
|
|
||
| test('should return error result on repository error', async () => { | ||
| const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository | ||
| datasetsRepositoryStub.getDatasetUploadLimits = jest | ||
| .fn() | ||
| .mockRejectedValue(new ReadError('[404] Dataset not found')) | ||
| const sut = new GetDatasetUploadLimits(datasetsRepositoryStub) | ||
|
|
||
| await expect(sut.execute(1)).rejects.toThrow(ReadError) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a duplicate entry for updateDatasetLicense in the CHANGELOG. Lines 11 and 13 contain nearly identical entries. Please remove one of them.