-
Notifications
You must be signed in to change notification settings - Fork 343
feat(content-sharing): convert api response for collabs #4322
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b1b171
feat(content-sharing): Convert api response for collaborators
reneshen0328 9f49c4f
feat(content-sharing): Convert api response for collaborators
reneshen0328 a7ecc91
fix: nits
reneshen0328 f28bde0
fix: add test coverage
reneshen0328 bbf2009
fix: test
reneshen0328 9c2f036
fix: remove console
reneshen0328 ec96144
fix: update contentSharingV2 useEffect logic
reneshen0328 f6bd77c
fix: add await for tests
reneshen0328 5802459
Merge branch 'master' into feat-convert-api-response-for-collabs
mergify[bot] 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
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
94 changes: 94 additions & 0 deletions
94
src/elements/content-sharing/apis/__tests__/fetchAvatars.test.ts
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,94 @@ | ||
| import { DEFAULT_USER_API_RESPONSE, MOCK_ITEM } from '../../utils/__mocks__/ContentSharingV2Mocks'; | ||
| import { fetchAvatars } from '..'; | ||
| import { createSuccessMock, createUsersAPIMock } from './testUtils'; | ||
|
|
||
| const getAvatarUrlMock = jest.fn(); | ||
| const getDefaultUserMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_USER_API_RESPONSE)); | ||
| const defaultAPIMock = createUsersAPIMock({ | ||
| getUser: getDefaultUserMock, | ||
| getAvatarUrlWithAccessToken: getAvatarUrlMock, | ||
| }); | ||
|
|
||
| const mockCollaborations = [ | ||
| { accessible_by: { id: 123 } }, | ||
| { accessible_by: { id: 456 } }, | ||
| { accessible_by: { id: 789 } }, | ||
| ]; | ||
|
|
||
| describe('content-sharing/apis/fetchAvatars', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should fetch avatars successfully', async () => { | ||
| getAvatarUrlMock | ||
| .mockResolvedValueOnce('https://example.com/avatar1.jpg') | ||
| .mockResolvedValueOnce('https://example.com/avatar2.jpg') | ||
| .mockResolvedValueOnce('https://example.com/avatar3.jpg'); | ||
|
|
||
| const result = await fetchAvatars({ | ||
| api: defaultAPIMock, | ||
| itemID: MOCK_ITEM.id, | ||
| collaborators: mockCollaborations, | ||
| }); | ||
|
|
||
| expect(defaultAPIMock.getUsersAPI).toHaveBeenCalledWith(false); | ||
| expect(getAvatarUrlMock).toHaveBeenCalledTimes(3); | ||
| expect(getAvatarUrlMock).toHaveBeenCalledWith('123', MOCK_ITEM.id); | ||
| expect(getAvatarUrlMock).toHaveBeenCalledWith('456', MOCK_ITEM.id); | ||
| expect(getAvatarUrlMock).toHaveBeenCalledWith('789', MOCK_ITEM.id); | ||
| expect(result).toEqual({ | ||
| 123: 'https://example.com/avatar1.jpg', | ||
| 456: 'https://example.com/avatar2.jpg', | ||
| 789: 'https://example.com/avatar3.jpg', | ||
| }); | ||
| }); | ||
|
|
||
| test('should handle avatar fetch errors gracefully', async () => { | ||
| getAvatarUrlMock | ||
| .mockResolvedValueOnce('https://example.com/avatar1.jpg') | ||
| .mockRejectedValueOnce(new Error('Avatar fetch failed')) | ||
| .mockResolvedValueOnce('https://example.com/avatar3.jpg'); | ||
|
|
||
| const result = await fetchAvatars({ | ||
| api: defaultAPIMock, | ||
| itemID: MOCK_ITEM.id, | ||
| collaborators: mockCollaborations, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| 123: 'https://example.com/avatar1.jpg', | ||
| 456: null, | ||
| 789: 'https://example.com/avatar3.jpg', | ||
| }); | ||
| }); | ||
|
|
||
| test('should handle collaborators without accessible_by', async () => { | ||
| const collaboratorsWithMissingData = [{ accessible_by: { id: 123 } }, {}, { accessible_by: null }]; | ||
|
|
||
| getAvatarUrlMock.mockResolvedValue('https://example.com/avatar.jpg'); | ||
|
|
||
| const result = await fetchAvatars({ | ||
| api: defaultAPIMock, | ||
| itemID: MOCK_ITEM.id, | ||
| collaborators: collaboratorsWithMissingData, | ||
| }); | ||
|
|
||
| expect(getAvatarUrlMock).toHaveBeenCalledTimes(1); | ||
| expect(getAvatarUrlMock).toHaveBeenCalledWith('123', MOCK_ITEM.id); | ||
| expect(result).toEqual({ | ||
| 123: 'https://example.com/avatar.jpg', | ||
| }); | ||
| }); | ||
|
|
||
| test('should handle empty collaborators array', async () => { | ||
| const result = await fetchAvatars({ | ||
| api: defaultAPIMock, | ||
| itemID: MOCK_ITEM.id, | ||
| collaborators: [], | ||
| }); | ||
|
|
||
| expect(getAvatarUrlMock).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({}); | ||
| }); | ||
| }); |
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.