@@ -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,6 +27,7 @@ describe('DataverseClient', () => {
2727
2828 let axiosGetStub : SinonStub
2929 let axiosPostStub : SinonStub
30+ let axiosPutStub : SinonStub
3031 let requestPostStub : SinonStub
3132 let axiosDeleteStub : SinonStub
3233
@@ -63,6 +64,7 @@ describe('DataverseClient', () => {
6364
6465 axiosGetStub = sandbox . stub ( axios , 'get' ) . resolves ( mockResponse )
6566 axiosPostStub = sandbox . stub ( axios , 'post' ) . resolves ( mockResponse )
67+ axiosPutStub = sandbox . stub ( axios , 'put' ) . resolves ( mockResponse )
6668 requestPostStub = sandbox . stub ( request , 'post' ) . resolves ( mockResponse )
6769 axiosDeleteStub = sandbox . stub ( axios , 'delete' ) . resolves ( mockResponse )
6870
@@ -1485,6 +1487,34 @@ describe('DataverseClient', () => {
14851487
14861488 } )
14871489
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+
14881518 describe ( 'deleteDataset()' , ( ) => {
14891519 it ( 'should call axios with expected url' , async ( ) => {
14901520 const datasetId : string = random . number ( ) . toString ( )
0 commit comments