-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Permettre la modification d'import à format via PixAdmin (P…
- Loading branch information
Showing
30 changed files
with
559 additions
and
163 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import UpdateOrganizationImportFormat from './update-organization-import-format'; | ||
|
||
<template><UpdateOrganizationImportFormat /></template> |
57 changes: 57 additions & 0 deletions
57
admin/app/components/administration/organizations/update-organization-import-format.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import PixButtonUpload from '@1024pix/pix-ui/components/pix-button-upload'; | ||
import { action } from '@ember/object'; | ||
import { service } from '@ember/service'; | ||
import Component from '@glimmer/component'; | ||
import { t } from 'ember-intl'; | ||
|
||
import AdministrationBlockLayout from '../block-layout'; | ||
|
||
export default class UpdateOrganizationImportFormat extends Component { | ||
@service intl; | ||
@service notifications; | ||
@service router; | ||
@service store; | ||
|
||
@action | ||
async uploadOrganizationImportFile(files) { | ||
this.notifications.clearAll(); | ||
const adapter = this.store.adapterFor('import-files'); | ||
try { | ||
await adapter.updateOrganizationImportFormat(files); | ||
this.notifications.success( | ||
this.intl.t('components.administration.organization-import-format.notifications.success'), | ||
); | ||
} catch (errorResponse) { | ||
const errors = errorResponse.errors; | ||
if (!errors) { | ||
return this.notifications.error(this.intl.t('common.notifications.generic-error')); | ||
} | ||
|
||
errors.forEach((error) => { | ||
switch (error.code) { | ||
case 'MISSING_REQUIRED_FIELD_NAMES': | ||
this.notifications.error(`${error.meta}`, { autoClear: false }); | ||
break; | ||
default: | ||
this.notifications.error(error.detail, { autoClear: false }); | ||
} | ||
}); | ||
} finally { | ||
this.isLoading = false; | ||
} | ||
} | ||
<template> | ||
<AdministrationBlockLayout | ||
@title={{t "components.administration.organization-import-format.title"}} | ||
@description={{t "components.administration.organization-import-format.description"}} | ||
> | ||
<PixButtonUpload | ||
@id="organization-import-file-upload" | ||
@onChange={{this.uploadOrganizationImportFile}} | ||
accept=".json" | ||
> | ||
{{t "components.administration.organization-import-format.upload-button"}} | ||
</PixButtonUpload> | ||
</AdministrationBlockLayout> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
admin/app/templates/authenticated/administration/organizations.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<Administration::Organizations /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...ration/components/administration/organizations/update-organization-import-format-test.gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { render } from '@1024pix/ember-testing-library'; | ||
import Service from '@ember/service'; | ||
import { triggerEvent } from '@ember/test-helpers'; | ||
import { setupMirage } from 'ember-cli-mirage/test-support'; | ||
import { t } from 'ember-intl/test-support'; | ||
import UpdateOrganizationImportFormat from 'pix-admin/components/administration/organizations/update-organization-import-format'; | ||
import { module, test } from 'qunit'; | ||
import sinon from 'sinon'; | ||
|
||
import setupIntlRenderingTest from '../../../../helpers/setup-intl-rendering'; | ||
|
||
module('Integration | Component | administration/update-organization-import-format', function (hooks) { | ||
setupIntlRenderingTest(hooks); | ||
setupMirage(hooks); | ||
|
||
let store, adapter, notificationSuccessStub, clearAllStub, saveAdapterStub, notificationErrorStub; | ||
hooks.beforeEach(function () { | ||
store = this.owner.lookup('service:store'); | ||
adapter = store.adapterFor('import-files'); | ||
saveAdapterStub = sinon.stub(adapter, 'updateOrganizationImportFormat'); | ||
notificationSuccessStub = sinon.stub(); | ||
notificationErrorStub = sinon.stub().returns(); | ||
|
||
clearAllStub = sinon.stub(); | ||
}); | ||
|
||
module('when import succeeds', function () { | ||
test('it displays a success notification', async function (assert) { | ||
// given | ||
const files = Symbol('file'); | ||
class NotificationsStub extends Service { | ||
success = notificationSuccessStub; | ||
error = notificationErrorStub; | ||
clearAll = clearAllStub; | ||
} | ||
this.owner.register('service:notifications', NotificationsStub); | ||
saveAdapterStub.withArgs([files]).resolves(); | ||
|
||
// when | ||
const screen = await render(<template><UpdateOrganizationImportFormat /></template>); | ||
const input = await screen.findByLabelText( | ||
t('components.administration.organization-import-format.upload-button'), | ||
); | ||
await triggerEvent(input, 'change', { files: [files] }); | ||
|
||
// then | ||
assert.ok(true); | ||
assert.ok(notificationErrorStub.notCalled); | ||
assert.ok( | ||
notificationSuccessStub.calledWith( | ||
t('components.administration.organization-import-format.notifications.success'), | ||
), | ||
); | ||
}); | ||
}); | ||
|
||
module('when import fails', function () { | ||
test('it displays a specific error notification on missing required field', async function (assert) { | ||
// given | ||
const files = Symbol('file'); | ||
class NotificationsStub extends Service { | ||
error = notificationErrorStub; | ||
success = notificationSuccessStub; | ||
clearAll = clearAllStub; | ||
} | ||
saveAdapterStub.withArgs([files]).rejects({ | ||
errors: [{ status: '422', meta: 'POUET', code: 'MISSING_REQUIRED_FIELD_NAMES' }], | ||
}); | ||
this.owner.register('service:notifications', NotificationsStub); | ||
|
||
// when | ||
const screen = await render(<template><UpdateOrganizationImportFormat /></template>); | ||
const input = await screen.findByLabelText( | ||
t('components.administration.organization-import-format.upload-button'), | ||
); | ||
await triggerEvent(input, 'change', { files: [files] }); | ||
|
||
// then | ||
assert.ok(notificationSuccessStub.notCalled); | ||
assert.ok(notificationErrorStub.calledWithExactly('POUET', { autoClear: false })); | ||
}); | ||
|
||
test('it displays an error notification', async function (assert) { | ||
// given | ||
const files = Symbol('file'); | ||
class NotificationsStub extends Service { | ||
error = notificationErrorStub; | ||
success = notificationSuccessStub; | ||
clearAll = clearAllStub; | ||
} | ||
saveAdapterStub.withArgs([files]).rejects({ | ||
errors: [{ status: '422', title: "Un soucis avec l'import", code: '422', detail: 'Erreur d’import' }], | ||
}); | ||
this.owner.register('service:notifications', NotificationsStub); | ||
|
||
// when | ||
const screen = await render(<template><UpdateOrganizationImportFormat /></template>); | ||
const input = await screen.findByLabelText( | ||
t('components.administration.organization-import-format.upload-button'), | ||
); | ||
await triggerEvent(input, 'change', { files: [files] }); | ||
|
||
// then | ||
assert.ok(notificationSuccessStub.notCalled); | ||
assert.ok(notificationErrorStub.called); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
api/scripts/organization-import-format/update-organization-import-format.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.