-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGetMyDataCollectionItems.test.ts
More file actions
282 lines (267 loc) · 7.09 KB
/
Copy pathGetMyDataCollectionItems.test.ts
File metadata and controls
282 lines (267 loc) · 7.09 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import {
ApiConfig,
createDataset,
CreatedDatasetIdentifiers,
CollectionPreview,
getMyDataCollectionItems
} from '../../../src'
import { TestConstants } from '../../testHelpers/TestConstants'
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
import {
createCollectionViaApi,
deleteCollectionViaApi
} from '../../testHelpers/collections/collectionHelper'
import { uploadFileViaApi } from '../../testHelpers/files/filesHelper'
import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper'
import { CollectionItemType } from '../../../src/collections/domain/models/CollectionItemType'
import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus'
const testRoleIds = [1, 2, 3, 4, 5, 6, 7, 8]
const testCollectionItemTypes = [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET,
CollectionItemType.FILE
]
const testPublishingStatuses = [
PublicationStatus.Published,
PublicationStatus.Draft,
PublicationStatus.Unpublished
]
describe('execute', () => {
const testCollectionAlias = 'collectionsRepositoryGetMyDataCollection'
let testDatasetIds: CreatedDatasetIdentifiers
const testTextFile1Name = 'test-file-2.txt'
beforeAll(async () => {
ApiConfig.init(
TestConstants.TEST_API_URL,
DataverseApiAuthMechanism.API_KEY,
process.env.TEST_API_KEY
)
await createCollectionViaApi(testCollectionAlias)
try {
testDatasetIds = await createDataset.execute(
TestConstants.TEST_NEW_DATASET_DTO,
testCollectionAlias
)
} catch (error) {
throw new Error('Tests beforeAll(): Error while creating test dataset')
}
await uploadFileViaApi(testDatasetIds.numericId, testTextFile1Name).catch(() => {
throw new Error(`Tests beforeAll(): Error while uploading file ${testTextFile1Name}`)
})
})
afterAll(async () => {
try {
await deleteUnpublishedDatasetViaApi(testDatasetIds.numericId)
} catch (error) {
throw new Error('Tests afterAll(): Error while deleting test dataset')
}
try {
await deleteCollectionViaApi(testCollectionAlias)
} catch (error) {
throw new Error('Tests afterAll(): Error while deleting test collection')
}
})
test('should return an empty item subset when repository returns no results', async () => {
const actual = await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
[PublicationStatus.Deaccessioned],
undefined,
undefined,
'no-results-for-get-my-data-collection-items'
)
expect(actual.items).toEqual([])
expect(actual.totalItemCount).toBe(0)
expect(actual.publicationStatusCounts).toEqual([
{
publicationStatus: 'Published',
count: 0
},
{
publicationStatus: 'Unpublished',
count: 0
},
{
publicationStatus: 'Draft',
count: 0
},
{
publicationStatus: 'In Review',
count: 0
},
{
publicationStatus: 'Deaccessioned',
count: 0
}
])
expect(actual.countPerObjectType).toEqual({
collections: 0,
datasets: 0,
files: 0
})
})
test('should return items when valid roles,collection types, and publishingStatuses are provided', async () => {
// Give enough time to Solr for indexing
await new Promise((resolve) => setTimeout(resolve, 5000))
try {
const actual = await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
testPublishingStatuses,
undefined,
undefined,
testCollectionAlias
)
const actualCollectionPreview = actual.items[0] as CollectionPreview
expect(actualCollectionPreview.alias).toBe(testCollectionAlias)
expect(actual.totalItemCount).toBe(1)
expect(actual.publicationStatusCounts).toEqual([
{
publicationStatus: 'Published',
count: 0
},
{
publicationStatus: 'Unpublished',
count: 1
},
{
publicationStatus: 'Draft',
count: 0
},
{
publicationStatus: 'In Review',
count: 0
},
{
publicationStatus: 'Deaccessioned',
count: 0
}
])
expect(actual.countPerObjectType).toEqual({
collections: 1,
datasets: 0,
files: 0
})
} catch (error) {
console.log(error)
throw new Error('Item subset should be retrieved')
}
})
test('should return an empty item subset when no role is specified', async () => {
const actual = await getMyDataCollectionItems.execute(
[],
[],
[],
undefined,
undefined,
undefined
)
expect(actual.items).toEqual([])
expect(actual.totalItemCount).toBe(0)
expect(actual.publicationStatusCounts).toEqual([
{
publicationStatus: 'Published',
count: 0
},
{
publicationStatus: 'Unpublished',
count: 0
},
{
publicationStatus: 'Draft',
count: 0
},
{
publicationStatus: 'In Review',
count: 0
},
{
publicationStatus: 'Deaccessioned',
count: 0
}
])
expect(actual.countPerObjectType).toEqual({
collections: 0,
datasets: 0,
files: 0
})
})
test('should return an empty item subset when no publication status is specified', async () => {
const actual = await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
[],
undefined,
undefined,
undefined
)
expect(actual.items).toEqual([])
expect(actual.totalItemCount).toBe(0)
expect(actual.publicationStatusCounts).toEqual([
{
publicationStatus: 'Published',
count: 0
},
{
publicationStatus: 'Unpublished',
count: 0
},
{
publicationStatus: 'Draft',
count: 0
},
{
publicationStatus: 'In Review',
count: 0
},
{
publicationStatus: 'Deaccessioned',
count: 0
}
])
expect(actual.countPerObjectType).toEqual({
collections: 0,
datasets: 0,
files: 0
})
})
test('should return an empty item subset when no collection type is specified', async () => {
const actual = await getMyDataCollectionItems.execute(
testRoleIds,
[],
testPublishingStatuses,
undefined,
undefined,
undefined
)
expect(actual.items).toEqual([])
expect(actual.totalItemCount).toBe(0)
expect(actual.publicationStatusCounts).toEqual([
{
publicationStatus: 'Published',
count: 0
},
{
publicationStatus: 'Unpublished',
count: 0
},
{
publicationStatus: 'Draft',
count: 0
},
{
publicationStatus: 'In Review',
count: 0
},
{
publicationStatus: 'Deaccessioned',
count: 0
}
])
expect(actual.countPerObjectType).toEqual({
collections: 0,
datasets: 0,
files: 0
})
})
})