@@ -4,7 +4,7 @@ import { expect } from 'chai'
44import axios from 'axios'
55import request from 'request-promise'
66import path from 'path'
7- import { internet , random , system } from 'faker'
7+ import { internet , random , system , name , date } from 'faker'
88import { DataverseException } from '../src/exceptions/dataverseException'
99import { DataverseMetricType } from '../src/@types/dataverseMetricType'
1010import { DatasetSubjects } from '../src/@types/datasetSubjects'
@@ -27,7 +27,9 @@ describe('DataverseClient', () => {
2727
2828 let axiosGetStub : SinonStub
2929 let axiosPostStub : SinonStub
30+ let axiosPutStub : SinonStub
3031 let requestPostStub : SinonStub
32+ let axiosDeleteStub : SinonStub
3133
3234 let mapBasicDatasetInformationStub : SinonStub
3335 let getErrorMessageStub : SinonStub
@@ -62,7 +64,9 @@ describe('DataverseClient', () => {
6264
6365 axiosGetStub = sandbox . stub ( axios , 'get' ) . resolves ( mockResponse )
6466 axiosPostStub = sandbox . stub ( axios , 'post' ) . resolves ( mockResponse )
67+ axiosPutStub = sandbox . stub ( axios , 'put' ) . resolves ( mockResponse )
6568 requestPostStub = sandbox . stub ( request , 'post' ) . resolves ( mockResponse )
69+ axiosDeleteStub = sandbox . stub ( axios , 'delete' ) . resolves ( mockResponse )
6670
6771 mapBasicDatasetInformationStub = sandbox . stub ( DatasetUtil , 'mapBasicDatasetInformation' ) . returns ( mockDatasetInformation )
6872 getErrorMessageStub = sandbox . stub ( ResponseUtil , 'getErrorMessage' ) . returns ( mockErrorMessage )
@@ -1480,5 +1484,46 @@ describe('DataverseClient', () => {
14801484 expect ( error . errorCode ) . to . be . equal ( errorCode )
14811485 } )
14821486 } )
1487+
14831488 } )
1484- } )
1489+
1490+ describe ( 'updateDataset()' , ( ) => {
1491+ it ( 'should call axios with expected url' , async ( ) => {
1492+ const datasetId = random . number ( ) . toString ( )
1493+ const datasetInformation : BasicDatasetInformation = {
1494+ title : random . words ( ) ,
1495+ descriptions : [ { text : random . words ( ) , date : date . recent ( ) . toString ( ) } ] ,
1496+ authors : [
1497+ {
1498+ fullname : name . findName ( )
1499+ }
1500+ ] ,
1501+ contact : [ { email : internet . email ( ) , fullname : name . findName ( ) } ] ,
1502+ subject : [ DatasetSubjects . AGRICULTURAL_SCIENCE ]
1503+ }
1504+
1505+ await client . updateDataset ( datasetId , datasetInformation )
1506+
1507+ assert . calledOnce ( axiosPutStub )
1508+ const payload : any = DatasetUtil . mapBasicDatasetInformation ( datasetInformation )
1509+ assert . calledWithExactly ( axiosPutStub , `${ host } /api/datasets/:persistentId/versions/:draft?persistentId=${ datasetId } ` , JSON . stringify ( payload . datasetVersion ) , {
1510+ headers : {
1511+ 'X-Dataverse-key' : apiToken ,
1512+ 'Content-Type' : 'application/json'
1513+ }
1514+ } )
1515+ } )
1516+ } )
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+
1529+ } )
0 commit comments