Skip to content

Commit

Permalink
fix(uaa-refactor): UAA handle uploader_display_name field (#3756)
Browse files Browse the repository at this point in the history
* fix(uaa-refactor): Handle uploader_display_name field

* fix(uaa-refactor): Handle uploader_display_name field

* fix(uaa-sidebar): Fix test

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
JChan106 and mergify[bot] authored Dec 3, 2024
1 parent 2d8facb commit bd9d44a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/api/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ export const getParsedFileActivitiesResponse = (
if (versionsItem.action_by) {
const collaborators = {};

if (versionsItem.action_by.length === 1) {
versionsItem.uploader_display_name = versionsItem.action_by[0].name;
}

versionsItem.action_by.map(collaborator => {
collaborators[collaborator.id] = { ...collaborator };
return collaborator;
Expand All @@ -228,6 +224,7 @@ export const getParsedFileActivitiesResponse = (

if (versionsItem.version_start === versionsItem.version_end) {
versionsItem.version_number = versionsItem.version_start;
versionsItem.uploader_display_name = versionsItem.start?.uploader_display_name;

if (
versionsItem.action_type === ACTION_TYPE_CREATED &&
Expand Down
15 changes: 15 additions & 0 deletions src/api/__tests__/Feed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
threadedComments as mockThreadedComments,
threadedCommentsFormatted,
annotationsWithFormattedReplies as mockFormattedAnnotations,
fileActivitiesVersion,
} from '../fixtures';

const mockErrors = [{ code: 'error_code_0' }, { code: 'error_code_1' }];
Expand Down Expand Up @@ -2331,10 +2332,24 @@ describe('api/Feed', () => {
${{ entries: mockFileActivities }}
${{ entries: [...mockFileActivities, { test: 'filtered out' }] }}
`('should return a parsed entries array when response is valid', ({ response }) => {
const mockUser = fileActivitiesVersion.start.created_by;

expect(getParsedFileActivitiesResponse(response)).toEqual([
{ ...mockTask, task_type: 'GENERAL', created_by: { target: mockTask.created_by.target } },
threadedCommentsFormatted[0],
mockFormattedAnnotations[0],
{
...fileActivitiesVersion,
uploader_display_name: 'John Doe',
type: FEED_ITEM_TYPE_VERSION,
version_number: 1,
version_end: 1,
version_start: 1,
modified_at: '2022-01-05T10:12:28.000-08:00',
id: '123',
modified_by: mockUser,
collaborators: { 42: mockUser },
},
]);
});
});
Expand Down
49 changes: 49 additions & 0 deletions src/api/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FILE_ACTIVITY_TYPE_ANNOTATION,
FILE_ACTIVITY_TYPE_COMMENT,
FILE_ACTIVITY_TYPE_TASK,
FILE_ACTIVITY_TYPE_VERSION,
TASK_NEW_NOT_STARTED,
} from '../constants';

Expand Down Expand Up @@ -84,6 +85,53 @@ export const annotations = [
},
];

export const fileActivitiesVersion = {
end: {
created_at: '2022-01-05T10:12:28.000-08:00',
created_by: {
id: '42',
name: 'John Doe',
login: 'johndoe@box.com',
type: 'user',
},
id: '123',
number: 1,
uploader_display_name: 'John Doe',
type: 'file_version',
},
start: {
created_at: '2022-01-05T10:12:28.000-08:00',
created_by: {
id: '42',
name: 'John Doe',
login: 'johndoe@box.com',
type: 'user',
},
id: '123',
number: 1,
uploader_display_name: 'John Doe',
type: 'file_version',
},
action_by: [
{
id: '42',
name: 'John Doe',
login: 'johndoe@box.com',
type: 'user',
},
],
created_by: [
{
id: '42',
name: 'John Doe',
login: 'johndoe@box.com',
type: 'user',
},
],
type: 'versions',
action_type: 'created',
};

export const annotationsWithFormattedReplies = [
{
created_at: '2022-08-19T03:39:00-07:00',
Expand Down Expand Up @@ -400,6 +448,7 @@ export const threadedCommentsFormatted = [
];

export const fileActivities = [
{ activity_type: FILE_ACTIVITY_TYPE_VERSION, source: { versions: fileActivitiesVersion } },
{ activity_type: FILE_ACTIVITY_TYPE_ANNOTATION, source: { annotation: annotationsWithFormattedReplies[0] } },
{ activity_type: FILE_ACTIVITY_TYPE_COMMENT, source: { comment: threadedCommentsFormatted[0] } },
{
Expand Down

0 comments on commit bd9d44a

Please sign in to comment.