Skip to content

Commit de41b3d

Browse files
committed
feat: update to delete draft dataset
1 parent 1b9b826 commit de41b3d

File tree

5 files changed

+8
-49
lines changed

5 files changed

+8
-49
lines changed

docs/useCases.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,9 @@ The `version` parameter should be a string or a [DatasetNotNumberedVersion](../s
838838

839839
You cannot deaccession a dataset more than once. If you call this endpoint twice for the same dataset version, you will get a not found error on the second call, since the dataset you are looking for will no longer be published since it is already deaccessioned.
840840

841-
#### Delete a Dataset
841+
#### Delete a Draft Dataset
842842

843-
Delete a Dataset, given its identifier.
843+
Delete a Draft Dataset, given its identifier.
844844

845845
##### Example call:
846846

src/datasets/domain/useCases/DeleteDataset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class DeleteDataset implements UseCase<void> {
99
}
1010

1111
/**
12-
* Delete a Dataset
12+
* Delete a Draft Dataset
1313
*
1414
* @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
1515
*/

src/datasets/infra/repositories/DatasetsRepository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ export class DatasetsRepository extends ApiRepository implements IDatasetsReposi
279279
}
280280

281281
public async deleteDataset(datasetId: string | number): Promise<void> {
282-
return this.doDelete(this.buildApiEndpoint(this.datasetsResourceName, undefined, datasetId))
282+
return this.doDelete(
283+
this.buildApiEndpoint(this.datasetsResourceName, 'versions/:draft', datasetId)
284+
)
283285
.then(() => undefined)
284286
.catch((error) => {
285287
throw error

test/functional/datasets/DeleteDataset.test.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import {
2-
createDataset,
3-
publishDataset,
4-
VersionUpdateType,
5-
deleteDataset
6-
} from '../../../src/datasets'
1+
import { createDataset, deleteDataset } from '../../../src/datasets'
72
import { ApiConfig, WriteError } from '../../../src'
83
import { TestConstants } from '../../testHelpers/TestConstants'
94
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
10-
import { waitForNoLocks } from '../../testHelpers/datasets/datasetHelper'
115

126
const testDataset = {
137
license: {
@@ -56,24 +50,7 @@ describe('execute', () => {
5650
)
5751
})
5852

59-
test('should delete a dataset when it is published successfully', async () => {
60-
const createdDatasetIdentifiers = await createDataset.execute(testDataset)
61-
62-
const response = await publishDataset.execute(
63-
createdDatasetIdentifiers.persistentId,
64-
VersionUpdateType.MAJOR
65-
)
66-
67-
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
68-
69-
expect(response).toBeUndefined()
70-
71-
const actual = await deleteDataset.execute(createdDatasetIdentifiers.numericId)
72-
73-
expect(actual).toBeUndefined()
74-
})
75-
76-
test('should delete a dataset when it is not published successfully', async () => {
53+
test('should delete a dataset when it is draft successfully', async () => {
7754
const createdDatasetIdentifiers = await createDataset.execute(testDataset)
7855

7956
const actual = await deleteDataset.execute(createdDatasetIdentifiers.numericId)

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,26 +1356,6 @@ describe('DatasetsRepository', () => {
13561356
).rejects.toThrow(expectedError)
13571357
})
13581358

1359-
test('should delete a published dataset', async () => {
1360-
const testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
1361-
1362-
await publishDatasetViaApi(testDatasetIds.numericId)
1363-
1364-
await waitForNoLocks(testDatasetIds.numericId, 10)
1365-
1366-
const actual = await sut.deleteDataset(testDatasetIds.numericId)
1367-
1368-
expect(actual).toBeUndefined()
1369-
1370-
const expectedError = new ReadError(
1371-
`[404] Dataset with ID ${testDatasetIds.numericId} not found.`
1372-
)
1373-
1374-
await expect(
1375-
sut.getDataset(testDatasetIds.numericId, DatasetNotNumberedVersion.LATEST, false, false)
1376-
).rejects.toThrow(expectedError)
1377-
})
1378-
13791359
test('should return error when dataset does not exist', async () => {
13801360
const expectedError = new WriteError(
13811361
`[404] Dataset with ID ${nonExistentTestDatasetId} not found.`

0 commit comments

Comments
 (0)