@@ -115,8 +115,9 @@ describe('DatasetsRepository', () => {
115115 TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_SESSION_COOKIE . withCredentials ,
116116 headers : TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_SESSION_COOKIE . headers
117117 }
118- describe ( 'with custom terms of use' , ( ) => {
119- test ( 'should return Dataset with customTerms when license is undefined' , async ( ) => {
118+
119+ describe ( 'by numeric id' , ( ) => {
120+ test ( 'should return Dataset when providing id, version id, and response is successful' , async ( ) => {
120121 jest . spyOn ( axios , 'get' ) . mockResolvedValue ( testDatasetVersionSuccessfulResponse )
121122 const expectedApiEndpoint = `${ TestConstants . TEST_API_URL } /datasets/${ testDatasetModel . id } /versions/${ testVersionId } `
122123
@@ -220,24 +221,7 @@ describe('DatasetsRepository', () => {
220221 )
221222 expect ( actual ) . toStrictEqual ( createDatasetModel ( undefined , true ) )
222223 } )
223-
224- test ( 'should return error on repository read error' , async ( ) => {
225- jest . spyOn ( axios , 'get' ) . mockRejectedValue ( TestConstants . TEST_ERROR_RESPONSE )
226-
227- let error = undefined as unknown as ReadError
228- await sut
229- . getDataset ( testDatasetModel . id , testVersionId , testIncludeDeaccessioned , false )
230- . catch ( ( e ) => ( error = e ) )
231-
232- expect ( axios . get ) . toHaveBeenCalledWith (
233- `${ TestConstants . TEST_API_URL } /datasets/${ testDatasetModel . id } /versions/${ testVersionId } ` ,
234- expectedRequestConfigApiKey
235- )
236- expect ( error ) . toBeInstanceOf ( Error )
237- } )
238- } )
239- describe ( 'by numeric id' , ( ) => {
240- test ( 'should return Dataset when providing id, version id, and response is successful' , async ( ) => {
224+ test ( 'should return Dataset with customTerms when license is undefined' , async ( ) => {
241225 jest . spyOn ( axios , 'get' ) . mockResolvedValue ( testDatasetVersionSuccessfulResponse )
242226 const expectedApiEndpoint = `${ TestConstants . TEST_API_URL } /datasets/${ testDatasetModel . id } /versions/${ testVersionId } `
243227
@@ -266,80 +250,34 @@ describe('DatasetsRepository', () => {
266250 )
267251 expect ( actual ) . toStrictEqual ( testDatasetModel )
268252 } )
253+ test ( 'should return Dataset without customTerms when license is defined' , async ( ) => {
254+ jest . spyOn ( axios , 'get' ) . mockResolvedValue ( testDatasetVersionSuccessfulResponse )
255+ const expectedApiEndpoint = `${ TestConstants . TEST_API_URL } /datasets/${ testDatasetModel . id } /versions/${ testVersionId } `
269256
270- test ( 'should return Dataset when providing id, version id, and response with license is successful' , async ( ) => {
271- const testDatasetLicense = createDatasetLicenseModel ( )
272- const testDatasetVersionWithLicenseSuccessfulResponse = {
273- data : {
274- status : 'OK' ,
275- data : createDatasetVersionPayload ( testDatasetLicense )
276- }
277- }
278- jest . spyOn ( axios , 'get' ) . mockResolvedValue ( testDatasetVersionWithLicenseSuccessfulResponse )
279-
280- const actual = await sut . getDataset (
281- testDatasetModel . id ,
282- testVersionId ,
283- testIncludeDeaccessioned ,
284- false
285- )
286-
287- expect ( axios . get ) . toHaveBeenCalledWith (
288- `${ TestConstants . TEST_API_URL } /datasets/${ testDatasetModel . id } /versions/${ testVersionId } ` ,
289- expectedRequestConfigApiKey
290- )
291- expect ( actual ) . toStrictEqual ( createDatasetModel ( testDatasetLicense ) )
292- } )
293-
294- test ( 'should return Dataset when providing id, version id, and response with license without icon URI is successful' , async ( ) => {
295- const testDatasetLicenseWithoutIconUri = createDatasetLicenseModel ( false )
296- const testDatasetVersionWithLicenseSuccessfulResponse = {
297- data : {
298- status : 'OK' ,
299- data : createDatasetVersionPayload ( testDatasetLicenseWithoutIconUri )
300- }
301- }
302- jest . spyOn ( axios , 'get' ) . mockResolvedValue ( testDatasetVersionWithLicenseSuccessfulResponse )
303-
304- const actual = await sut . getDataset (
257+ // API Key auth
258+ let actual = await sut . getDataset (
305259 testDatasetModel . id ,
306260 testVersionId ,
307261 testIncludeDeaccessioned ,
308262 false
309263 )
310264
311- expect ( axios . get ) . toHaveBeenCalledWith (
312- `${ TestConstants . TEST_API_URL } /datasets/${ testDatasetModel . id } /versions/${ testVersionId } ` ,
313- expectedRequestConfigApiKey
314- )
315- expect ( actual ) . toStrictEqual ( createDatasetModel ( testDatasetLicenseWithoutIconUri ) )
316- } )
317-
318- test ( 'should return dataset with alternative persistent id, publication date and citation date when they are present in the response' , async ( ) => {
319- const testDatasetVersionWithAlternativePersistentIdAndDatesSuccessfulResponse = {
320- data : {
321- status : 'OK' ,
322- data : createDatasetVersionPayload ( undefined , true )
323- }
324- }
325- jest
326- . spyOn ( axios , 'get' )
327- . mockResolvedValue (
328- testDatasetVersionWithAlternativePersistentIdAndDatesSuccessfulResponse
329- )
265+ expect ( axios . get ) . toHaveBeenCalledWith ( expectedApiEndpoint , expectedRequestConfigApiKey )
266+ expect ( actual ) . toStrictEqual ( testDatasetModel )
330267
331- const actual = await sut . getDataset (
268+ // Session cookie auth
269+ ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . SESSION_COOKIE )
270+ actual = await sut . getDataset (
332271 testDatasetModel . id ,
333272 testVersionId ,
334273 testIncludeDeaccessioned ,
335274 false
336275 )
337-
338276 expect ( axios . get ) . toHaveBeenCalledWith (
339- ` ${ TestConstants . TEST_API_URL } /datasets/ ${ testDatasetModel . id } /versions/ ${ testVersionId } ` ,
340- expectedRequestConfigApiKey
277+ expectedApiEndpoint ,
278+ expectedRequestConfigSessionCookie
341279 )
342- expect ( actual ) . toStrictEqual ( createDatasetModel ( undefined , true ) )
280+ expect ( actual ) . toStrictEqual ( testDatasetModel )
343281 } )
344282
345283 test ( 'should return error on repository read error' , async ( ) => {
0 commit comments