From 7a3f2e2a3d1f986105c1a6e70b9629031156d3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannick=20Fran=C3=A7ois?= Date: Mon, 9 Dec 2024 14:26:48 +0100 Subject: [PATCH] :truck: refactor(api): move session summaries to `src` --- .../certification-center-controller.js | 15 ---- .../certification-centers/index.js | 23 ------ .../certification-center-controller_test.js | 73 ------------------- .../certification-centers/index_test.js | 18 +---- 4 files changed, 1 insertion(+), 128 deletions(-) diff --git a/api/lib/application/certification-centers/certification-center-controller.js b/api/lib/application/certification-centers/certification-center-controller.js index 4e861b5fcd1..761451af419 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -5,20 +5,6 @@ import { usecases } from '../../domain/usecases/index.js'; import * as sessionSummarySerializer from '../../infrastructure/serializers/jsonapi/session-summary-serializer.js'; import * as studentCertificationSerializer from '../../infrastructure/serializers/jsonapi/student-certification-serializer.js'; -const findPaginatedSessionSummaries = async function (request) { - const certificationCenterId = request.params.id; - const userId = request.auth.credentials.userId; - const options = request.query; - - const { models: sessionSummaries, meta } = await usecases.findPaginatedCertificationCenterSessionSummaries({ - userId, - certificationCenterId, - page: options.page, - }); - - return sessionSummarySerializer.serialize(sessionSummaries, meta); -}; - const getStudents = async function (request) { const certificationCenterId = request.params.certificationCenterId; const sessionId = request.params.sessionId; @@ -91,7 +77,6 @@ const updateReferer = async function (request, h) { const certificationCenterController = { createCertificationCenterMembershipByEmail, findCertificationCenterMembershipsByCertificationCenter, - findPaginatedSessionSummaries, getDivisions, getStudents, updateReferer, diff --git a/api/lib/application/certification-centers/index.js b/api/lib/application/certification-centers/index.js index dd61886e854..4a8f3546825 100644 --- a/api/lib/application/certification-centers/index.js +++ b/api/lib/application/certification-centers/index.js @@ -149,29 +149,6 @@ const register = async function (server) { tags: ['api', 'certification-center', 'students', 'session'], }, }, - { - method: 'GET', - path: '/api/certification-centers/{id}/session-summaries', - config: { - validate: { - params: Joi.object({ - id: identifiersType.certificationCenterId, - }), - query: Joi.object({ - page: Joi.object({ - number: Joi.number().integer().empty('').allow(null).optional(), - size: Joi.number().integer().empty('').allow(null).optional(), - }).default({}), - }), - }, - handler: certificationCenterController.findPaginatedSessionSummaries, - tags: ['api', 'certification-center'], - notes: [ - '- **Cette route est restreinte aux utilisateurs authentifiés**\n', - '- Elle retourne les sessions rattachées au centre de certification.', - ], - }, - }, ]); }; diff --git a/api/tests/unit/application/certification-centers/certification-center-controller_test.js b/api/tests/unit/application/certification-centers/certification-center-controller_test.js index 50972e57d3c..14ed71d70f2 100644 --- a/api/tests/unit/application/certification-centers/certification-center-controller_test.js +++ b/api/tests/unit/application/certification-centers/certification-center-controller_test.js @@ -182,79 +182,6 @@ describe('Unit | Controller | certifications-center-controller', function () { }); }); - describe('#findPaginatedSessionSummaries', function () { - beforeEach(function () { - sinon.stub(usecases, 'findPaginatedCertificationCenterSessionSummaries'); - }); - - it('should return a list of JSON API session summaries with pagination information', async function () { - // given - const request = { - params: { id: 456 }, - auth: { credentials: { userId: 123 } }, - query: { - page: { - number: 1, - size: 10, - }, - }, - }; - const sessionSummary = domainBuilder.buildSessionSummary.created({ - id: 1, - address: 'ici', - room: 'la-bas', - date: '2020-01-01', - time: '16:00', - examiner: 'Moi', - enrolledCandidatesCount: 5, - effectiveCandidatesCount: 4, - }); - usecases.findPaginatedCertificationCenterSessionSummaries - .withArgs({ - userId: 123, - certificationCenterId: 456, - page: { number: 1, size: 10 }, - }) - .resolves({ - models: [sessionSummary], - meta: { page: 1, pageSize: 10, itemsCount: 1, pagesCount: 1, hasSessions: true }, - }); - - // when - const serializedSessionSummaries = await certificationCenterController.findPaginatedSessionSummaries( - request, - hFake, - ); - - // then - expect(serializedSessionSummaries).to.deep.equal({ - data: [ - { - id: '1', - type: 'session-summaries', - attributes: { - address: 'ici', - room: 'la-bas', - date: '2020-01-01', - time: '16:00', - examiner: 'Moi', - 'effective-candidates-count': 4, - 'enrolled-candidates-count': 5, - status: 'created', - }, - }, - ], - meta: { - hasSessions: true, - itemsCount: 1, - page: 1, - pageSize: 10, - pagesCount: 1, - }, - }); - }); - }); - describe('#updateReferer', function () { it('should call updateCertificationCenterReferer usecase and return 204', async function () { // given diff --git a/api/tests/unit/application/certification-centers/index_test.js b/api/tests/unit/application/certification-centers/index_test.js index 40a136f8abc..8b91ce868df 100644 --- a/api/tests/unit/application/certification-centers/index_test.js +++ b/api/tests/unit/application/certification-centers/index_test.js @@ -1,5 +1,5 @@ import { certificationCenterController } from '../../../../lib/application/certification-centers/certification-center-controller.js'; -import * as moduleUnderTest from '../../../../lib/application/certification-centers/index.js'; +import * as moduleUnderTest from '../../../../src/certification/session-management/application/certification-centers-session-summaries.route.js'; import { securityPreHandlers } from '../../../../src/shared/application/security-pre-handlers.js'; import { expect, HttpTestServer, sinon } from '../../../test-helper.js'; @@ -272,20 +272,4 @@ describe('Unit | Router | certification-center-router', function () { expect(result.statusCode).to.equal(400); }); }); - - describe('GET /api/certification-centers/{certificationCenterId}/session-summaries', function () { - it('should return 200', async function () { - // given - sinon.stub(certificationCenterController, 'findPaginatedSessionSummaries').returns('ok'); - const httpTestServer = new HttpTestServer(); - await httpTestServer.register(moduleUnderTest); - - // when - const response = await httpTestServer.request('GET', '/api/certification-centers/123/session-summaries'); - - // then - expect(response.statusCode).to.equal(200); - sinon.assert.calledOnce(certificationCenterController.findPaginatedSessionSummaries); - }); - }); });