|
8 | 8 | waitForDatasetsIndexedInSolr, |
9 | 9 | deletePublishedDatasetViaApi, |
10 | 10 | deaccessionDatasetViaApi, |
11 | | - createDatasetLicenseModel |
| 11 | + createDatasetLicenseModel, |
| 12 | + setDatasetStorageSizeViaApi, |
| 13 | + setUseStorageQuotasViaApi |
12 | 14 | } from '../../testHelpers/datasets/datasetHelper' |
13 | 15 | import { ReadError } from '../../../src/core/domain/repositories/ReadError' |
14 | 16 | import { |
@@ -2229,4 +2231,45 @@ describe('DatasetsRepository', () => { |
2229 | 2231 | expect(typeof storageDriver.uploadOutOfBand).toBe('boolean') |
2230 | 2232 | }) |
2231 | 2233 | }) |
| 2234 | + |
| 2235 | + describe('getDatasetUploadLimits', () => { |
| 2236 | + const testCollectionAlias = 'UploadLimitsQuotaDataset' |
| 2237 | + let testDatasetIds: CreatedDatasetIdentifiers |
| 2238 | + const testCollectionStorageQuotaInBytes = 1000 |
| 2239 | + |
| 2240 | + beforeAll(async () => { |
| 2241 | + await createCollectionViaApi(testCollectionAlias) |
| 2242 | + await publishCollectionViaApi(testCollectionAlias) |
| 2243 | + testDatasetIds = await createDataset.execute( |
| 2244 | + TestConstants.TEST_NEW_DATASET_DTO, |
| 2245 | + testCollectionAlias |
| 2246 | + ) |
| 2247 | + await setUseStorageQuotasViaApi(true) |
| 2248 | + await publishDatasetViaApi(testDatasetIds.numericId) |
| 2249 | + await waitForNoLocks(testDatasetIds.numericId, 10) |
| 2250 | + }) |
| 2251 | + |
| 2252 | + afterAll(async () => { |
| 2253 | + await deletePublishedDatasetViaApi(testDatasetIds.persistentId).catch(() => undefined) |
| 2254 | + await deleteCollectionViaApi(testCollectionAlias).catch(() => undefined) |
| 2255 | + }) |
| 2256 | + |
| 2257 | + test('should return upload limits for dataset (quota configured)', async () => { |
| 2258 | + await setDatasetStorageSizeViaApi(testDatasetIds.numericId, testCollectionStorageQuotaInBytes) |
| 2259 | + const uploadLimits = await sut.getDatasetUploadLimits(testDatasetIds.numericId) |
| 2260 | + |
| 2261 | + expect(uploadLimits).toBeDefined() |
| 2262 | + expect(typeof uploadLimits.storageQuotaRemaining).toBe('number') |
| 2263 | + expect(uploadLimits.storageQuotaRemaining).toBeLessThanOrEqual( |
| 2264 | + testCollectionStorageQuotaInBytes |
| 2265 | + ) |
| 2266 | + expect(uploadLimits.storageQuotaRemaining).toBeGreaterThanOrEqual(0) |
| 2267 | + }) |
| 2268 | + |
| 2269 | + test('should return error when dataset does not exist', async () => { |
| 2270 | + await expect(sut.getDatasetUploadLimits(nonExistentTestDatasetId)).rejects.toBeInstanceOf( |
| 2271 | + ReadError |
| 2272 | + ) |
| 2273 | + }) |
| 2274 | + }) |
2232 | 2275 | }) |
0 commit comments