-
Notifications
You must be signed in to change notification settings - Fork 8
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
178 publish collection use case #182
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1a5db45
Add Publish Collection use case and functional test
ekraffmiller ba8de45
fix: use doGet() in PublishCollection implemementation
ekraffmiller 0a0dcf2
updated tests
ekraffmiller c50b63e
use consistent param name
ekraffmiller 3cb8f19
fix: function documentation
ekraffmiller 7f18ee4
add use case documentation
ekraffmiller 14a99ff
resolve merge conflicts
ekraffmiller 942ae75
Update PublishCollection.ts
ekraffmiller 957496c
Merge branch 'develop' into 178-publish-collection
ekraffmiller 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 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { UseCase } from '../../../core/domain/useCases/UseCase' | ||
import { ICollectionsRepository } from '../repositories/ICollectionsRepository' // Assuming Axios for HTTP requests | ||
|
||
export class PublishCollection implements UseCase<void> { | ||
private collectionsRepository: ICollectionsRepository | ||
|
||
constructor(collectionsRepository: ICollectionsRepository) { | ||
this.collectionsRepository = collectionsRepository | ||
} | ||
|
||
/** | ||
* Publishes a collection, given its identifier and the type of version update type. | ||
* | ||
* @param {number | string} [collectionIdOrAlias] - The collection identifier, which can be a string (for collection alias), or a number (for numeric identifiers). | ||
* @returns {Promise<void>} - This method does not return anything upon successful completion. | ||
*/ | ||
async execute(collectionIdOrAlias: number | string): Promise<void> { | ||
return await this.collectionsRepository.publishCollection(collectionIdOrAlias) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ApiConfig, createCollection, publishCollection, WriteError } from '../../../src' | ||
import { TestConstants } from '../../testHelpers/TestConstants' | ||
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' | ||
import { | ||
createCollectionDTO, | ||
deleteCollectionViaApi | ||
} from '../../testHelpers/collections/collectionHelper' | ||
|
||
const testNewCollection = createCollectionDTO('test-publish-collection') | ||
|
||
describe('execute', () => { | ||
beforeEach(async () => { | ||
ApiConfig.init( | ||
TestConstants.TEST_API_URL, | ||
DataverseApiAuthMechanism.API_KEY, | ||
process.env.TEST_API_KEY | ||
) | ||
}) | ||
|
||
test('should successfully publish a collection with id', async () => { | ||
const createdCollectiontIdentifier = await createCollection.execute(testNewCollection) | ||
|
||
const response = await publishCollection.execute(createdCollectiontIdentifier) | ||
|
||
expect(response).toBeUndefined() | ||
await deleteCollectionViaApi(testNewCollection.alias) | ||
}) | ||
test('should successfully publish a collection with alias', async () => { | ||
await createCollection.execute(testNewCollection) | ||
|
||
const response = await publishCollection.execute(testNewCollection.alias) | ||
|
||
expect(response).toBeUndefined() | ||
await deleteCollectionViaApi(testNewCollection.alias) | ||
}) | ||
|
||
test('should throw an error when trying to publish a collection that does not exist', async () => { | ||
const nonExistentTestCollectionId = 4567 | ||
const expectedError = new WriteError( | ||
`[404] Can't find dataverse with identifier='${nonExistentTestCollectionId}'` | ||
) | ||
|
||
await expect(publishCollection.execute(nonExistentTestCollectionId)).rejects.toThrow( | ||
expectedError | ||
) | ||
}) | ||
}) |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository' | ||
import { PublishCollection } from '../../../src/collections/domain/useCases/PublishCollection' | ||
import { WriteError } from '../../../src' | ||
|
||
describe('execute', () => { | ||
test('should return undefined on repository success', async () => { | ||
const collectionsRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository | ||
collectionsRepositoryStub.publishCollection = jest.fn().mockResolvedValue(undefined) | ||
const sut = new PublishCollection(collectionsRepositoryStub) | ||
|
||
const actual = await sut.execute(1) | ||
|
||
expect(actual).toEqual(undefined) | ||
}) | ||
|
||
test('should return error result on repository error', async () => { | ||
const collectionsRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository | ||
collectionsRepositoryStub.publishCollection = jest.fn().mockRejectedValue(new WriteError()) | ||
const sut = new PublishCollection(collectionsRepositoryStub) | ||
|
||
await expect(sut.execute(1)).rejects.toThrow(WriteError) | ||
}) | ||
}) |
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 think the last part
"and the type of version update type."
should be removed!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.
@GPortas thanks for finding that, done!