-
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.
[TECH] Export de la liste blanche SCO
- Loading branch information
Showing
25 changed files
with
590 additions
and
51 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
admin/app/styles/components/administration/certification/sco-whitelist-configuration.scss
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,8 @@ | ||
.sco-whitelist-configuration { | ||
&__actions { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--pix-spacing-6x); | ||
margin-top: var(--pix-spacing-6x); | ||
} | ||
} |
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
138 changes: 138 additions & 0 deletions
138
.../integration/components/administration/certification/sco-whitelist-configuration_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,138 @@ | ||
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'; | ||
import ScoWhitelistConfiguration from 'pix-admin/components/administration/certification/sco-whitelist-configuration'; | ||
import ENV from 'pix-admin/config/environment'; | ||
import { module, test } from 'qunit'; | ||
import sinon from 'sinon'; | ||
|
||
import setupIntlRenderingTest from '../../../../helpers/setup-intl-rendering'; | ||
|
||
const accessToken = 'An access token'; | ||
const fileContent = 'foo'; | ||
const file = new Blob([fileContent], { type: `valid-file` }); | ||
|
||
module('Integration | Component | administration/certification/sco-whitelist-configuration', function (hooks) { | ||
setupIntlRenderingTest(hooks); | ||
|
||
let fetchStub, fileSaverStub; | ||
|
||
hooks.beforeEach(function () { | ||
class SessionService extends Service { | ||
data = { authenticated: { access_token: accessToken } }; | ||
} | ||
this.owner.register('service:session', SessionService); | ||
|
||
class FileSaver extends Service { | ||
save = fileSaverStub; | ||
} | ||
|
||
this.owner.register('service:file-saver', FileSaver); | ||
|
||
fetchStub = sinon.stub(window, 'fetch'); | ||
fileSaverStub = sinon.stub(); | ||
}); | ||
|
||
hooks.afterEach(function () { | ||
window.fetch.restore(); | ||
}); | ||
|
||
module('Export', function () { | ||
module('when export succeeds', function () { | ||
test('it succeeds', async function (assert) { | ||
// given | ||
fileSaverStub.resolves(); | ||
// when | ||
const screen = await render(<template><ScoWhitelistConfiguration /><PixToastContainer /></template>); | ||
const input = await screen.findByText(t('pages.administration.certification.sco-whitelist.export.button')); | ||
await triggerEvent(input, 'click'); | ||
|
||
// then | ||
assert | ||
.dom(await screen.queryByText(t('pages.administration.certification.sco-whitelist.export.error'))) | ||
.doesNotExist(); | ||
}); | ||
}); | ||
|
||
module('when export fails', function () { | ||
test('it displays an error notification', async function (assert) { | ||
// given | ||
fileSaverStub.rejects(); | ||
// when | ||
const screen = await render(<template><ScoWhitelistConfiguration /><PixToastContainer /></template>); | ||
const input = await screen.findByText(t('pages.administration.certification.sco-whitelist.export.button')); | ||
await triggerEvent(input, 'click'); | ||
|
||
// then | ||
assert.dom(await screen.getByText(t('pages.administration.certification.sco-whitelist.export.error'))).exists(); | ||
}); | ||
}); | ||
}); | ||
|
||
module('Import', function () { | ||
module('when import succeeds', function (hooks) { | ||
hooks.beforeEach(function () { | ||
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({ status: 201 })); | ||
}); | ||
|
||
test('it displays a success notification', async function (assert) { | ||
// when | ||
const screen = await render(<template><ScoWhitelistConfiguration /><PixToastContainer /></template>); | ||
const input = await screen.getByLabelText(t('pages.administration.certification.sco-whitelist.import.button')); | ||
await triggerEvent(input, 'change', { files: [file] }); | ||
|
||
// then | ||
assert | ||
.dom(await screen.getByText(t('pages.administration.certification.sco-whitelist.import.success'))) | ||
.exists(); | ||
}); | ||
}); | ||
|
||
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] }); | ||
|
||
// then | ||
assert.dom(await screen.getByText(t('pages.administration.certification.sco-whitelist.import.error'))).exists(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function fetchResponse({ body, status }) { | ||
const mockResponse = new window.Response(JSON.stringify(body), { | ||
status, | ||
headers: { | ||
'Content-type': 'application/json', | ||
}, | ||
}); | ||
|
||
return mockResponse; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
api/src/certification/configuration/application/http-error-mapper-configuration.js
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,10 @@ | ||
import { HttpErrors } from '../../../shared/application/http-errors.js'; | ||
import { DomainErrorMappingConfiguration } from '../../../shared/application/models/domain-error-mapping-configuration.js'; | ||
import { InvalidScoWhitelistError } from '../domain/errors.js'; | ||
|
||
export const configurationDomainErrorMappingConfiguration = [ | ||
{ | ||
name: InvalidScoWhitelistError.name, | ||
httpErrorFn: (error) => new HttpErrors.UnprocessableEntityError(error.message, error.code, error.meta), | ||
}, | ||
].map((domainErrorMappingConfiguration) => new DomainErrorMappingConfiguration(domainErrorMappingConfiguration)); |
Oops, something went wrong.