-
Notifications
You must be signed in to change notification settings - Fork 11
update tests for the MyData api fix #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ekraffmiller
merged 2 commits into
develop
from
450-update-the-tests-related-to-mydata-api
Jun 3, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
|
@@ -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) | ||
|
|
||
| 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') | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| }) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.