Skip to content

Commit

Permalink
fix(uaa-parity): Handle UAA Promotion Fix (#3835)
Browse files Browse the repository at this point in the history
* fix(uaa-parity): Handle UAA promoted_from field

* fix(uaa-parity): Add version promotion tests
  • Loading branch information
JChan106 authored Jan 10, 2025
1 parent 0041134 commit b6d983f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/Feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import AppActivityAPI from './AppActivity';
import {
ACTION_TYPE_CREATED,
ACTION_TYPE_RESTORED,
ACTION_TYPE_PROMOTED,
ACTION_TYPE_TRASHED,
ERROR_CODE_CREATE_TASK,
ERROR_CODE_UPDATE_TASK,
Expand Down Expand Up @@ -250,6 +251,9 @@ export const getParsedFileActivitiesResponse = (
versionsItem.restored_at = versionsItem.start.restored_at;
versionsItem.restored_by = { ...versionsItem.start.restored_by };
}
if (versionsItem.action_type === ACTION_TYPE_PROMOTED && versionsItem.start?.promoted_from) {
versionsItem.version_promoted = versionsItem.start?.promoted_from;
}
}

return versionsItem;
Expand Down
27 changes: 27 additions & 0 deletions src/api/__tests__/Feed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
threadedCommentsFormatted,
annotationsWithFormattedReplies as mockFormattedAnnotations,
fileActivitiesVersion,
promotedFileActivitiesVersion,
} from '../fixtures';

const mockErrors = [{ code: 'error_code_0' }, { code: 'error_code_1' }];
Expand Down Expand Up @@ -2352,5 +2353,31 @@ describe('api/Feed', () => {
},
]);
});

test('should return a parsed entries array when response is valid', () => {
const mockUser = fileActivitiesVersion.start.created_by;
const promotedFileActivities = {
entries: [
{
activity_type: FILE_ACTIVITY_TYPE_VERSION,
source: { versions: promotedFileActivitiesVersion },
},
],
};

expect(getParsedFileActivitiesResponse(promotedFileActivities)).toEqual([
{
...promotedFileActivitiesVersion,
uploader_display_name: 'John Doe',
type: FEED_ITEM_TYPE_VERSION,
version_number: 4,
version_end: 4,
version_start: 4,
id: '123',
collaborators: { 42: mockUser },
version_promoted: 2,
},
]);
});
});
});
49 changes: 49 additions & 0 deletions src/api/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,55 @@ export const fileActivitiesVersion = {
action_type: 'created',
};

export const promotedFileActivitiesVersion = {
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: 4,
uploader_display_name: 'John Doe',
type: 'file_version',
promoted_from: 2,
},
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: 4,
uploader_display_name: 'John Doe',
type: 'file_version',
promoted_from: 2,
},
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: 'promoted',
};

export const annotationsWithFormattedReplies = [
{
created_at: '2022-08-19T03:39:00-07:00',
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export const ACTIVITY_FILTER_OPTION_UNRESOLVED: 'open' = 'open';
/* ------------------ File Activity Action Types ----------- */
export const ACTION_TYPE_CREATED: 'created' = 'created';
export const ACTION_TYPE_RESTORED: 'restored' = 'restored';
export const ACTION_TYPE_PROMOTED: 'promoted' = 'promoted';
export const ACTION_TYPE_TRASHED: 'trashed' = 'trashed';

/* ------------------ File Activity Types ------------------ */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,25 @@ describe('elements/content-sidebar/ActivityFeed/version/Version', () => {
version_number: '1',
});
});

test('should correctly render promoted version', () => {
selectors.getVersionUser = jest.fn().mockReturnValueOnce(defaultUser);

const version = {
id: '14',
modified_at: Date.now(),
modified_by: defaultUser,
version_number: '10',
version_promoted: '2',
};

const wrapper = shallow(<Version {...version} {...translationProps} />);

expect(wrapper.hasClass('bcs-Version')).toBe(true);
expect(wrapper.find('FormattedMessage').prop('values')).toEqual({
name: <strong>{defaultUser.name}</strong>,
version_number: '10',
version_promoted: '2',
});
});
});

0 comments on commit b6d983f

Please sign in to comment.