Skip to content

Commit

Permalink
✨ admin: handle new error in pix-certif
Browse files Browse the repository at this point in the history
Co-authored-by: Steph0 <[email protected]>
  • Loading branch information
P-Jeremy and Steph0 authored Nov 27, 2024
1 parent 66f3ce0 commit 4f2b6f4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ export default class ScoWhitelistConfiguration extends Component {
message: this.intl.t('pages.administration.certification.sco-whitelist.import.success'),
});
} else {
const responseJson = await response.json();
const errorKey = responseJson?.errors[0]?.code || 'error';

this.pixToast.sendErrorNotification({
message: this.intl.t('pages.administration.certification.sco-whitelist.import.error'),
message: this.intl.t(`pages.administration.certification.sco-whitelist.import.${errorKey}`),
});
}
} catch (error) {
Expand All @@ -59,7 +62,7 @@ export default class ScoWhitelistConfiguration extends Component {
await this.fileSaver.save({ url, fileName, token });
} catch (error) {
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.administration.certification.sco-whitelist.export.error')
message: this.intl.t('pages.administration.certification.sco-whitelist.export.error'),
});
} finally {
this.isExportLoading = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,58 @@ module('Integration | Component | administration/certification/sco-whitelist-con
});

module('when import fails', function () {
test('it displays an error notification', async function (assert) {
// given
fetchStub
.withArgs(`${ENV.APP.API_HOST}/api/admin/sco-whitelist`, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'text/csv',
Accept: 'application/json',
},
method: 'POST',
body: file,
})
.rejects();
// when
const screen = await render(<template><ScoWhitelistConfiguration /><PixToastContainer /></template>);
const input = await screen.findByLabelText(t('pages.administration.certification.sco-whitelist.import.button'));
await triggerEvent(input, 'change', { files: [file] });
module('when it is a generic error', function () {
test('it displays an error notification', async function (assert) {
// given
fetchStub
.withArgs(`${ENV.APP.API_HOST}/api/admin/sco-whitelist`, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'text/csv',
Accept: 'application/json',
},
method: 'POST',
body: file,
})
.rejects();
// when
const screen = await render(<template><ScoWhitelistConfiguration /><PixToastContainer /></template>);
const input = await screen.findByLabelText(t('pages.administration.certification.sco-whitelist.import.button'));
await triggerEvent(input, 'change', { files: [file] });

// then
assert.ok(await screen.findByText(t('pages.administration.certification.sco-whitelist.import.error')));
// then
assert.ok(await screen.findByText(t('pages.administration.certification.sco-whitelist.import.error')));
});
});

module('when it is a CERTIFICATION_INVALID_SCO_WHITELIST_ERROR', function () {
test('it displays an error notification', async function (assert) {
// given
fetchStub
.withArgs(`${ENV.APP.API_HOST}/api/admin/sco-whitelist`, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'text/csv',
Accept: 'application/json',
},
method: 'POST',
body: file,
})
.resolves(
fetchResponse({ body: { errors: [{ code: 'CERTIFICATION_INVALID_SCO_WHITELIST_ERROR' }] }, status: 422 }),
);
// when
const screen = await render(<template><ScoWhitelistConfiguration /><PixToastContainer /></template>);
const input = await screen.findByLabelText(t('pages.administration.certification.sco-whitelist.import.button'));
await triggerEvent(input, 'change', { files: [file] });

// then
assert.ok(
await screen.findByText(
t('pages.administration.certification.sco-whitelist.import.CERTIFICATION_INVALID_SCO_WHITELIST_ERROR'),
),
);
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PixToastContainer from '@1024pix/pix-ui/components/pix-toast-container';
import { render } from '@1024pix/ember-testing-library';
import PixToastContainer from '@1024pix/pix-ui/components/pix-toast-container';
import Service from '@ember/service';
import { triggerEvent } from '@ember/test-helpers';
import { t } from 'ember-intl/test-support';
Expand Down
1 change: 1 addition & 0 deletions admin/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@
"error": "Could not download SCO whitelist."
},
"import": {
"CERTIFICATION_INVALID_SCO_WHITELIST_ERROR": "An error has occurred. Please verify externalIds in csv.",
"button": "Import file as whitelist (CSV)",
"error": "Could not save SCO whitelist",
"success": "SCO whitelist saved."
Expand Down
1 change: 1 addition & 0 deletions admin/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@
"error": "Échec de la récupération de la liste blanche."
},
"import": {
"CERTIFICATION_INVALID_SCO_WHITELIST_ERROR": "Une erreur est survenue. Veuillez vérifier les externalId renseignés.",
"button": "Importer une nouvelle liste blanche (format CSV)",
"error": "Échec de l'enregistrement de la liste blanche",
"success": "Liste blanche enregistrée."
Expand Down

0 comments on commit 4f2b6f4

Please sign in to comment.