-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcollectionHelper.ts
More file actions
263 lines (247 loc) · 10.2 KB
/
collectionHelper.ts
File metadata and controls
263 lines (247 loc) · 10.2 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import { Collection, CollectionFacet } from '../../../src/collections'
import { DvObjectType } from '../../../src'
import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
import { TestConstants } from '../TestConstants'
import axios from 'axios'
import { CollectionDTO } from '../../../src/collections/domain/dtos/CollectionDTO'
import { NewCollectionRequestPayload } from '../../../src/collections/infra/repositories/CollectionsRepository'
import { CollectionFacetPayload } from '../../../src/collections/infra/repositories/transformers/CollectionFacetPayload'
import { CollectionType } from '../../../src/collections/domain/models/CollectionType'
export const ROOT_COLLECTION_ALIAS = 'root'
const COLLECTION_ID = 11111
const COLLECTION_IS_RELEASED = true
const COLLECTION_ALIAS_STR = 'secondCollection'
const COLLECTION_NAME_STR = 'Laboratory Research'
const COLLECTION_AFFILIATION_STR = 'Laboratory Research Corporation'
const COLLECTION_DESCRIPTION = 'This is an <b>example</b> collection used for testing.'
const DATAVERSE_API_REQUEST_HEADERS = {
headers: { 'Content-Type': 'application/json', 'X-Dataverse-Key': process.env.TEST_API_KEY }
}
export const createCollectionModel = (): Collection => {
const collectionModel: Collection = {
id: COLLECTION_ID,
alias: COLLECTION_ALIAS_STR,
name: COLLECTION_NAME_STR,
isReleased: COLLECTION_IS_RELEASED,
affiliation: COLLECTION_AFFILIATION_STR,
description: COLLECTION_DESCRIPTION,
isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' },
inputLevels: [
{
datasetFieldName: 'test',
required: true,
include: true
}
],
type: CollectionType.UNCATEGORIZED,
contacts: [
{
email: 'dataverse@test.com',
displayOrder: 0
}
],
allowedDatasetTypes: [
{
id: 1,
name: 'review',
displayName: 'Review',
description: 'A review of a dataset compiled by the expert community.'
}
],
isMetadataBlockRoot: true,
isFacetRoot: true,
childCount: 0
}
return collectionModel
}
export const createCollectionPayload = (): CollectionPayload => {
const collectionPayload: CollectionPayload = {
id: COLLECTION_ID,
alias: COLLECTION_ALIAS_STR,
name: COLLECTION_NAME_STR,
isReleased: COLLECTION_IS_RELEASED,
affiliation: COLLECTION_AFFILIATION_STR,
description: COLLECTION_DESCRIPTION,
isPartOf: { type: DvObjectType.DATAVERSE, identifier: 'root', displayName: 'Root' },
inputLevels: [
{
datasetFieldTypeName: 'test',
required: true,
include: true
}
],
dataverseType: CollectionType.UNCATEGORIZED,
dataverseContacts: [
{
contactEmail: 'dataverse@test.com',
displayOrder: 0
}
],
allowedDatasetTypes: [
{
id: 1,
name: 'review',
displayName: 'Review',
description: 'A review of a dataset compiled by the expert community.'
}
],
isMetadataBlockRoot: true,
isFacetRoot: true,
childCount: 0
}
return collectionPayload
}
export async function createCollectionViaApi(
collectionAlias: string,
parentCollectionAlias: string | undefined = undefined
): Promise<CollectionPayload> {
try {
if (parentCollectionAlias == undefined) {
parentCollectionAlias = ':root'
}
return await axios
.post(
`${TestConstants.TEST_API_URL}/dataverses/${parentCollectionAlias}`,
JSON.stringify({
alias: collectionAlias,
name: 'Scientific Research',
dataverseContacts: [
{
contactEmail: 'pi@example.edu'
},
{
contactEmail: 'student@example.edu'
}
],
affiliation: 'Scientific Research University',
description: 'We do all the science.',
dataverseType: 'LABORATORY'
}),
DATAVERSE_API_REQUEST_HEADERS
)
.then((response) => response.data.data)
} catch (error) {
throw new Error(`Error while creating test collection ${collectionAlias}`)
}
}
export async function deleteCollectionViaApi(collectionAlias: string): Promise<void> {
try {
return await axios.delete(
`${TestConstants.TEST_API_URL}/dataverses/${collectionAlias}`,
DATAVERSE_API_REQUEST_HEADERS
)
} catch (error) {
console.log(error)
throw new Error(`Error while deleting test collection ${collectionAlias}`)
}
}
export async function setStorageDriverViaApi(
collectionAlias: string,
driverLabel: string
): Promise<void> {
try {
return await axios.put(
`${TestConstants.TEST_API_URL}/admin/dataverse/${collectionAlias}/storageDriver`,
driverLabel,
{
headers: { 'Content-Type': 'text/plain', 'X-Dataverse-Key': process.env.TEST_API_KEY }
}
)
} catch (error) {
console.log(error)
throw new Error(`Error while setting storage driver for collection ${collectionAlias}`)
}
}
export async function publishCollectionViaApi(collectionAlias: string): Promise<void> {
try {
return await axios.post(
`${TestConstants.TEST_API_URL}/dataverses/${collectionAlias}/actions/:publish`,
{},
DATAVERSE_API_REQUEST_HEADERS
)
} catch (error) {
throw new Error(`Error while publishing test collection ${collectionAlias}`)
}
}
export const createCollectionDTO = (alias = 'test-collection'): CollectionDTO => {
return {
alias: alias,
name: 'Test Collection',
contacts: ['dataverse@test.com'],
type: CollectionType.DEPARTMENT,
metadataBlockNames: ['citation', 'geospatial'],
facetIds: ['authorName', 'authorAffiliation'],
description: 'test description',
affiliation: 'test affiliation',
inputLevels: [
{
datasetFieldName: 'geographicCoverage',
required: true,
include: true
}
],
inheritFacetsFromParent: false,
inheritMetadataBlocksFromParent: false
}
}
export const createNewCollectionRequestPayload = (): NewCollectionRequestPayload => {
return {
alias: 'test-collection',
name: 'Test Collection',
dataverseContacts: [
{
contactEmail: 'dataverse@test.com'
}
],
dataverseType: 'DEPARTMENT',
description: 'test description',
affiliation: 'test affiliation',
metadataBlocks: {
metadataBlockNames: ['citation', 'geospatial'],
inputLevels: [
{
datasetFieldTypeName: 'geographicCoverage',
include: true,
required: true
}
],
facetIds: ['authorName', 'authorAffiliation'],
inheritMetadataBlocksFromParent: false,
inheritFacetsFromParent: false
}
}
}
export const createCollectionFacetModel = (): CollectionFacet => {
return {
id: 1,
name: 'testName',
displayName: 'testDisplayName'
}
}
export const createCollectionFacetRequestPayload = (): CollectionFacetPayload => {
return {
id: '1',
name: 'testName',
displayName: 'testDisplayName'
}
}
export const CONTENT_FIELD_WITH_ALL_TAGS =
'<h1 class="rte-heading">A title</h1><p class="rte-paragraph">Esto es una oracion que contiene texto en <strong class="rte-bold">negrita</strong>, <em class="rte-italic">italica</em>, <u class="rte-underline">subrayada</u>, <s class="rte-strike">tachado</s>, <code class="rte-code">de tipo code</code>, este es <a target="_blank" rel="noopener noreferrer nofollow" class="rte-link" href="https://youtube.com">un link que apunta a youtube</a>.</p><p class="rte-paragraph">Una lista desordenada:</p><ul class="rte-bullet-list"><li><p class="rte-paragraph">Item</p></li><li><p class="rte-paragraph">Item</p></li></ul><p class="rte-paragraph">Una lista ordenada:</p><ol class="rte-ordered-list"><li><p class="rte-paragraph">Item 1</p></li><li><p class="rte-paragraph">Item 2</p></li></ol><blockquote class="rte-blockquote"><p class="rte-paragraph">Este es un blockquote.</p></blockquote><p class="rte-paragraph">Esto que viene es un bloque de codigo.</p><pre class="rte-code-block"><code> <Controller name={`featuredItems.${itemIndex}.content`} control={control} rules={rules} render={({ field: { onChange, ref, value }, fieldState: { invalid, error } }) => { console.log({ value }) return ( <Col> <RichTextEditor initialValue={value as string} editorContentAriaLabelledBy={`featuredItems.${itemIndex}.content`} onChange={onChange} invalid={invalid} ariaRequired ref={ref} /> {invalid && <div className={styles["error-msg"]}>{error?.message}</div>} </Col> ) }} /></code></pre>'
export const EXPECTED_CONTENT_FIELD_WITH_ALL_TAGS =
'<h1 class="rte-heading">A title</h1>\n' +
'<p class="rte-paragraph">Esto es una oracion que contiene texto en <strong class="rte-bold">negrita</strong>, <em class="rte-italic">italica</em>, <u class="rte-underline">subrayada</u>, <s class="rte-strike">tachado</s>, <code class="rte-code">de tipo code</code>, este es <a target="_blank" rel="noopener noreferrer nofollow" class="rte-link" href="https://youtube.com">un link que apunta a youtube</a>.</p>\n' +
'<p class="rte-paragraph">Una lista desordenada:</p>\n' +
'<ul class="rte-bullet-list">\n' +
' <li><p class="rte-paragraph">Item</p></li>\n' +
' <li><p class="rte-paragraph">Item</p></li>\n' +
'</ul>\n' +
'<p class="rte-paragraph">Una lista ordenada:</p>\n' +
'<ol class="rte-ordered-list">\n' +
' <li><p class="rte-paragraph">Item 1</p></li>\n' +
' <li><p class="rte-paragraph">Item 2</p></li>\n' +
'</ol>\n' +
'<blockquote class="rte-blockquote">\n' +
' <p class="rte-paragraph">Este es un blockquote.</p>\n' +
'</blockquote>\n' +
'<p class="rte-paragraph">Esto que viene es un bloque de codigo.</p>\n' +
'<pre class="rte-code-block"><code> <Controller name={`featuredItems.${itemIndex}.content`} control={control} rules={rules} render={({ field: { onChange, ref, value }, fieldState: { invalid, error } }) => { console.log({ value }) return ( <Col> <RichTextEditor initialValue={value as string} editorContentAriaLabelledBy={`featuredItems.${itemIndex}.content`} onChange={onChange} invalid={invalid} ariaRequired ref={ref} /> {invalid && <div className={styles["error-msg"]}>{error?.message}</div>} </Col> ) }} /></code></pre>'