Skip to content

Commit 4235db5

Browse files
committed
test: add unit and integration tests
1 parent 1331a81 commit 4235db5

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

test/integration/info/DataverseInfoRepository.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,12 @@ describe('DataverseInfoRepository', () => {
7373
await deleteApplicationTermsOfUseViaApi()
7474
})
7575
})
76+
77+
describe('getAvailableDatasetMetadataExportFormats', () => {
78+
test('should return available dataset metadata export formats', async () => {
79+
const actual = await sut.getAvailableDatasetMetadataExportFormats()
80+
81+
expect(actual).toBeDefined()
82+
})
83+
})
7684
})

test/unit/info/DataverseInfoRepository.test.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios'
22
import { DataverseInfoRepository } from '../../../src/info/infra/repositories/DataverseInfoRepository'
3-
import { ApiConfig, ReadError } from '../../../src'
3+
import { ApiConfig, DatasetMetadataExportFormats, ReadError } from '../../../src'
44
import { TestConstants } from '../../testHelpers/TestConstants'
55
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
66

@@ -188,4 +188,56 @@ describe('DataverseInfoRepository', () => {
188188
expect(error).toBeInstanceOf(Error)
189189
})
190190
})
191+
192+
describe('getAvailableDatasetMetadataExportFormats', () => {
193+
test('should return available dataset metadata export formats on successful response', async () => {
194+
const formats: DatasetMetadataExportFormats = {
195+
OAI_ORE: {
196+
displayName: 'OAI_ORE',
197+
mediaType: 'application/json',
198+
isHarvestable: false,
199+
isVisibleInUserInterface: true
200+
},
201+
Datacite: {
202+
displayName: 'DataCite',
203+
mediaType: 'application/xml',
204+
isHarvestable: true,
205+
isVisibleInUserInterface: true,
206+
XMLNameSpace: 'http://datacite.org/schema/kernel-4',
207+
XMLSchemaLocation:
208+
'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4.5/metadata.xsd',
209+
XMLSchemaVersion: '4.5'
210+
}
211+
}
212+
213+
const testSuccessfulResponse = {
214+
data: {
215+
status: 'OK',
216+
data: formats
217+
}
218+
}
219+
jest.spyOn(axios, 'get').mockResolvedValue(testSuccessfulResponse)
220+
221+
const actual = await sut.getAvailableDatasetMetadataExportFormats()
222+
223+
expect(axios.get).toHaveBeenCalledWith(
224+
`${TestConstants.TEST_API_URL}/info/exportFormats`,
225+
TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG
226+
)
227+
expect(actual).toEqual(formats)
228+
})
229+
230+
test('should return error result on error response', async () => {
231+
jest.spyOn(axios, 'get').mockRejectedValue(TestConstants.TEST_ERROR_RESPONSE)
232+
233+
let error: ReadError | undefined
234+
await sut.getAvailableDatasetMetadataExportFormats().catch((e) => (error = e))
235+
236+
expect(axios.get).toHaveBeenCalledWith(
237+
`${TestConstants.TEST_API_URL}/info/exportFormats`,
238+
TestConstants.TEST_EXPECTED_UNAUTHENTICATED_REQUEST_CONFIG
239+
)
240+
expect(error).toBeInstanceOf(Error)
241+
})
242+
})
191243
})

0 commit comments

Comments
 (0)