From a7ceca920b2392001020760e46472ffbaa3ac2be Mon Sep 17 00:00:00 2001 From: AndreiaPena Date: Fri, 6 Dec 2024 19:06:20 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A5=20admin:=20remove=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/app/adapters/session.js | 5 +- .../sessions/session-informations.gjs | 11 --- .../sessions/session/informations.js | 5 -- admin/app/models/session.js | 5 -- .../sessions/session/informations.scss | 4 -- .../sessions/session/informations.hbs | 1 - admin/mirage/config.js | 6 -- .../flag-results-sent-to-prescriptor-test.js | 69 ------------------- admin/tests/acceptance/session-test.js | 1 - .../sessions/session-id/informations-test.gjs | 30 -------- admin/tests/unit/models/session-test.js | 28 -------- 11 files changed, 1 insertion(+), 164 deletions(-) delete mode 100644 admin/tests/acceptance/flag-results-sent-to-prescriptor-test.js diff --git a/admin/app/adapters/session.js b/admin/app/adapters/session.js index 9430e08dcec..301b4bd6d3b 100644 --- a/admin/app/adapters/session.js +++ b/admin/app/adapters/session.js @@ -31,10 +31,7 @@ export default class SessionAdapter extends ApplicationAdapter { } updateRecord(store, type, snapshot) { - if (snapshot.adapterOptions.flagResultsAsSentToPrescriber) { - const url = this.urlForUpdateRecord(snapshot.id, type.modelName, snapshot) + '/results-sent-to-prescriber'; - return this.ajax(url, 'PUT'); - } else if (snapshot.adapterOptions.updatePublishedCertifications) { + if (snapshot.adapterOptions.updatePublishedCertifications) { let url; if (snapshot.adapterOptions.toPublish) { url = this.urlForUpdateRecord(snapshot.id, type.modelName, snapshot) + '/publish'; diff --git a/admin/app/components/sessions/session-informations.gjs b/admin/app/components/sessions/session-informations.gjs index 9439d479e4f..724844d8b42 100644 --- a/admin/app/components/sessions/session-informations.gjs +++ b/admin/app/components/sessions/session-informations.gjs @@ -190,17 +190,6 @@ function getFormattedDate(param) { > Télécharger les attestations - - {{#if @sessionModel.areResultsToBeSentToPrescriber}} - - Résultats transmis au prescripteur - - {{/if}} {{/if}} diff --git a/admin/app/controllers/authenticated/sessions/session/informations.js b/admin/app/controllers/authenticated/sessions/session/informations.js index 1868bd80d02..82ff8056a2c 100644 --- a/admin/app/controllers/authenticated/sessions/session/informations.js +++ b/admin/app/controllers/authenticated/sessions/session/informations.js @@ -40,11 +40,6 @@ export default class IndexController extends Controller { return this.sessionModel.assignedCertificationOfficer.get('id') ? true : false; } - @action - async tagSessionAsSentToPrescriber() { - await this.sessionModel.save({ adapterOptions: { flagResultsAsSentToPrescriber: true } }); - } - @action async unfinalizeSession() { try { diff --git a/admin/app/models/session.js b/admin/app/models/session.js index f0228755b30..4afe137b1c0 100644 --- a/admin/app/models/session.js +++ b/admin/app/models/session.js @@ -117,11 +117,6 @@ export default class Session extends Model { ); } - @computed('resultsSentToPrescriberAt', 'isFinalized') - get areResultsToBeSentToPrescriber() { - return Boolean(this.isFinalized && !this.resultsSentToPrescriberAt); - } - @computed('status') get displayStatus() { return statusToDisplayName[this.status]; diff --git a/admin/app/styles/authenticated/sessions/session/informations.scss b/admin/app/styles/authenticated/sessions/session/informations.scss index 7eba83414cd..38d073b477a 100644 --- a/admin/app/styles/authenticated/sessions/session/informations.scss +++ b/admin/app/styles/authenticated/sessions/session/informations.scss @@ -72,10 +72,6 @@ margin: 0 10px; } - &__download-button:first-child { - margin-left: 0; - } - &__published-buttons { display: flex; flex-direction: row; diff --git a/admin/app/templates/authenticated/sessions/session/informations.hbs b/admin/app/templates/authenticated/sessions/session/informations.hbs index a94267ae74e..206ae66cb21 100644 --- a/admin/app/templates/authenticated/sessions/session/informations.hbs +++ b/admin/app/templates/authenticated/sessions/session/informations.hbs @@ -8,7 +8,6 @@ @copyButtonText={{this.copyButtonText}} @copyResultsDownloadLink={{this.copyResultsDownloadLink}} @downloadPDFAttestations={{this.downloadPDFAttestations}} - @tagSessionAsSentToPrescriber={{this.tagSessionAsSentToPrescriber}} @modalTitle={{this.modalTitle}} @modalMessage={{this.modalMessage}} @modalConfirmAction={{this.modalConfirmAction}} diff --git a/admin/mirage/config.js b/admin/mirage/config.js index 952eecdb450..e21c3b52a67 100644 --- a/admin/mirage/config.js +++ b/admin/mirage/config.js @@ -119,12 +119,6 @@ function routes() { }); this.get('/admin/sessions/:id'); this.get('/admin/sessions/:id/jury-certification-summaries', getPaginatedJuryCertificationSummariesBySessionId); - this.put('/admin/sessions/:id/results-sent-to-prescriber', (schema, request) => { - const sessionId = request.params.id; - const session = schema.sessions.findBy({ id: sessionId }); - session.update({ resultsSentToPrescriberAt: new Date() }); - return session; - }); this.post('/admin/sessions/publish-in-batch', () => { return new Response(200); }); diff --git a/admin/tests/acceptance/flag-results-sent-to-prescriptor-test.js b/admin/tests/acceptance/flag-results-sent-to-prescriptor-test.js deleted file mode 100644 index d5cd5932336..00000000000 --- a/admin/tests/acceptance/flag-results-sent-to-prescriptor-test.js +++ /dev/null @@ -1,69 +0,0 @@ -import { clickByName, visit } from '@1024pix/ember-testing-library'; -import { currentURL } from '@ember/test-helpers'; -import { setupMirage } from 'ember-cli-mirage/test-support'; -import { setupApplicationTest } from 'ember-qunit'; -import { FINALIZED } from 'pix-admin/models/session'; -import { authenticateAdminMemberWithRole } from 'pix-admin/tests/helpers/test-init'; -import { module, test } from 'qunit'; - -module('Acceptance | Session page', function (hooks) { - setupApplicationTest(hooks); - setupMirage(hooks); - - hooks.beforeEach(async function () { - await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server); - }); - - module('Access', function () { - test('Session page should be accessible from /certification/sessions', async function (assert) { - // when - await visitSessionsPage(); - - // then - assert.strictEqual(currentURL(), '/sessions/list/with-required-action'); - }); - }); - - module('Rendering', function (hooks) { - hooks.beforeEach(async function () { - await visitSessionsPage(); - }); - - test('Should not have a "Date de finalisation" section', async function (assert) { - const session = this.server.create('session'); - - // when - const screen = await visit(`/sessions/${session.id}`); - - assert.dom(screen.getByText('Centre :')).exists(); - assert.dom(screen.queryByText('Date de finalisation :')).doesNotExist(); - }); - - test('Should have "Date de finalisation" section', async function (assert) { - const finalizedDate = new Date('2019-03-10T01:03:04Z'); - const session = this.server.create('session', { status: FINALIZED, finalizedAt: finalizedDate }); - - // when - const screen = await visit(`/sessions/${session.id}`); - - assert.dom(screen.getByText('Date de finalisation :')).exists(); - assert.dom(screen.getByText('10/03/2019')).exists(); - }); - - test('Should remove "Résultats transmis au prescripteur" button', async function (assert) { - const session = this.server.create('session', { - status: FINALIZED, - finalizedAt: new Date('2019-03-10T01:03:04Z'), - }); - // when - const screen = await visit(`/sessions/${session.id}`); - await clickByName('Résultats transmis au prescripteur'); - - assert.dom(screen.queryByRole('button', { name: 'Résultats transmis au prescripteur' })).doesNotExist(); - }); - }); - - async function visitSessionsPage() { - return visit('/sessions'); - } -}); diff --git a/admin/tests/acceptance/session-test.js b/admin/tests/acceptance/session-test.js index ef7a56ac38c..46f9938b0b6 100644 --- a/admin/tests/acceptance/session-test.js +++ b/admin/tests/acceptance/session-test.js @@ -157,7 +157,6 @@ module('Acceptance | Session pages', function (hooks) { // then assert.dom(screen.getByText("M'assigner la session")).exists(); assert.dom(screen.getByText('Lien de téléchargement des résultats')).exists(); - assert.dom(screen.getByText('Résultats transmis au prescripteur')).exists(); }); module('copy link button', function () { diff --git a/admin/tests/integration/components/routes/authenticated/sessions/session-id/informations-test.gjs b/admin/tests/integration/components/routes/authenticated/sessions/session-id/informations-test.gjs index 32eccb2a530..4057d7b4d3a 100644 --- a/admin/tests/integration/components/routes/authenticated/sessions/session-id/informations-test.gjs +++ b/admin/tests/integration/components/routes/authenticated/sessions/session-id/informations-test.gjs @@ -145,34 +145,6 @@ module('Integration | Component | routes/authenticated/sessions/session | inform assert.dom(screen.queryByText('Commentaire global :')).doesNotExist(); }); - module('when results have not yet been sent to prescriber', function () { - test('it should display the button to flag results as sent', async function (assert) { - // given - await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server); - const session = _buildSessionWithTwoJuryCertificationSummary({ resultsSentToPrescriberAt: null }, server); - - // when - const screen = await visit(`/sessions/${session.id}`); - - // then - assert.dom(screen.getByRole('button', { name: 'Résultats transmis au prescripteur' })).exists(); - }); - }); - - module('when results have been sent to prescriber', function () { - test('it should not display the button to flag results as sent', async function (assert) { - // given - await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server); - const session = _buildSessionWithTwoJuryCertificationSummary({ resultsSentToPrescriberAt: new Date() }, server); - - // when - const screen = await visit(`/sessions/${session.id}`); - - // then - assert.dom(screen.queryByRole('button', { name: 'Résultats transmis au prescripteur' })).doesNotExist(); - }); - }); - module('when the session results have been sent to the prescriber', function () { test('it renders the resultsSentToPrescriberAt date', async function (assert) { // given @@ -218,7 +190,6 @@ module('Integration | Component | routes/authenticated/sessions/session | inform assert.dom(screen.queryByText("M'assigner la session")).doesNotExist(); assert.dom(screen.queryByText('Définaliser la session')).doesNotExist(); assert.dom(screen.queryByText('Lien de téléchargement des résultats')).doesNotExist(); - assert.dom(screen.queryByText('Résultats transmis au prescripteur')).doesNotExist(); }); }); }); @@ -236,7 +207,6 @@ module('Integration | Component | routes/authenticated/sessions/session | inform assert.dom(screen.getByRole('button', { name: "M'assigner la session" })).exists(); assert.dom(screen.getByRole('button', { name: 'Définaliser la session' })).exists(); assert.dom(screen.getByRole('button', { name: 'Lien de téléchargement des résultats' })).exists(); - assert.dom(screen.getByRole('button', { name: 'Résultats transmis au prescripteur' })).exists(); }); }); }); diff --git a/admin/tests/unit/models/session-test.js b/admin/tests/unit/models/session-test.js index 9d313963dda..fedb5265c27 100644 --- a/admin/tests/unit/models/session-test.js +++ b/admin/tests/unit/models/session-test.js @@ -324,34 +324,6 @@ module('Unit | Model | session', function (hooks) { }); }); - module('#areResultsToBeSentToPrescriber', function () { - module('when session is finalized but results were not sent to prescriber yet', function () { - test('it should return areResultsToBeSentToPrescriber with true value', function (assert) { - // given - const session = store.createRecord('session', { status: 'finalized', resultsSentToPrescriberAt: null }); - - // when - const areResultsToBeSentToPrescriber = session.areResultsToBeSentToPrescriber; - - // then - assert.true(areResultsToBeSentToPrescriber); - }); - }); - - module('when session is finalized and results has been sent to prescriber', function () { - test('it should return areResultsToBeSentToPrescriber with false value', function (assert) { - // given - const session = store.createRecord('session', { status: 'finalized', resultsSentToPrescriberAt: new Date() }); - - // when - const areResultsToBeSentToPrescriber = session.areResultsToBeSentToPrescriber; - - // then - assert.false(areResultsToBeSentToPrescriber); - }); - }); - }); - module('#displayStatus', function () { module('when status is created', function () { test('it should display created printable equivalent', function (assert) { From f65bbfdec9f2d30ef04448e189e7c140561231f6 Mon Sep 17 00:00:00 2001 From: AndreiaPena Date: Fri, 6 Dec 2024 19:18:14 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A5=20api:=20remove=20results-sent?= =?UTF-8?q?-to-prescriber=20PUT=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/lib/application/sessions/index.js | 30 ---- .../sessions/session-controller.js | 8 - ...g-session-results-as-sent-to-prescriber.js | 24 --- .../domain/models/SessionManagement.js | 6 - ...ler-put-results-sent-to-prescriber_test.js | 140 ------------------ .../domain/models/SessionManagement_test.js | 28 ---- .../unit/application/session/index_test.js | 41 ----- .../session/session-controller_test.js | 63 -------- ...sion-results-as-sent-to-prescriber_test.js | 86 ----------- 9 files changed, 426 deletions(-) delete mode 100644 api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js delete mode 100644 api/tests/acceptance/application/session/session-controller-put-results-sent-to-prescriber_test.js delete mode 100644 api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js diff --git a/api/lib/application/sessions/index.js b/api/lib/application/sessions/index.js index 8374d48b3fa..c8e1e49d8c4 100644 --- a/api/lib/application/sessions/index.js +++ b/api/lib/application/sessions/index.js @@ -97,36 +97,6 @@ const register = async function (server) { tags: ['api', 'session', 'publication'], }, }, - { - method: 'PUT', - path: '/api/admin/sessions/{id}/results-sent-to-prescriber', - config: { - validate: { - params: Joi.object({ - id: identifiersType.sessionId, - }), - }, - pre: [ - { - method: (request, h) => - securityPreHandlers.hasAtLeastOneAccessOf([ - securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, - securityPreHandlers.checkAdminMemberHasRoleCertif, - securityPreHandlers.checkAdminMemberHasRoleSupport, - ])(request, h), - assign: 'hasAuthorizationToAccessAdminScope', - }, - ], - - handler: sessionController.flagResultsAsSentToPrescriber, - tags: ['api', 'sessions'], - notes: [ - "- **Cette route est restreinte aux utilisateurs authentifiés ayant les droits d'accès**\n" + - '- Elle permet de marquer le fait que les résultats de la session ont été envoyés au prescripteur,\n', - '- par le biais de la sauvegarde de la date courante.', - ], - }, - }, ]); }; diff --git a/api/lib/application/sessions/session-controller.js b/api/lib/application/sessions/session-controller.js index 85ba2847028..80566a88604 100644 --- a/api/lib/application/sessions/session-controller.js +++ b/api/lib/application/sessions/session-controller.js @@ -47,18 +47,10 @@ const unpublish = async function (request, h, dependencies = { sessionManagement return dependencies.sessionManagementSerializer.serialize({ session }); }; -const flagResultsAsSentToPrescriber = async function (request, h, dependencies = { sessionManagementSerializer }) { - const sessionId = request.params.id; - const { resultsFlaggedAsSent, session } = await usecases.flagSessionResultsAsSentToPrescriber({ sessionId }); - const serializedSession = await dependencies.sessionManagementSerializer.serialize({ session }); - return resultsFlaggedAsSent ? h.response(serializedSession).created() : serializedSession; -}; - const sessionController = { getJuryCertificationSummaries, publishInBatch, unpublish, - flagResultsAsSentToPrescriber, }; export { sessionController }; diff --git a/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js b/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js deleted file mode 100644 index f0fcec97f53..00000000000 --- a/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js +++ /dev/null @@ -1,24 +0,0 @@ -import { NotFoundError } from '../../../src/shared/domain/errors.js'; - -const flagSessionResultsAsSentToPrescriber = async function ({ sessionId, sessionRepository }) { - const integerSessionId = parseInt(sessionId); - const NOT_FOUND_SESSION = `La session ${sessionId} n'existe pas ou son accès est restreint lors du marquage d'envoi des résultats au prescripteur`; - - if (!Number.isFinite(integerSessionId)) { - throw new NotFoundError(NOT_FOUND_SESSION); - } - - let session = await sessionRepository.get({ id: sessionId }); - - if (!session.areResultsFlaggedAsSent()) { - session = await sessionRepository.flagResultsAsSentToPrescriber({ - id: sessionId, - resultsSentToPrescriberAt: new Date(), - }); - return { resultsFlaggedAsSent: true, session }; - } - - return { resultsFlaggedAsSent: false, session }; -}; - -export { flagSessionResultsAsSentToPrescriber }; diff --git a/api/src/certification/session-management/domain/models/SessionManagement.js b/api/src/certification/session-management/domain/models/SessionManagement.js index 4430421c1db..a6f2d191513 100644 --- a/api/src/certification/session-management/domain/models/SessionManagement.js +++ b/api/src/certification/session-management/domain/models/SessionManagement.js @@ -1,5 +1,3 @@ -import _ from 'lodash'; - import { SESSION_STATUSES } from '../../../shared/domain/constants.js'; import { SESSIONS_VERSIONS } from '../../../shared/domain/models/SessionVersion.js'; @@ -52,10 +50,6 @@ class SessionManagement { this.createdBy = createdBy; } - areResultsFlaggedAsSent() { - return !_.isNil(this.resultsSentToPrescriberAt); - } - get status() { if (this.publishedAt) { return SESSION_STATUSES.PROCESSED; diff --git a/api/tests/acceptance/application/session/session-controller-put-results-sent-to-prescriber_test.js b/api/tests/acceptance/application/session/session-controller-put-results-sent-to-prescriber_test.js deleted file mode 100644 index 1763e88eb1f..00000000000 --- a/api/tests/acceptance/application/session/session-controller-put-results-sent-to-prescriber_test.js +++ /dev/null @@ -1,140 +0,0 @@ -import { - createServer, - databaseBuilder, - expect, - generateValidRequestAuthorizationHeader, -} from '../../../test-helper.js'; - -describe('PUT /api/admin/sessions/:id/results-sent-to-prescriber', function () { - let server; - const options = { method: 'PUT' }; - let userId; - - beforeEach(async function () { - server = await createServer(); - }); - - context('when user does not have the role Super Admin', function () { - beforeEach(function () { - userId = databaseBuilder.factory.buildUser().id; - return databaseBuilder.commit(); - }); - - it('should return a 403 error code', async function () { - // given - options.url = '/api/admin/sessions/12/results-sent-to-prescriber'; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; - - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(403); - }); - }); - - context('when user has role Super Admin', function () { - beforeEach(function () { - // given - userId = databaseBuilder.factory.buildUser.withRole().id; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; - return databaseBuilder.commit(); - }); - - context('when the session id has an invalid format', function () { - it('should return a 400 error code', async function () { - // given - options.url = '/api/admin/sessions/any/results-sent-to-prescriber'; - - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(400); - }); - }); - - context('when the session id is a number', function () { - context('when the session does not exist', function () { - it('should return a 404 error code', async function () { - // given - options.url = '/api/admin/sessions/1/results-sent-to-prescriber'; - - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(404); - }); - }); - - context('when the session exists', function () { - let sessionId; - - context('when the session results were already flagged as sent to prescriber', function () { - const date = new Date(); - - beforeEach(function () { - // given - sessionId = databaseBuilder.factory.buildSession({ resultsSentToPrescriberAt: date }).id; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; - return databaseBuilder.commit(); - }); - - it('should return a 200 status code', async function () { - // given - options.url = `/api/admin/sessions/${sessionId}/results-sent-to-prescriber`; - - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(200); - }); - - it('should return the serialized session with an untouched resultsSentToPrescriberAt date', async function () { - // given - options.url = `/api/admin/sessions/${sessionId}/results-sent-to-prescriber`; - - // when - const response = await server.inject(options); - - // then - expect(response.result.data.attributes['results-sent-to-prescriber-at']).to.deep.equal(date); - }); - }); - - context('when the session results were not flagged as sent to prescriber', function () { - beforeEach(function () { - // given - sessionId = databaseBuilder.factory.buildSession({ resultsSentToPrescriberAt: null }).id; - options.headers = { authorization: generateValidRequestAuthorizationHeader(userId) }; - return databaseBuilder.commit(); - }); - - it('should return a 201 status code', async function () { - // given - options.url = `/api/admin/sessions/${sessionId}/results-sent-to-prescriber`; - - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(201); - }); - - it('should return the serialized session with a defined resultsSentToPrescriberAt date', async function () { - // given - options.url = `/api/admin/sessions/${sessionId}/results-sent-to-prescriber`; - - // when - const response = await server.inject(options); - - // then - expect(response.result.data.attributes['results-sent-to-prescriber-at']).to.be.an.instanceOf(Date); - }); - }); - }); - }); - }); -}); diff --git a/api/tests/certification/session-management/unit/domain/models/SessionManagement_test.js b/api/tests/certification/session-management/unit/domain/models/SessionManagement_test.js index 22b9f906553..a425dbde310 100644 --- a/api/tests/certification/session-management/unit/domain/models/SessionManagement_test.js +++ b/api/tests/certification/session-management/unit/domain/models/SessionManagement_test.js @@ -65,34 +65,6 @@ describe('Unit | Certification | Session | Domain | Models | SessionManagement', expect(_.keys(session)).to.have.deep.members(SESSION_PROPS); }); - context('#areResultsFlaggedAsSent', function () { - context('when session resultsSentToPrescriberAt timestamp is defined', function () { - it('should return true', function () { - // given - session.resultsSentToPrescriberAt = new Date(); - - // when - const areResultsFlaggedAsSent = session.areResultsFlaggedAsSent(); - - // then - expect(areResultsFlaggedAsSent).to.be.true; - }); - }); - - context('when session resultsSentToPrescriberAt timestamp is falsy', function () { - it('should return false', function () { - // given - session.resultsSentToPrescriberAt = null; - - // when - const areResultsFlaggedAsSent = session.areResultsFlaggedAsSent(); - - // then - expect(areResultsFlaggedAsSent).to.be.false; - }); - }); - }); - context('#get status', function () { context('when session publishedAt timestamp is defined', function () { it('should return PROCESSED', function () { diff --git a/api/tests/unit/application/session/index_test.js b/api/tests/unit/application/session/index_test.js index f8ee81dc183..f63df1b9b1d 100644 --- a/api/tests/unit/application/session/index_test.js +++ b/api/tests/unit/application/session/index_test.js @@ -163,47 +163,6 @@ describe('Unit | Application | Sessions | Routes', function () { expect(response.statusCode).to.equal(400); }); }); - - describe('PUT /api/admin/sessions/{id}/results-sent-to-prescriber', function () { - it('should exist', async function () { - // when - sinon.stub(securityPreHandlers, 'hasAtLeastOneAccessOf').returns(() => true); - sinon.stub(sessionController, 'flagResultsAsSentToPrescriber').returns('ok'); - const httpTestServer = new HttpTestServer(); - await httpTestServer.register(moduleUnderTest); - - const response = await httpTestServer.request('PUT', '/api/admin/sessions/3/results-sent-to-prescriber'); - - // then - expect(response.statusCode).to.equal(200); - }); - - it('return forbidden access if user has METIER role', async function () { - // given - sinon - .stub(securityPreHandlers, 'hasAtLeastOneAccessOf') - .withArgs([ - securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, - securityPreHandlers.checkAdminMemberHasRoleCertif, - securityPreHandlers.checkAdminMemberHasRoleSupport, - ]) - .callsFake( - () => (request, h) => - h - .response({ errors: new Error('forbidden') }) - .code(403) - .takeover(), - ); - const httpTestServer = new HttpTestServer(); - await httpTestServer.register(moduleUnderTest); - - // when - const response = await httpTestServer.request('PUT', '/api/admin/sessions/1/results-sent-to-prescriber'); - - // then - expect(response.statusCode).to.equal(403); - }); - }); }); describe('DELETE /api/sessions/{id}', function () { diff --git a/api/tests/unit/application/session/session-controller_test.js b/api/tests/unit/application/session/session-controller_test.js index bef315beca3..67f563603fd 100644 --- a/api/tests/unit/application/session/session-controller_test.js +++ b/api/tests/unit/application/session/session-controller_test.js @@ -7,7 +7,6 @@ import { logger } from '../../../../src/shared/infrastructure/utils/logger.js'; import { catchErr, expect, hFake, sinon } from '../../../test-helper.js'; describe('Unit | Controller | sessionController', function () { - let request; const userId = 274939274; describe('#getJuryCertificationSummaries ', function () { @@ -190,66 +189,4 @@ describe('Unit | Controller | sessionController', function () { expect(error).to.be.an.instanceof(SessionPublicationBatchError); }); }); - - describe('#flagResultsAsSentToPrescriber', function () { - let sessionId; - let session; - let serializedSession; - - beforeEach(function () { - sessionId = 123; - session = Symbol('session'); - serializedSession = Symbol('serializedSession'); - request = { - params: { - id: sessionId, - }, - }; - }); - - context('when the session results were already flagged as sent', function () { - beforeEach(function () { - const usecaseResult = { resultsFlaggedAsSent: false, session }; - sinon.stub(usecases, 'flagSessionResultsAsSentToPrescriber').withArgs({ sessionId }).resolves(usecaseResult); - }); - - it('should return the serialized session', async function () { - // given - const sessionManagementSerializer = { - serialize: sinon.stub(), - }; - sessionManagementSerializer.serialize.withArgs({ session }).resolves(serializedSession); - - // when - const response = await sessionController.flagResultsAsSentToPrescriber(request, hFake, { - sessionManagementSerializer, - }); - - // then - expect(response).to.equal(serializedSession); - }); - }); - - context('when the session results were not flagged as sent', function () { - beforeEach(function () { - const usecaseResult = { resultsFlaggedAsSent: true, session }; - sinon.stub(usecases, 'flagSessionResultsAsSentToPrescriber').withArgs({ sessionId }).resolves(usecaseResult); - }); - - it('should return the serialized session with code 201', async function () { - // given - const sessionManagementSerializer = { serialize: sinon.stub() }; - sessionManagementSerializer.serialize.withArgs({ session }).resolves(serializedSession); - - // when - const response = await sessionController.flagResultsAsSentToPrescriber(request, hFake, { - sessionManagementSerializer, - }); - - // then - expect(response.statusCode).to.equal(201); - expect(response.source).to.equal(serializedSession); - }); - }); - }); }); diff --git a/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js b/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js deleted file mode 100644 index cef89f61fb9..00000000000 --- a/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js +++ /dev/null @@ -1,86 +0,0 @@ -import { flagSessionResultsAsSentToPrescriber } from '../../../../lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js'; -import { SessionManagement } from '../../../../src/certification/session-management/domain/models/SessionManagement.js'; -import { NotFoundError } from '../../../../src/shared/domain/errors.js'; -import { catchErr, expect, sinon } from '../../../test-helper.js'; - -describe('Unit | UseCase | flag-session-results-as-sent-to-prescriber', function () { - let sessionId; - let sessionRepository; - - beforeEach(function () { - sessionRepository = { flagResultsAsSentToPrescriber: sinon.stub(), get: sinon.stub() }; - }); - - context('when session id is not a number', function () { - it('should throw a NotFound error', async function () { - // given - sessionId = 'notANumber'; - - // when - const error = await catchErr(flagSessionResultsAsSentToPrescriber)({ sessionId, sessionRepository }); - - // then - expect(error).to.be.an.instanceOf(NotFoundError); - }); - }); - - context('when session id is a number', function () { - beforeEach(function () { - sessionId = 1; - }); - - context('when results are already flagged as sent', function () { - const alreadyFlaggedResultsAsSentSession = new SessionManagement({ resultsSentToPrescriberAt: new Date() }); - - it('should return a NON updated session with a flag to indicate that results has already been sent', async function () { - // given - sessionRepository.get.withArgs({ id: sessionId }).resolves(alreadyFlaggedResultsAsSentSession); - - // when - const { resultsFlaggedAsSent, session } = await flagSessionResultsAsSentToPrescriber({ - sessionId, - sessionRepository, - }); - - // then - expect(resultsFlaggedAsSent).to.be.false; - expect(session).to.equal(alreadyFlaggedResultsAsSentSession); - }); - }); - - context('when results are not flagged as sent yet', function () { - let notFlaggedSession, updatedSession; - const now = new Date('2019-01-01T05:06:07Z'); - let clock; - - beforeEach(function () { - updatedSession = Symbol('updatedSession'); - clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); - - notFlaggedSession = new SessionManagement({ resultsSentToPrescriberAt: null }); - sessionRepository.get.withArgs({ id: sessionId }).resolves(notFlaggedSession); - }); - - afterEach(function () { - clock.restore(); - }); - - it('should return an updated session with a flag to indicate that the flagging has been done', async function () { - // given - sessionRepository.flagResultsAsSentToPrescriber - .withArgs({ id: sessionId, resultsSentToPrescriberAt: now }) - .resolves(updatedSession); - - // when - const { resultsFlaggedAsSent, session } = await flagSessionResultsAsSentToPrescriber({ - sessionId, - sessionRepository, - }); - - // then - expect(resultsFlaggedAsSent).to.be.true; - expect(session).to.equal(updatedSession); - }); - }); - }); -});