Skip to content
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

refactor: Update error message while adding library team member [FC-0062] #1572

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/library-authoring/library-team/LibraryTeam.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ describe('<LibraryTeam />', () => {
expect(await screen.findByText('Team Member added')).toBeInTheDocument();
});

it('shows error when user do not exist', async () => {
it('shows error when specific error', async () => {
const url = getLibraryTeamApiUrl(libraryId);
const axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock.onPost(url).reply(400, { email: 'Error' });
axiosMock.onPost(url).reply(400, { email: 'This is an specific error.' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
axiosMock.onPost(url).reply(400, { email: 'This is an specific error.' });
axiosMock.onPost(url).reply(400, { email: 'This is a specific error.' });


await renderLibraryTeam();

Expand All @@ -204,7 +204,7 @@ describe('<LibraryTeam />', () => {
});

expect(await screen.findByText(
'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.',
'Error adding Team Member. This is an specific error.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Error adding Team Member. This is an specific error.',
'Error adding Team Member. This is a specific error.',

)).toBeInTheDocument();
});

Expand Down
11 changes: 10 additions & 1 deletion src/library-authoring/library-team/LibraryTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@
}).catch((addMemberError) => {
const errorData = typeof addMemberError === 'object' ? addMemberError.response?.data : undefined;
if (errorData && 'email' in errorData) {
showToast(intl.formatMessage(messages.addMemberEmailError));
const errorEmail = errorData.email;
if (typeof errorEmail === 'string') {
showToast(intl.formatMessage(messages.addMemberSpecificError, {
message: errorEmail,
}));
} else {
showToast(intl.formatMessage(messages.addMemberSpecificError, {

Check warning on line 77 in src/library-authoring/library-team/LibraryTeam.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/library-team/LibraryTeam.tsx#L76-L77

Added lines #L76 - L77 were not covered by tests
message: errorEmail[0],
}));
}
} else {
showToast(intl.formatMessage(messages.addMemberError));
}
Expand Down
8 changes: 4 additions & 4 deletions src/library-authoring/library-team/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ const messages = defineMessages({
defaultMessage: 'Error adding Team Member',
description: 'Message shown when an error occurs while adding a Library Team member',
},
addMemberEmailError: {
id: 'course-authoring.library-authoring.library-team.add-member-email-error',
defaultMessage: 'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.',
description: 'Message shown when an error occurs with email while adding a Library Team member.',
addMemberSpecificError: {
id: 'course-authoring.library-authoring.library-team.add-member-specific-error',
defaultMessage: 'Error adding Team Member. {message}',
description: 'Message shown when an error occurs with an specific error while adding a Library Team member.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: 'Message shown when an error occurs with an specific error while adding a Library Team member.',
description: 'Message shown when an error occurs while adding a Library Team member, including a specific error message.',

},
deleteMemberSuccess: {
id: 'course-authoring.library-authoring.library-team.delete-member-success',
Expand Down
Loading