Skip to content

Commit

Permalink
🥅(frontend) catch new errors on mailbox creation
Browse files Browse the repository at this point in the history
- catch errors related to MAIL_PROVISIONING_API_CREDENTIALS
introduced in commit #ba30b1d3eec73718add6585f30c6b7959cb21850.
Intentionally does not parse the error
"Permission denied. Please check your MAIL_PROVISIONING_API_CREDENTIALS."
as it means the user is neither admin or owner of the domain and
should not access the mailbox creation form
- update translations and component tests
  • Loading branch information
daproclaima committed Sep 10, 2024
1 parent 77cc64a commit ca192c9
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ export const ModalCreateMailbox = ({
},
secret: {
causes: [
"Please configure your domain's secret before creating any mailbox.",
`Secret not valid for this domain`,
'Token denied. Please check your MAIL_PROVISIONING_API_CREDENTIALS.',
'Please configure MAIL_PROVISIONING_API_CREDENTIALS before creating any mailbox.',
],
causeShown: t(
'The mail domain secret is misconfigured. Please, contact ' +
'our support team to solve the issue: [email protected]',
'Your request to create a mailbox cannot be completed due to incorrect settings on our server. ' +
'Please contact our support team to resolve the problem: [email protected]',
),
handleError: () => {
methods.setFocus('first_name');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,7 @@ describe('ModalCreateMailbox', () => {
expect(mockOnSuccess).toHaveBeenCalled();
});

it('displays right error message error when mailbox prefix is already used', async () => {
// mockCreateMailbox.mockRejectedValueOnce(
// new APIError('Failed to create the mailbox', {
// status: 400,
// cause: ['Mailbox with this Local_part and Domain already exists.'],
// }),
// );
it('displays right error message when mailbox prefix is already used', async () => {
fetchMock.mock(`end:mail-domains/${mockMailDomain.slug}/mailboxes/`, {
status: 400,
body: {
Expand Down Expand Up @@ -294,6 +288,125 @@ describe('ModalCreateMailbox', () => {
expect(inputLocalPart).toHaveFocus();
});

it('displays right error message when DImail api token is invalid', async () => {
fetchMock.mock(`end:mail-domains/${mockMailDomain.slug}/mailboxes/`, {
status: 400,
body: {
secret:
'Token denied. Please check your MAIL_PROVISIONING_API_CREDENTIALS.',
},
});

const user = userEvent.setup();

renderModalCreateMailbox();

const {
inputFirstName,
inputLastName,
inputLocalPart,
inputEmailAddress,
buttonSubmit,
} = getFormElements();

await user.type(inputFirstName, 'John');
await user.type(inputLastName, 'Doe');
await user.type(inputLocalPart, 'john.doe');
await user.type(inputEmailAddress, '[email protected]');

await user.click(buttonSubmit);

await waitFor(() => {
expect(
screen.getByText(
'Your request to create a mailbox cannot be completed due to incorrect settings on our server. ' +
'Please contact our support team to resolve the problem: [email protected]',
),
).toBeInTheDocument();
});

expect(inputFirstName).toHaveFocus();
});

it('displays unhandled error cause', async () => {
fetchMock.mock(`end:mail-domains/${mockMailDomain.slug}/mailboxes/`, {
status: 400,
body: {
secret:
'Permission denied. Please check your MAIL_PROVISIONING_API_CREDENTIALS.',
},
});

const user = userEvent.setup();

renderModalCreateMailbox();

const {
inputFirstName,
inputLastName,
inputLocalPart,
inputEmailAddress,
buttonSubmit,
} = getFormElements();

await user.type(inputFirstName, 'John');
await user.type(inputLastName, 'Doe');
await user.type(inputLocalPart, 'john.doe');
await user.type(inputEmailAddress, '[email protected]');

await user.click(buttonSubmit);

await waitFor(() => {
expect(
screen.getByText(
'Permission denied. Please check your MAIL_PROVISIONING_API_CREDENTIALS.',
),
).toBeInTheDocument();
});

expect(buttonSubmit).toHaveFocus();
});

it('displays right error message when DImail api token is missing', async () => {
fetchMock.mock(`end:mail-domains/${mockMailDomain.slug}/mailboxes/`, {
status: 400,
body: {
secret:
'Please configure MAIL_PROVISIONING_API_CREDENTIALS before creating any mailbox.',
},
});

const user = userEvent.setup();

renderModalCreateMailbox();

const {
inputFirstName,
inputLastName,
inputLocalPart,
inputEmailAddress,
buttonSubmit,
} = getFormElements();

await user.type(inputFirstName, 'John');
await user.type(inputLastName, 'Doe');
await user.type(inputLocalPart, 'john.doe');
await user.type(inputEmailAddress, '[email protected]');

await user.click(buttonSubmit);

await waitFor(() => {
expect(
screen.getByText(
'Your request to create a mailbox cannot be completed due to incorrect settings on our server. ' +
'Please contact our support team to resolve the problem: [email protected]',
),
).toBeInTheDocument();
});

expect(inputFirstName).toHaveFocus();
});

it('displays right error message error when error 500 is received', async () => {
fetchMock.mock(`end:mail-domains/${mockMailDomain.slug}/mailboxes/`, {
status: 500,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/apps/desk/src/i18n/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
"Teams": "Équipes",
"The National Agency for Territorial Cohesion undertakes to make its\n service accessible, in accordance with article 47 of law no. 2005-102\n of February 11, 2005.": "L'Agence Nationale de la Cohésion des Territoires s’engage à rendre son service accessible, conformément à l’article 47 de la loi n° 2005-102 du 11 février 2005.",
"The domain name encounters an error. Please contact our support team to solve the problem:": "Le nom de domaine rencontre une erreur. Veuillez contacter notre support pour résoudre le problème :",
"The mail domain secret is misconfigured. Please, contact our support team to solve the issue: [email protected]": "Le secret du domaine de messagerie est mal configurĂ©. Veuillez contacter notre support pour rĂ©soudre le problème : [email protected]",
"The member has been removed from the team": "Le membre a été supprimé de votre groupe",
"The role has been updated": "Le rôle a bien été mis à jour",
"The team has been removed.": "Le groupe a été supprimé.",
Expand Down Expand Up @@ -168,6 +167,7 @@
"You must have minimum 1 character": "Vous devez entrer au moins 1 caractère",
"Your domain name is being validated. You will not be able to create mailboxes until your domain name has been validated by our team.": "Votre nom de domaine est en cours de validation. Vous ne pourrez créer de boîtes mail que lorsque votre nom de domaine sera validé par notre équipe.",
"Your request cannot be processed because the server is experiencing an error. If the problem persists, please contact our support to resolve the issue: [email protected]": "Votre demande ne peut pas ĂŞtre traitĂ©e car le serveur rencontre une erreur. Si le problème persiste, veuillez contacter notre support pour rĂ©soudre le problème : [email protected]",
"Your request to create a mailbox cannot be completed due to incorrect settings on our server. Please contact our support team to resolve the problem: [email protected]": "Votre demande de crĂ©ation de boĂ®te mail ne peut pas ĂŞtre complĂ©tĂ©e en raison de paramètres incorrects sur notre serveur. Veuillez contacter notre Ă©quipe support pour rĂ©soudre le problème : [email protected]",
"[disabled]": "[désactivé]",
"[enabled]": "[actif]",
"[failed]": "[erroné]",
Expand Down

0 comments on commit ca192c9

Please sign in to comment.