-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDataverseInfoRepository.test.ts
More file actions
119 lines (99 loc) · 4.3 KB
/
DataverseInfoRepository.test.ts
File metadata and controls
119 lines (99 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { DataverseInfoRepository } from '../../../src/info/infra/repositories/DataverseInfoRepository'
import {
ApiConfig,
DataverseApiAuthMechanism
} from '../../../src/core/infra/repositories/ApiConfig'
import { TestConstants } from '../../testHelpers/TestConstants'
import {
deleteApplicationTermsOfUseViaApi,
setApplicationTermsOfUseViaApi,
setDatasetPublishPopupCustomTextViaApi,
setMaxEmbargoDurationInMonthsViaApi,
setPublishDatasetDisclaimerTextViaApi
} from '../../testHelpers/info/infoHelper'
import { ReadError } from '../../../src/core/domain/repositories/ReadError'
describe('DataverseInfoRepository', () => {
const sut: DataverseInfoRepository = new DataverseInfoRepository()
beforeAll(async () => {
ApiConfig.init(
TestConstants.TEST_API_URL,
DataverseApiAuthMechanism.API_KEY,
process.env.TEST_API_KEY
)
})
describe('getDataverseVersion', () => {
test('should return Dataverse version', async () => {
const actual = await sut.getDataverseVersion()
expect(typeof actual.number).toBe('string')
})
})
describe('getZipDownloadLimit', () => {
test('should return zip download limit', async () => {
const actual = await sut.getZipDownloadLimit()
expect(typeof actual).toBe('number')
})
})
describe('getMaxEmbargoDurationInMonths', () => {
test('should return error when the setting does not exist', async () => {
const errorExpected: ReadError = new ReadError(
'[404] Setting :MaxEmbargoDurationInMonths not found'
)
await expect(sut.getMaxEmbargoDurationInMonths()).rejects.toThrow(errorExpected)
})
test('should return duration when the setting exists', async () => {
const testMaxEmbargoDurationInMonths = 12
await setMaxEmbargoDurationInMonthsViaApi(testMaxEmbargoDurationInMonths)
const actual = await sut.getMaxEmbargoDurationInMonths()
expect(actual).toBe(testMaxEmbargoDurationInMonths)
})
})
describe('getPublishDatasetDisclaimerText', () => {
test('should return error when the setting does not exist', async () => {
const errorExpected: ReadError = new ReadError(
'[404] Setting :PublishDatasetDisclaimerText not found'
)
await expect(sut.getPublishDatasetDisclaimerText()).rejects.toThrow(errorExpected)
})
test('should return text when the setting exists', async () => {
const testPublishDatasetDisclaimerText = 'please read and accept'
await setPublishDatasetDisclaimerTextViaApi(testPublishDatasetDisclaimerText)
const actual = await sut.getPublishDatasetDisclaimerText()
expect(actual).toBe(testPublishDatasetDisclaimerText)
})
})
describe('getDatasetPublishPopupCustomText', () => {
test('should return error when the setting does not exist', async () => {
const errorExpected: ReadError = new ReadError(
'[404] Setting :DatasetPublishPopupCustomText not found'
)
await expect(sut.getDatasetPublishPopupCustomText()).rejects.toThrow(errorExpected)
})
test('should return text when the setting exists', async () => {
const testDatasetPublishPopupCustomText = 'custom publish popup text'
await setDatasetPublishPopupCustomTextViaApi(testDatasetPublishPopupCustomText)
const actual = await sut.getDatasetPublishPopupCustomText()
expect(actual).toBe(testDatasetPublishPopupCustomText)
})
})
describe('getApplicationTermsOfUse', () => {
test('should return no terms message when terms are not set', async () => {
const defaultNoTermsOfUseMessage =
'There are no Terms of Use for this Dataverse installation.'
const actual = await sut.getApplicationTermsOfUse()
expect(actual).toBe(defaultNoTermsOfUseMessage)
})
test('should return terms when terms are set', async () => {
const testTermsOfUse = 'Be excellent to each other.'
await setApplicationTermsOfUseViaApi(testTermsOfUse)
const actual = await sut.getApplicationTermsOfUse()
expect(actual).toBe(testTermsOfUse)
await deleteApplicationTermsOfUseViaApi()
})
})
describe('getAvailableDatasetMetadataExportFormats', () => {
test('should return available dataset metadata export formats', async () => {
const actual = await sut.getAvailableDatasetMetadataExportFormats()
expect(actual).toBeDefined()
})
})
})