Skip to content

Commit 3381bbd

Browse files
authored
Merge pull request #451 from IQSS/450-update-the-tests-related-to-mydata-api
update tests for the MyData api fix
2 parents fafe986 + 40f8509 commit 3381bbd

2 files changed

Lines changed: 240 additions & 144 deletions

File tree

test/functional/collections/GetMyDataCollectionItems.test.ts

Lines changed: 201 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
createDataset,
44
CreatedDatasetIdentifiers,
55
CollectionPreview,
6-
getMyDataCollectionItems,
7-
ReadError
6+
getMyDataCollectionItems
87
} from '../../../src'
98
import { TestConstants } from '../../testHelpers/TestConstants'
109
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
@@ -66,136 +65,213 @@ describe('execute', () => {
6665
throw new Error('Tests afterAll(): Error while deleting test collection')
6766
}
6867
})
69-
test('should return error message when repository returns empty item subset', async () => {
70-
expect.assertions(2)
71-
let readError: ReadError | undefined = undefined
72-
try {
73-
await getMyDataCollectionItems.execute(
74-
testRoleIds,
75-
testCollectionItemTypes,
76-
[PublicationStatus.Deaccessioned],
77-
undefined,
78-
undefined,
79-
undefined
80-
)
81-
throw new Error('Use case should throw an error')
82-
} catch (error) {
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-
)
89-
}
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))
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+
)
9477

95-
try {
96-
const actual = await getMyDataCollectionItems.execute(
97-
testRoleIds,
98-
testCollectionItemTypes,
99-
testPublishingStatuses,
100-
undefined,
101-
undefined,
102-
testCollectionAlias
103-
)
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+
})
104108

105-
const actualCollectionPreview = actual.items[0] as CollectionPreview
106-
expect(actualCollectionPreview.alias).toBe(testCollectionAlias)
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+
113+
const actual = await getMyDataCollectionItems.execute(
114+
testRoleIds,
115+
testCollectionItemTypes,
116+
testPublishingStatuses,
117+
undefined,
118+
undefined,
119+
testCollectionAlias
120+
)
107121

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')
122+
const actualCollectionPreview = actual.items[0] as CollectionPreview
123+
expect(actualCollectionPreview.alias).toBe(testCollectionAlias)
124+
125+
expect(actual.totalItemCount).toBe(1)
126+
expect(actual.publicationStatusCounts).toEqual([
127+
{
128+
publicationStatus: 'Published',
129+
count: 0
130+
},
131+
{
132+
publicationStatus: 'Unpublished',
133+
count: 1
134+
},
135+
{
136+
publicationStatus: 'Draft',
137+
count: 0
138+
},
139+
{
140+
publicationStatus: 'In Review',
141+
count: 0
142+
},
143+
{
144+
publicationStatus: 'Deaccessioned',
145+
count: 0
139146
}
147+
])
148+
expect(actual.countPerObjectType).toEqual({
149+
collections: 1,
150+
datasets: 0,
151+
files: 0
140152
})
153+
})
141154

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-
}
155+
test('should return an empty item subset when no role is specified', async () => {
156+
const actual = await getMyDataCollectionItems.execute(
157+
[],
158+
[],
159+
[],
160+
undefined,
161+
undefined,
162+
undefined
163+
)
164+
165+
expect(actual.items).toEqual([])
166+
expect(actual.totalItemCount).toBe(0)
167+
expect(actual.publicationStatusCounts).toEqual([
168+
{
169+
publicationStatus: 'Published',
170+
count: 0
171+
},
172+
{
173+
publicationStatus: 'Unpublished',
174+
count: 0
175+
},
176+
{
177+
publicationStatus: 'Draft',
178+
count: 0
179+
},
180+
{
181+
publicationStatus: 'In Review',
182+
count: 0
183+
},
184+
{
185+
publicationStatus: 'Deaccessioned',
186+
count: 0
187+
}
188+
])
189+
expect(actual.countPerObjectType).toEqual({
190+
collections: 0,
191+
datasets: 0,
192+
files: 0
193+
})
156194
})
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-
}
195+
196+
test('should return an empty item subset when no publication status is specified', async () => {
197+
const actual = await getMyDataCollectionItems.execute(
198+
testRoleIds,
199+
testCollectionItemTypes,
200+
[],
201+
undefined,
202+
undefined,
203+
undefined
204+
)
205+
206+
expect(actual.items).toEqual([])
207+
expect(actual.totalItemCount).toBe(0)
208+
expect(actual.publicationStatusCounts).toEqual([
209+
{
210+
publicationStatus: 'Published',
211+
count: 0
212+
},
213+
{
214+
publicationStatus: 'Unpublished',
215+
count: 0
216+
},
217+
{
218+
publicationStatus: 'Draft',
219+
count: 0
220+
},
221+
{
222+
publicationStatus: 'In Review',
223+
count: 0
224+
},
225+
{
226+
publicationStatus: 'Deaccessioned',
227+
count: 0
228+
}
229+
])
230+
expect(actual.countPerObjectType).toEqual({
231+
collections: 0,
232+
datasets: 0,
233+
files: 0
234+
})
178235
})
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-
}
236+
237+
test('should return an empty item subset when no collection type is specified', async () => {
238+
const actual = await getMyDataCollectionItems.execute(
239+
testRoleIds,
240+
[],
241+
testPublishingStatuses,
242+
undefined,
243+
undefined,
244+
undefined
245+
)
246+
247+
expect(actual.items).toEqual([])
248+
expect(actual.totalItemCount).toBe(0)
249+
expect(actual.publicationStatusCounts).toEqual([
250+
{
251+
publicationStatus: 'Published',
252+
count: 0
253+
},
254+
{
255+
publicationStatus: 'Unpublished',
256+
count: 0
257+
},
258+
{
259+
publicationStatus: 'Draft',
260+
count: 0
261+
},
262+
{
263+
publicationStatus: 'In Review',
264+
count: 0
265+
},
266+
{
267+
publicationStatus: 'Deaccessioned',
268+
count: 0
269+
}
270+
])
271+
expect(actual.countPerObjectType).toEqual({
272+
collections: 0,
273+
datasets: 0,
274+
files: 0
275+
})
200276
})
201277
})

0 commit comments

Comments
 (0)