Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
319 changes: 200 additions & 119 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,218 @@ 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
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 {
await getMyDataCollectionItems.execute(
const actual = await getMyDataCollectionItems.execute(
testRoleIds,
testCollectionItemTypes,
[PublicationStatus.Deaccessioned],
testPublishingStatuses,
undefined,
undefined,
undefined
testCollectionAlias
)
throw new Error('Use case should throw an error')

const actualCollectionPreview = actual.items[0] as CollectionPreview
expect(actualCollectionPreview.alias).toBe(testCollectionAlias)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the copilot suggested change is necessary, since the test only returns one item - ordering is not important.

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) {
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.'
)
console.log(error)
throw new Error('Item subset should be retrieved')
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this try/catch logic is leftover from when we had to assert the message in the Error, for empty result sets. So I think the try/catch and throw new Error can be removed.

}),
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)
test('should return an empty item subset when no role is specified', async () => {
const actual = await getMyDataCollectionItems.execute(
[],
[],
[],
undefined,
undefined,
undefined
)

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')
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 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 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