-
Notifications
You must be signed in to change notification settings - Fork 11
Extend get guestbooks use case with stats and Download responses #449
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 11 commits into
develop
from
448-add-usage-and-response-counts-to-get-guestbooks-use-case
Jun 10, 2026
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
96b99ac
feat: extend guestbook with counts
ChengShi-1 de17e97
fix: integration tests
ChengShi-1 6343e69
fix: add use case of downloading responses
ChengShi-1 8ac4f89
fix: lint error
ChengShi-1 8c66e14
update changelog and useCase.md
ChengShi-1 b2ba964
feat: update includeInherited guestbooks queryparam
ChengShi-1 74edeaa
fix: change dataverseId to collectionId, and update GetGuestbookRespo…
ChengShi-1 a84e7f0
Merge branch 'develop' into 448-add-usage-and-response-counts-to-get-…
ChengShi-1 0576b3f
chore: fix lowercases to Uppercases in the naming
ChengShi-1 d447d3f
chore: fix lint
ChengShi-1 46b12b0
fix: add pagination info to return result
ChengShi-1 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import axios from 'axios' | ||
| import { | ||
| ApiConfig, | ||
| DataverseApiAuthMechanism | ||
| } from '../../../src/core/infra/repositories/ApiConfig' | ||
| import { GuestbooksRepository } from '../../../src/guestbooks/infra/repositories/GuestbooksRepository' | ||
| import { ReadError } from '../../../src/core/domain/repositories/ReadError' | ||
| import { TestConstants } from '../../testHelpers/TestConstants' | ||
|
|
||
| describe('GuestbooksRepository', () => { | ||
| const sut = new GuestbooksRepository() | ||
| const collectionIdOrAlias = 'collectionAlias' | ||
| const guestbooksResponse = { | ||
| data: { | ||
| status: 'OK', | ||
| data: [ | ||
| { | ||
| id: 12, | ||
| name: 'test', | ||
| enabled: true, | ||
| emailRequired: true, | ||
| nameRequired: true, | ||
| institutionRequired: false, | ||
| positionRequired: false, | ||
| customQuestions: [], | ||
| createTime: '2024-01-01T00:00:00Z', | ||
| dataverseId: 10, | ||
| usageCount: 3, | ||
| responseCount: 2 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| ApiConfig.init( | ||
| TestConstants.TEST_API_URL, | ||
| DataverseApiAuthMechanism.API_KEY, | ||
| TestConstants.TEST_DUMMY_API_KEY | ||
| ) | ||
|
|
||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| describe('getGuestbooksByCollectionId', () => { | ||
| test('should list guestbooks without stats by default', async () => { | ||
| jest.spyOn(axios, 'get').mockResolvedValue(guestbooksResponse) | ||
|
|
||
| const actual = await sut.getGuestbooksByCollectionId(collectionIdOrAlias) | ||
|
|
||
| expect(axios.get).toHaveBeenCalledWith( | ||
| `${TestConstants.TEST_API_URL}/guestbooks/${collectionIdOrAlias}/list`, | ||
| TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY | ||
| ) | ||
| expect(actual).toStrictEqual(guestbooksResponse.data.data) | ||
| }) | ||
|
|
||
| test('should list guestbooks with stats when includeStats is true', async () => { | ||
| jest.spyOn(axios, 'get').mockResolvedValue(guestbooksResponse) | ||
|
|
||
| const actual = await sut.getGuestbooksByCollectionId(collectionIdOrAlias, true) | ||
|
|
||
| expect(axios.get).toHaveBeenCalledWith( | ||
| `${TestConstants.TEST_API_URL}/guestbooks/${collectionIdOrAlias}/list`, | ||
| { | ||
| params: { | ||
| includeStats: true | ||
| }, | ||
| headers: TestConstants.TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY.headers | ||
| } | ||
| ) | ||
| expect(actual[0].usageCount).toBe(3) | ||
| expect(actual[0].responseCount).toBe(2) | ||
| }) | ||
|
|
||
| test('should return error result on error response', async () => { | ||
| jest.spyOn(axios, 'get').mockRejectedValue(TestConstants.TEST_ERROR_RESPONSE) | ||
|
|
||
| await expect(sut.getGuestbooksByCollectionId(collectionIdOrAlias, true)).rejects.toThrow( | ||
| ReadError | ||
| ) | ||
| }) | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.