|
1 | 1 | import axios from 'axios' |
2 | 2 | import { DataverseInfoRepository } from '../../../src/info/infra/repositories/DataverseInfoRepository' |
3 | | -import { ApiConfig, ReadError } from '../../../src' |
| 3 | +import { ApiConfig, DatasetMetadataExportFormats, ReadError } from '../../../src' |
4 | 4 | import { TestConstants } from '../../testHelpers/TestConstants' |
5 | 5 | import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
6 | 6 |
|
@@ -188,4 +188,56 @@ describe('DataverseInfoRepository', () => { |
188 | 188 | expect(error).toBeInstanceOf(Error) |
189 | 189 | }) |
190 | 190 | }) |
| 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 | + }) |
191 | 243 | }) |
0 commit comments