Add use case for setting default contributor#415
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new Collections use case to set a collection’s default contributor role (Dataverse endpoint for assigning the default role to users creating datasets in a collection), wiring it through the repository layer, public exports, docs, and unit tests.
Changes:
- Add
SetDefaultContributorRoleuse case and expose it from the collections public API. - Implement
setDefaultContributorRoleinCollectionsRepositoryand add it toICollectionsRepository. - Document the new use case and add a unit test for the use case behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
test/unit/collections/SetDefaultContributorRole.test.ts |
Adds unit tests for the new use case. |
src/collections/infra/repositories/CollectionsRepository.ts |
Adds repository method calling the Dataverse API endpoint via PUT. |
src/collections/index.ts |
Exposes the new use case from the collections module. |
src/collections/domain/useCases/SetDefaultContributorRole.ts |
Introduces the new use case implementation and JSDoc. |
src/collections/domain/repositories/ICollectionsRepository.ts |
Extends the repository interface with the new method. |
docs/useCases.md |
Documents the new use case and adds it to the use-cases list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await expect(testSetDefaultContributorRole.execute(1, "curator")).resolves.toBeUndefined() | ||
| expect(collectionRepositoryStub.setDefaultContributorRole).toHaveBeenCalledWith(1, "curator") |
| await expect(testSetDefaultContributorRole.execute(1, "curator")).rejects.toThrow(WriteError) | ||
| expect(collectionRepositoryStub.setDefaultContributorRole).toHaveBeenCalledWith(1, "curator") |
| public async setDefaultContributorRole( | ||
| collectionIdOrAlias: number | string, | ||
| roleAlias: string | ||
| ): Promise<void> { | ||
| return this.doPut( | ||
| `/${this.collectionsResourceName}/${collectionIdOrAlias}/defaultContributorRole/${roleAlias}`, | ||
| {} | ||
| ) | ||
| .then(() => undefined) | ||
| .catch((error) => { | ||
| throw error | ||
| }) | ||
| } |
| #### Set Default Contributor Role | ||
|
|
||
| Sets the default contributor role of a collection, given a collection identifier and a role alias. | ||
|
|
||
| ##### Example call: | ||
|
|
||
| ```typescript | ||
| import { setDefaultContributorRole } from '@iqss/dataverse-client-javascript' | ||
|
|
||
| /* ... */ | ||
|
|
||
| const collectionIdOrAlias = 12345 | ||
| const roleAlias = 'curator' | ||
|
|
||
| setDefaultContributorRole.execute(collectionIdOrAlias, roleAlias) | ||
|
|
ChengShi-1
left a comment
There was a problem hiding this comment.
Hi Vera, thanks for your contribution! Here are some suggestions
- Merge with dev to update
- update Changelog.md
- For roleAlias(see roles in Dataverse), we could have a built-in reference to export, similar to
FileCitationFormat.tsin js-dataverse- For example,
export enum RoleAlias { ADMIN = 'Admin', ...}
- For example,
- add integration test proving the setDefault is working in different conditions
- Successfully set a role, if possible, please check GET collection return a correct roleAlias
- If this parameter is not set, the default value is: ':root'
- maybe a few error conditions
- run
npm run format npx prettier . --checkbefore your commit to clear the format
Hi @vera , sorry I forgot to @ you earlier. Just mentioning you here in case you have time to follow up. |
|
@ChengShi-1 thanks for the reminder. I'll be on vacation for the rest of the month, but I'll be picking this up again in August (along with my other open PRs in this repo). |
What this PR does / why we need it:
This PR adds code for setting the default contributor role of a collection.
Which issue(s) this PR closes:
/
Related Dataverse PRs:
/
Special notes for your reviewer:
/
Suggestions on how to test this:
I've added tests and docs on how to use.
Is there a release notes or changelog update needed for this change?:
Yes
Additional documentation: