Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 201 additions & 125 deletions test/functional/collections/GetMyDataCollectionItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
createDataset,
CreatedDatasetIdentifiers,
CollectionPreview,
getMyDataCollectionItems,
ReadError
getMyDataCollectionItems
} from '../../../src'
import { TestConstants } from '../../testHelpers/TestConstants'
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
Expand Down Expand Up @@ -66,136 +65,213 @@ describe('execute', () => {
throw new Error('Tests afterAll(): Error while deleting test collection')
}
})
test('should return error message when repository returns empty item subset', async () => {
expect.assertions(2)
let readError: ReadError | undefined = undefined
try {
await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
[PublicationStatus.Deaccessioned],
undefined,
undefined,
undefined
)
throw new Error('Use case should throw an error')
} catch (error) {
readError = error as ReadError
} finally {
expect(readError).toBeInstanceOf(ReadError)
expect(readError?.message).toEqual(
'There was an error when reading the resource. Reason was: Sorry, no results were found.'
)
}
}),
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))
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'
)

try {
const actual = await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
testPublishingStatuses,
undefined,
undefined,
testCollectionAlias
)
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
})
})

const actualCollectionPreview = actual.items[0] as CollectionPreview
expect(actualCollectionPreview.alias).toBe(testCollectionAlias)
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))

const actual = await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
testPublishingStatuses,
undefined,
undefined,
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')
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
})
})

test('should return an error message when no role is specified', async () => {
expect.assertions(2)
let readError: ReadError | undefined = undefined
try {
await getMyDataCollectionItems.execute([], [], [], undefined, undefined, undefined)
throw new Error('Use case should throw an error')
} catch (error) {
readError = error as ReadError
} finally {
expect(readError).toBeInstanceOf(ReadError)
expect(readError?.message).toEqual(
`There was an error when reading the resource. Reason was: No results. Please select at least one Role.`
)
}
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 error message when no publication status is specified', async () => {
expect.assertions(2)
let readError: ReadError | undefined = undefined
try {
await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
[],
undefined,
undefined,
undefined
)
throw new Error('Use case should throw an error')
} catch (error) {
readError = error as ReadError
} finally {
expect(readError).toBeInstanceOf(ReadError)
expect(readError?.message).toEqual(
`There was an error when reading the resource. Reason was: No user found for: "Published, Unpublished, Draft, In Review, Deaccessioned"`
)
}

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 an error message when no collection type is specified', async () => {
expect.assertions(2)
let readError: ReadError | undefined = undefined
try {
await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
[],
undefined,
undefined,
undefined
)
throw new Error('Use case should throw an error')
} catch (error) {
readError = error as ReadError
} finally {
expect(readError).toBeInstanceOf(ReadError)
expect(readError?.message).toEqual(
`There was an error when reading the resource. Reason was: No user found for: "Published, Unpublished, Draft, In Review, Deaccessioned"`
)
}

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
})
})
})
Loading
Loading