|
9 | 9 | waitForDatasetsIndexedInSolr, |
10 | 10 | deletePublishedDatasetViaApi, |
11 | 11 | deaccessionDatasetViaApi, |
12 | | - createDatasetLicenseModel |
| 12 | + createDatasetLicenseModel, |
| 13 | + setDatasetStorageSizeViaApi, |
| 14 | + setUseStorageQuotasViaApi |
13 | 15 | } from '../../testHelpers/datasets/datasetHelper' |
14 | 16 | import { ReadError } from '../../../src/core/domain/repositories/ReadError' |
15 | 17 | import { |
@@ -2244,4 +2246,49 @@ describe('DatasetsRepository', () => { |
2244 | 2246 | expect(typeof storageDriver.uploadOutOfBand).toBe('boolean') |
2245 | 2247 | }) |
2246 | 2248 | }) |
| 2249 | + |
| 2250 | + describe('getDatasetUploadLimits', () => { |
| 2251 | + const testCollectionAlias = 'UploadLimitsQuotaDataset' |
| 2252 | + let testDatasetIds: CreatedDatasetIdentifiers |
| 2253 | + const testCollectionStorageQuotaInBytes = 1000 |
| 2254 | + |
| 2255 | + beforeAll(async () => { |
| 2256 | + await createCollectionViaApi(testCollectionAlias) |
| 2257 | + await publishCollectionViaApi(testCollectionAlias) |
| 2258 | + testDatasetIds = await createDataset.execute( |
| 2259 | + TestConstants.TEST_NEW_DATASET_DTO, |
| 2260 | + testCollectionAlias |
| 2261 | + ) |
| 2262 | + await setUseStorageQuotasViaApi(true) |
| 2263 | + await publishDatasetViaApi(testDatasetIds.numericId) |
| 2264 | + await waitForNoLocks(testDatasetIds.numericId, 10) |
| 2265 | + }) |
| 2266 | + |
| 2267 | + afterAll(async () => { |
| 2268 | + await deletePublishedDatasetViaApi(testDatasetIds.persistentId).catch(() => undefined) |
| 2269 | + await deleteCollectionViaApi(testCollectionAlias).catch(() => undefined) |
| 2270 | + }) |
| 2271 | + |
| 2272 | + test('should return empty for dataset (if DatasetStorageSize is not set)', async () => { |
| 2273 | + const uploadLimits = await sut.getDatasetUploadLimits(testDatasetIds.numericId) |
| 2274 | + |
| 2275 | + expect(uploadLimits).toEqual({}) |
| 2276 | + }) |
| 2277 | + |
| 2278 | + test('should return upload limits for dataset (if DatasetStorageSize is set)', async () => { |
| 2279 | + await setDatasetStorageSizeViaApi(testDatasetIds.numericId, testCollectionStorageQuotaInBytes) |
| 2280 | + const uploadLimits = await sut.getDatasetUploadLimits(testDatasetIds.numericId) |
| 2281 | + |
| 2282 | + expect(uploadLimits).toBeDefined() |
| 2283 | + expect(uploadLimits.storageQuotaRemaining).toBeLessThanOrEqual( |
| 2284 | + testCollectionStorageQuotaInBytes |
| 2285 | + ) |
| 2286 | + }) |
| 2287 | + |
| 2288 | + test('should return error when dataset does not exist', async () => { |
| 2289 | + await expect(sut.getDatasetUploadLimits(nonExistentTestDatasetId)).rejects.toBeInstanceOf( |
| 2290 | + ReadError |
| 2291 | + ) |
| 2292 | + }) |
| 2293 | + }) |
2247 | 2294 | }) |
0 commit comments