Skip to content

Commit 2015691

Browse files
committed
Merge branch 'master' into dataset-update
Conflicts: README.md src/dataverseClient.ts test/dataverseClient.spec.ts
2 parents 2661c4f + 8b224a4 commit 2015691

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ http://demo.dataverse.org/api/datasets/389608/versions/1
6363

6464
`public async updateDataset(datasetId: string, datasetInformation: BasicDatasetInformation): Promise<AxiosResponse> {`
6565

66+
`public async deleteDataset(datasetId: string): Promise<AxiosResponse> {`
67+
6668
## Build project
6769

6870
In order to build the project, we need to run the following command:
@@ -110,4 +112,4 @@ Automated publishing of versions could be automated when merging to master. Belo
110112
5. Publish, `npm publish`
111113

112114
## Contributing
113-
[If you are interested in contributing, please click here](/CONTRIBUTING.md)
115+
[If you are interested in contributing, please click here](/CONTRIBUTING.md)

src/dataverseClient.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ export class DataverseClient {
185185
})
186186
}
187187

188+
public async deleteDataset(datasetId: string): Promise<AxiosResponse> {
189+
const url = `${this.host}/api/datasets/:persistentId/destroy/?persistentId=${datasetId}`
190+
return this.deleteRequest(url)
191+
}
192+
188193
private async getRequest(url: string, options: { params?: object, headers?: DataverseHeaders, responseType?: ResponseType } = { headers: this.getHeaders() }): Promise<AxiosResponse> {
189194
return await axios.get(url, options).catch(error => {
190195
throw new DataverseException(error.response.status, error.response.data ? error.response.data.message : '')
@@ -203,6 +208,12 @@ export class DataverseClient {
203208
})
204209
}
205210

211+
private async deleteRequest(url: string, options: { params?: object, headers?: DataverseHeaders, responseType?: ResponseType } = { headers: this.getHeaders() }): Promise<AxiosResponse> {
212+
return await axios.delete(url, options).catch(error => {
213+
throw new DataverseException(error.response.status, error.response.data ? error.response.data.message : '')
214+
})
215+
}
216+
206217
private getHeaders(): DataverseHeaders {
207218
return {
208219
'X-Dataverse-key': this.apiToken ? this.apiToken : ''
@@ -223,4 +234,4 @@ export class DataverseClient {
223234
fq: options.fq
224235
}
225236
}
226-
}
237+
}

test/dataverseClient.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('DataverseClient', () => {
2929
let axiosPostStub: SinonStub
3030
let axiosPutStub: SinonStub
3131
let requestPostStub: SinonStub
32+
let axiosDeleteStub: SinonStub
3233

3334
let mapBasicDatasetInformationStub: SinonStub
3435
let getErrorMessageStub: SinonStub
@@ -65,6 +66,7 @@ describe('DataverseClient', () => {
6566
axiosPostStub = sandbox.stub(axios, 'post').resolves(mockResponse)
6667
axiosPutStub = sandbox.stub(axios, 'put').resolves(mockResponse)
6768
requestPostStub = sandbox.stub(request, 'post').resolves(mockResponse)
69+
axiosDeleteStub = sandbox.stub(axios, 'delete').resolves(mockResponse)
6870

6971
mapBasicDatasetInformationStub = sandbox.stub(DatasetUtil, 'mapBasicDatasetInformation').returns(mockDatasetInformation)
7072
getErrorMessageStub = sandbox.stub(ResponseUtil, 'getErrorMessage').returns(mockErrorMessage)
@@ -1482,6 +1484,7 @@ describe('DataverseClient', () => {
14821484
expect(error.errorCode).to.be.equal(errorCode)
14831485
})
14841486
})
1487+
14851488
})
14861489

14871490
describe('updateDataset()', () => {
@@ -1511,4 +1514,16 @@ describe('DataverseClient', () => {
15111514
})
15121515
})
15131516
})
1517+
1518+
describe('deleteDataset()', () => {
1519+
it('should call axios with expected url', async () => {
1520+
const datasetId: string = random.number().toString()
1521+
1522+
await client.deleteDataset(datasetId)
1523+
1524+
assert.calledOnce(axiosDeleteStub)
1525+
assert.calledWithExactly(axiosDeleteStub, `${host}/api/datasets/:persistentId/destroy/?persistentId=${datasetId}`, { headers: { 'X-Dataverse-key': apiToken } })
1526+
})
1527+
})
1528+
15141529
})

0 commit comments

Comments
 (0)