|
3 | 3 | createDataset, |
4 | 4 | CreatedDatasetIdentifiers, |
5 | 5 | CollectionPreview, |
6 | | - getMyDataCollectionItems |
| 6 | + getMyDataCollectionItems, |
| 7 | + ReadError |
7 | 8 | } from '../../../src' |
8 | 9 | import { TestConstants } from '../../testHelpers/TestConstants' |
9 | 10 | import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
@@ -65,218 +66,136 @@ describe('execute', () => { |
65 | 66 | throw new Error('Tests afterAll(): Error while deleting test collection') |
66 | 67 | } |
67 | 68 | }) |
68 | | - test('should return an empty item subset when repository returns no results', async () => { |
69 | | - const actual = await getMyDataCollectionItems.execute( |
70 | | - testRoleIds, |
71 | | - testCollectionItemTypes, |
72 | | - [PublicationStatus.Deaccessioned], |
73 | | - undefined, |
74 | | - undefined, |
75 | | - 'no-results-for-get-my-data-collection-items' |
76 | | - ) |
77 | | - |
78 | | - expect(actual.items).toEqual([]) |
79 | | - expect(actual.totalItemCount).toBe(0) |
80 | | - expect(actual.publicationStatusCounts).toEqual([ |
81 | | - { |
82 | | - publicationStatus: 'Published', |
83 | | - count: 0 |
84 | | - }, |
85 | | - { |
86 | | - publicationStatus: 'Unpublished', |
87 | | - count: 0 |
88 | | - }, |
89 | | - { |
90 | | - publicationStatus: 'Draft', |
91 | | - count: 0 |
92 | | - }, |
93 | | - { |
94 | | - publicationStatus: 'In Review', |
95 | | - count: 0 |
96 | | - }, |
97 | | - { |
98 | | - publicationStatus: 'Deaccessioned', |
99 | | - count: 0 |
100 | | - } |
101 | | - ]) |
102 | | - expect(actual.countPerObjectType).toEqual({ |
103 | | - collections: 0, |
104 | | - datasets: 0, |
105 | | - files: 0 |
106 | | - }) |
107 | | - }) |
108 | | - |
109 | | - test('should return items when valid roles,collection types, and publishingStatuses are provided', async () => { |
110 | | - // Give enough time to Solr for indexing |
111 | | - await new Promise((resolve) => setTimeout(resolve, 5000)) |
112 | | - |
| 69 | + test('should return error message when repository returns empty item subset', async () => { |
| 70 | + expect.assertions(2) |
| 71 | + let readError: ReadError | undefined = undefined |
113 | 72 | try { |
114 | | - const actual = await getMyDataCollectionItems.execute( |
| 73 | + await getMyDataCollectionItems.execute( |
115 | 74 | testRoleIds, |
116 | 75 | testCollectionItemTypes, |
117 | | - testPublishingStatuses, |
| 76 | + [PublicationStatus.Deaccessioned], |
118 | 77 | undefined, |
119 | 78 | undefined, |
120 | | - testCollectionAlias |
| 79 | + undefined |
121 | 80 | ) |
122 | | - |
123 | | - const actualCollectionPreview = actual.items[0] as CollectionPreview |
124 | | - expect(actualCollectionPreview.alias).toBe(testCollectionAlias) |
125 | | - |
126 | | - expect(actual.totalItemCount).toBe(1) |
127 | | - expect(actual.publicationStatusCounts).toEqual([ |
128 | | - { |
129 | | - publicationStatus: 'Published', |
130 | | - count: 0 |
131 | | - }, |
132 | | - { |
133 | | - publicationStatus: 'Unpublished', |
134 | | - count: 1 |
135 | | - }, |
136 | | - { |
137 | | - publicationStatus: 'Draft', |
138 | | - count: 0 |
139 | | - }, |
140 | | - { |
141 | | - publicationStatus: 'In Review', |
142 | | - count: 0 |
143 | | - }, |
144 | | - { |
145 | | - publicationStatus: 'Deaccessioned', |
146 | | - count: 0 |
147 | | - } |
148 | | - ]) |
149 | | - expect(actual.countPerObjectType).toEqual({ |
150 | | - collections: 1, |
151 | | - datasets: 0, |
152 | | - files: 0 |
153 | | - }) |
| 81 | + throw new Error('Use case should throw an error') |
154 | 82 | } catch (error) { |
155 | | - console.log(error) |
156 | | - throw new Error('Item subset should be retrieved') |
| 83 | + readError = error as ReadError |
| 84 | + } finally { |
| 85 | + expect(readError).toBeInstanceOf(ReadError) |
| 86 | + expect(readError?.message).toEqual( |
| 87 | + 'There was an error when reading the resource. Reason was: Sorry, no results were found.' |
| 88 | + ) |
157 | 89 | } |
158 | | - }) |
| 90 | + }), |
| 91 | + test('should return items when valid roles,collection types, and publishingStatuses are provided', async () => { |
| 92 | + // Give enough time to Solr for indexing |
| 93 | + await new Promise((resolve) => setTimeout(resolve, 5000)) |
159 | 94 |
|
160 | | - test('should return an empty item subset when no role is specified', async () => { |
161 | | - const actual = await getMyDataCollectionItems.execute( |
162 | | - [], |
163 | | - [], |
164 | | - [], |
165 | | - undefined, |
166 | | - undefined, |
167 | | - undefined |
168 | | - ) |
169 | | - |
170 | | - expect(actual.items).toEqual([]) |
171 | | - expect(actual.totalItemCount).toBe(0) |
172 | | - expect(actual.publicationStatusCounts).toEqual([ |
173 | | - { |
174 | | - publicationStatus: 'Published', |
175 | | - count: 0 |
176 | | - }, |
177 | | - { |
178 | | - publicationStatus: 'Unpublished', |
179 | | - count: 0 |
180 | | - }, |
181 | | - { |
182 | | - publicationStatus: 'Draft', |
183 | | - count: 0 |
184 | | - }, |
185 | | - { |
186 | | - publicationStatus: 'In Review', |
187 | | - count: 0 |
188 | | - }, |
189 | | - { |
190 | | - publicationStatus: 'Deaccessioned', |
191 | | - count: 0 |
192 | | - } |
193 | | - ]) |
194 | | - expect(actual.countPerObjectType).toEqual({ |
195 | | - collections: 0, |
196 | | - datasets: 0, |
197 | | - files: 0 |
198 | | - }) |
199 | | - }) |
| 95 | + try { |
| 96 | + const actual = await getMyDataCollectionItems.execute( |
| 97 | + testRoleIds, |
| 98 | + testCollectionItemTypes, |
| 99 | + testPublishingStatuses, |
| 100 | + undefined, |
| 101 | + undefined, |
| 102 | + testCollectionAlias |
| 103 | + ) |
200 | 104 |
|
201 | | - test('should return an empty item subset when no publication status is specified', async () => { |
202 | | - const actual = await getMyDataCollectionItems.execute( |
203 | | - testRoleIds, |
204 | | - testCollectionItemTypes, |
205 | | - [], |
206 | | - undefined, |
207 | | - undefined, |
208 | | - undefined |
209 | | - ) |
| 105 | + const actualCollectionPreview = actual.items[0] as CollectionPreview |
| 106 | + expect(actualCollectionPreview.alias).toBe(testCollectionAlias) |
210 | 107 |
|
211 | | - expect(actual.items).toEqual([]) |
212 | | - expect(actual.totalItemCount).toBe(0) |
213 | | - expect(actual.publicationStatusCounts).toEqual([ |
214 | | - { |
215 | | - publicationStatus: 'Published', |
216 | | - count: 0 |
217 | | - }, |
218 | | - { |
219 | | - publicationStatus: 'Unpublished', |
220 | | - count: 0 |
221 | | - }, |
222 | | - { |
223 | | - publicationStatus: 'Draft', |
224 | | - count: 0 |
225 | | - }, |
226 | | - { |
227 | | - publicationStatus: 'In Review', |
228 | | - count: 0 |
229 | | - }, |
230 | | - { |
231 | | - publicationStatus: 'Deaccessioned', |
232 | | - count: 0 |
| 108 | + expect(actual.totalItemCount).toBe(1) |
| 109 | + expect(actual.publicationStatusCounts).toEqual([ |
| 110 | + { |
| 111 | + publicationStatus: 'Published', |
| 112 | + count: 0 |
| 113 | + }, |
| 114 | + { |
| 115 | + publicationStatus: 'Unpublished', |
| 116 | + count: 1 |
| 117 | + }, |
| 118 | + { |
| 119 | + publicationStatus: 'Draft', |
| 120 | + count: 0 |
| 121 | + }, |
| 122 | + { |
| 123 | + publicationStatus: 'In Review', |
| 124 | + count: 0 |
| 125 | + }, |
| 126 | + { |
| 127 | + publicationStatus: 'Deaccessioned', |
| 128 | + count: 0 |
| 129 | + } |
| 130 | + ]) |
| 131 | + expect(actual.countPerObjectType).toEqual({ |
| 132 | + collections: 1, |
| 133 | + datasets: 0, |
| 134 | + files: 0 |
| 135 | + }) |
| 136 | + } catch (error) { |
| 137 | + console.log(error) |
| 138 | + throw new Error('Item subset should be retrieved') |
233 | 139 | } |
234 | | - ]) |
235 | | - expect(actual.countPerObjectType).toEqual({ |
236 | | - collections: 0, |
237 | | - datasets: 0, |
238 | | - files: 0 |
239 | 140 | }) |
240 | | - }) |
241 | | - |
242 | | - test('should return an empty item subset when no collection type is specified', async () => { |
243 | | - const actual = await getMyDataCollectionItems.execute( |
244 | | - testRoleIds, |
245 | | - [], |
246 | | - testPublishingStatuses, |
247 | | - undefined, |
248 | | - undefined, |
249 | | - undefined |
250 | | - ) |
251 | 141 |
|
252 | | - expect(actual.items).toEqual([]) |
253 | | - expect(actual.totalItemCount).toBe(0) |
254 | | - expect(actual.publicationStatusCounts).toEqual([ |
255 | | - { |
256 | | - publicationStatus: 'Published', |
257 | | - count: 0 |
258 | | - }, |
259 | | - { |
260 | | - publicationStatus: 'Unpublished', |
261 | | - count: 0 |
262 | | - }, |
263 | | - { |
264 | | - publicationStatus: 'Draft', |
265 | | - count: 0 |
266 | | - }, |
267 | | - { |
268 | | - publicationStatus: 'In Review', |
269 | | - count: 0 |
270 | | - }, |
271 | | - { |
272 | | - publicationStatus: 'Deaccessioned', |
273 | | - count: 0 |
274 | | - } |
275 | | - ]) |
276 | | - expect(actual.countPerObjectType).toEqual({ |
277 | | - collections: 0, |
278 | | - datasets: 0, |
279 | | - files: 0 |
280 | | - }) |
| 142 | + test('should return an error message when no role is specified', async () => { |
| 143 | + expect.assertions(2) |
| 144 | + let readError: ReadError | undefined = undefined |
| 145 | + try { |
| 146 | + await getMyDataCollectionItems.execute([], [], [], undefined, undefined, undefined) |
| 147 | + throw new Error('Use case should throw an error') |
| 148 | + } catch (error) { |
| 149 | + readError = error as ReadError |
| 150 | + } finally { |
| 151 | + expect(readError).toBeInstanceOf(ReadError) |
| 152 | + expect(readError?.message).toEqual( |
| 153 | + `There was an error when reading the resource. Reason was: No results. Please select at least one Role.` |
| 154 | + ) |
| 155 | + } |
| 156 | + }) |
| 157 | + test('should return an error message when no publication status is specified', async () => { |
| 158 | + expect.assertions(2) |
| 159 | + let readError: ReadError | undefined = undefined |
| 160 | + try { |
| 161 | + await getMyDataCollectionItems.execute( |
| 162 | + testRoleIds, |
| 163 | + testCollectionItemTypes, |
| 164 | + [], |
| 165 | + undefined, |
| 166 | + undefined, |
| 167 | + undefined |
| 168 | + ) |
| 169 | + throw new Error('Use case should throw an error') |
| 170 | + } catch (error) { |
| 171 | + readError = error as ReadError |
| 172 | + } finally { |
| 173 | + expect(readError).toBeInstanceOf(ReadError) |
| 174 | + expect(readError?.message).toEqual( |
| 175 | + `There was an error when reading the resource. Reason was: No user found for: "Published, Unpublished, Draft, In Review, Deaccessioned"` |
| 176 | + ) |
| 177 | + } |
| 178 | + }) |
| 179 | + test('should an error message when no collection type is specified', async () => { |
| 180 | + expect.assertions(2) |
| 181 | + let readError: ReadError | undefined = undefined |
| 182 | + try { |
| 183 | + await getMyDataCollectionItems.execute( |
| 184 | + testRoleIds, |
| 185 | + testCollectionItemTypes, |
| 186 | + [], |
| 187 | + undefined, |
| 188 | + undefined, |
| 189 | + undefined |
| 190 | + ) |
| 191 | + throw new Error('Use case should throw an error') |
| 192 | + } catch (error) { |
| 193 | + readError = error as ReadError |
| 194 | + } finally { |
| 195 | + expect(readError).toBeInstanceOf(ReadError) |
| 196 | + expect(readError?.message).toEqual( |
| 197 | + `There was an error when reading the resource. Reason was: No user found for: "Published, Unpublished, Draft, In Review, Deaccessioned"` |
| 198 | + ) |
| 199 | + } |
281 | 200 | }) |
282 | 201 | }) |
0 commit comments