From e1a9ec79ed6bfaa26596f74d1767d323e849cd0d Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Thu, 7 Nov 2024 17:19:56 +0100 Subject: [PATCH 1/4] refactor(api): move certificationCenterMembershipsByCertificationCenter usecase to src/team --- .../certification-center-controller.js | 5 +++-- ...r-memberships-by-certification-center.usecase.js} | 0 ...berships-by-certification-center.usecase.test.js} | 12 ++++++------ ...berships-by-certification-center.usecase.test.js} | 8 ++++---- .../certification-center-controller_test.js | 9 +++++---- 5 files changed, 18 insertions(+), 16 deletions(-) rename api/{lib/domain/usecases/find-certification-center-memberships-by-certification-center.js => src/team/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.js} (100%) rename api/tests/{integration/domain/usecases/find-certification-center-memberships-by-certification-center_test.js => team/integration/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js} (68%) rename api/tests/{unit/domain/usecases/find-certification-center-memberships-by-certification-center_test.js => team/unit/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js} (71%) diff --git a/api/lib/application/certification-centers/certification-center-controller.js b/api/lib/application/certification-centers/certification-center-controller.js index 8778a1e70af..6a6e9e5da5a 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -2,6 +2,7 @@ import lodash from 'lodash'; import { usecases as certificationConfigurationUsecases } from '../../../src/certification/configuration/domain/usecases/index.js'; import * as divisionSerializer from '../../../src/prescription/campaign/infrastructure/serializers/jsonapi/division-serializer.js'; +import { usecases as teamUsecases } from '../../../src/team/domain/usecases/index.js'; import { usecases } from '../../domain/usecases/index.js'; import { DomainTransaction } from '../../infrastructure/DomainTransaction.js'; import * as certificationCenterForAdminSerializer from '../../infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js'; @@ -102,7 +103,7 @@ const findCertificationCenterMembershipsByCertificationCenter = async function ( dependencies = { certificationCenterMembershipSerializer }, ) { const certificationCenterId = request.params.certificationCenterId; - const certificationCenterMemberships = await usecases.findCertificationCenterMembershipsByCertificationCenter({ + const certificationCenterMemberships = await teamUsecases.findCertificationCenterMembershipsByCertificationCenter({ certificationCenterId, }); @@ -115,7 +116,7 @@ const findCertificationCenterMemberships = async function ( dependencies = { certificationCenterMembershipSerializer }, ) { const certificationCenterId = request.params.certificationCenterId; - const certificationCenterMemberships = await usecases.findCertificationCenterMembershipsByCertificationCenter({ + const certificationCenterMemberships = await teamUsecases.findCertificationCenterMembershipsByCertificationCenter({ certificationCenterId, }); diff --git a/api/lib/domain/usecases/find-certification-center-memberships-by-certification-center.js b/api/src/team/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.js similarity index 100% rename from api/lib/domain/usecases/find-certification-center-memberships-by-certification-center.js rename to api/src/team/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.js diff --git a/api/tests/integration/domain/usecases/find-certification-center-memberships-by-certification-center_test.js b/api/tests/team/integration/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js similarity index 68% rename from api/tests/integration/domain/usecases/find-certification-center-memberships-by-certification-center_test.js rename to api/tests/team/integration/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js index 10917772611..4d2cd8872a3 100644 --- a/api/tests/integration/domain/usecases/find-certification-center-memberships-by-certification-center_test.js +++ b/api/tests/team/integration/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js @@ -1,12 +1,12 @@ -import { usecases } from '../../../../lib/domain/usecases/index.js'; -import { CertificationCenterMembership } from '../../../../src/shared/domain/models/CertificationCenterMembership.js'; -import { certificationCenterMembershipRepository } from '../../../../src/team/infrastructure/repositories/certification-center-membership.repository.js'; -import { databaseBuilder, expect } from '../../../test-helper.js'; +import { CertificationCenterMembership } from '../../../../../src/shared/domain/models/CertificationCenterMembership.js'; +import { usecases } from '../../../../../src/team/domain/usecases/index.js'; +import { certificationCenterMembershipRepository } from '../../../../../src/team/infrastructure/repositories/certification-center-membership.repository.js'; +import { databaseBuilder, expect } from '../../../../test-helper.js'; const { findCertificationCenterMembershipsByCertificationCenter } = usecases; -describe('Integration | UseCase | find-certification-center-memberships-by-certification-center', function () { - it('should return certification center memberships', async function () { +describe('Integration | Team | Domain | UseCase | find-certification-center-memberships-by-certification-center', function () { + it('returns certification center memberships', async function () { // given const certificationCenter = databaseBuilder.factory.buildCertificationCenter(); const user = databaseBuilder.factory.buildUser(); diff --git a/api/tests/unit/domain/usecases/find-certification-center-memberships-by-certification-center_test.js b/api/tests/team/unit/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js similarity index 71% rename from api/tests/unit/domain/usecases/find-certification-center-memberships-by-certification-center_test.js rename to api/tests/team/unit/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js index d93b28eb309..cdab7aefbde 100644 --- a/api/tests/unit/domain/usecases/find-certification-center-memberships-by-certification-center_test.js +++ b/api/tests/team/unit/domain/usecases/find-certification-center-memberships-by-certification-center.usecase.test.js @@ -1,8 +1,8 @@ -import { usecases } from '../../../../lib/domain/usecases/index.js'; -import { domainBuilder, expect, sinon } from '../../../test-helper.js'; +import { usecases } from '../../../../../src/team/domain/usecases/index.js'; +import { domainBuilder, expect, sinon } from '../../../../test-helper.js'; -describe('Unit | UseCase | find-certification-center-memberships-by-certification-center', function () { - it('should result certification-center-memberships by certification center id', async function () { +describe('Unit | Team | Domain | UseCase | find-certification-center-memberships-by-certification-center', function () { + it('returns certification-center-memberships by certification center id', async function () { // given const certificationCenterId = 1; const certificationCenterMemberships = [domainBuilder.buildCertificationCenterMembership()]; 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 29a5632a8bf..6a5b6c42a5c 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 @@ -1,5 +1,6 @@ import { certificationCenterController } from '../../../../lib/application/certification-centers/certification-center-controller.js'; import { usecases } from '../../../../lib/domain/usecases/index.js'; +import { usecases as teamUsecases } from '../../../../src/team/domain/usecases/index.js'; import { domainBuilder, expect, hFake, sinon } from '../../../test-helper.js'; describe('Unit | Controller | certifications-center-controller', function () { @@ -122,7 +123,7 @@ describe('Unit | Controller | certifications-center-controller', function () { let certificationCenterMembershipSerializerStub; beforeEach(function () { - sinon.stub(usecases, 'findCertificationCenterMembershipsByCertificationCenter'); + sinon.stub(teamUsecases, 'findCertificationCenterMembershipsByCertificationCenter'); certificationCenterMembershipSerializerStub = { serialize: sinon.stub(), }; @@ -130,7 +131,7 @@ describe('Unit | Controller | certifications-center-controller', function () { it('should call usecase and serializer and return ok', async function () { // given - usecases.findCertificationCenterMembershipsByCertificationCenter + teamUsecases.findCertificationCenterMembershipsByCertificationCenter .withArgs({ certificationCenterId, }) @@ -167,7 +168,7 @@ describe('Unit | Controller | certifications-center-controller', function () { }; sinon - .stub(usecases, 'findCertificationCenterMembershipsByCertificationCenter') + .stub(teamUsecases, 'findCertificationCenterMembershipsByCertificationCenter') .withArgs({ certificationCenterId: certificationCenter.id, }) @@ -186,7 +187,7 @@ describe('Unit | Controller | certifications-center-controller', function () { }); // then - expect(usecases.findCertificationCenterMembershipsByCertificationCenter).to.have.been.calledOnce; + expect(teamUsecases.findCertificationCenterMembershipsByCertificationCenter).to.have.been.calledOnce; expect(response).equal(serializedCertificationCenterMembership); }); }); From f3317e06ecb1f6208444764772c0328fd132ad7a Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Thu, 7 Nov 2024 18:36:49 +0100 Subject: [PATCH 2/4] refactor(api): move certificationCenterMembership serializer to src/shared --- .../certification-center-membership-controller.js | 2 +- .../certification-centers/certification-center-controller.js | 2 +- api/lib/application/users/user-controller.js | 2 +- .../jsonapi/certification-center-membership.serializer.js} | 2 +- ...st.js => certification-center-membership.serializer.test.js} | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename api/{lib/infrastructure/serializers/jsonapi/certification-center-membership-serializer.js => src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js} (95%) rename api/tests/unit/infrastructure/serializers/jsonapi/{certification-center-membership-serializer_test.js => certification-center-membership.serializer.test.js} (98%) diff --git a/api/lib/application/certification-center-memberships/certification-center-membership-controller.js b/api/lib/application/certification-center-memberships/certification-center-membership-controller.js index 2a3dd398aa8..f66c28f7f3d 100644 --- a/api/lib/application/certification-center-memberships/certification-center-membership-controller.js +++ b/api/lib/application/certification-center-memberships/certification-center-membership-controller.js @@ -1,8 +1,8 @@ import { BadRequestError, ForbiddenError } from '../../../src/shared/application/http-errors.js'; +import * as certificationCenterMembershipSerializer from '../../../src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js'; import * as requestResponseUtils from '../../../src/shared/infrastructure/utils/request-response-utils.js'; import { certificationCenterMembershipRepository } from '../../../src/team/infrastructure/repositories/certification-center-membership.repository.js'; import { usecases } from '../../domain/usecases/index.js'; -import * as certificationCenterMembershipSerializer from '../../infrastructure/serializers/jsonapi/certification-center-membership-serializer.js'; const disableFromPixAdmin = async function (request, h, dependencies = { requestResponseUtils }) { const certificationCenterMembershipId = request.params.id; diff --git a/api/lib/application/certification-centers/certification-center-controller.js b/api/lib/application/certification-centers/certification-center-controller.js index 6a6e9e5da5a..c3a9fc02cba 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -2,11 +2,11 @@ import lodash from 'lodash'; import { usecases as certificationConfigurationUsecases } from '../../../src/certification/configuration/domain/usecases/index.js'; import * as divisionSerializer from '../../../src/prescription/campaign/infrastructure/serializers/jsonapi/division-serializer.js'; +import * as certificationCenterMembershipSerializer from '../../../src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js'; import { usecases as teamUsecases } from '../../../src/team/domain/usecases/index.js'; import { usecases } from '../../domain/usecases/index.js'; import { DomainTransaction } from '../../infrastructure/DomainTransaction.js'; import * as certificationCenterForAdminSerializer from '../../infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js'; -import * as certificationCenterMembershipSerializer from '../../infrastructure/serializers/jsonapi/certification-center-membership-serializer.js'; import * as sessionSummarySerializer from '../../infrastructure/serializers/jsonapi/session-summary-serializer.js'; import * as studentCertificationSerializer from '../../infrastructure/serializers/jsonapi/student-certification-serializer.js'; diff --git a/api/lib/application/users/user-controller.js b/api/lib/application/users/user-controller.js index 6070d10b385..8290a57da6b 100644 --- a/api/lib/application/users/user-controller.js +++ b/api/lib/application/users/user-controller.js @@ -5,11 +5,11 @@ import * as scorecardSerializer from '../../../src/evaluation/infrastructure/ser import { usecases as identityAccessManagementUsecases } from '../../../src/identity-access-management/domain/usecases/index.js'; import * as userDetailsForAdminSerializer from '../../../src/identity-access-management/infrastructure/serializers/jsonapi/user-details-for-admin.serializer.js'; import * as campaignParticipationSerializer from '../../../src/prescription/campaign-participation/infrastructure/serializers/jsonapi/campaign-participation-serializer.js'; +import * as certificationCenterMembershipSerializer from '../../../src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js'; import * as userSerializer from '../../../src/shared/infrastructure/serializers/jsonapi/user-serializer.js'; import * as requestResponseUtils from '../../../src/shared/infrastructure/utils/request-response-utils.js'; import { usecases } from '../../domain/usecases/index.js'; import { DomainTransaction } from '../../infrastructure/DomainTransaction.js'; -import * as certificationCenterMembershipSerializer from '../../infrastructure/serializers/jsonapi/certification-center-membership-serializer.js'; import * as userAnonymizedDetailsForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-anonymized-details-for-admin-serializer.js'; import * as userOrganizationForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-organization-for-admin-serializer.js'; diff --git a/api/lib/infrastructure/serializers/jsonapi/certification-center-membership-serializer.js b/api/src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js similarity index 95% rename from api/lib/infrastructure/serializers/jsonapi/certification-center-membership-serializer.js rename to api/src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js index 07f29acf7f2..6d80d896b89 100644 --- a/api/lib/infrastructure/serializers/jsonapi/certification-center-membership-serializer.js +++ b/api/src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js @@ -1,6 +1,6 @@ import jsonapiSerializer from 'jsonapi-serializer'; -import { CertificationCenterMembership } from '../../../../src/shared/domain/models/index.js'; +import { CertificationCenterMembership } from '../../../domain/models/index.js'; const { Serializer } = jsonapiSerializer; diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/certification-center-membership-serializer_test.js b/api/tests/unit/infrastructure/serializers/jsonapi/certification-center-membership.serializer.test.js similarity index 98% rename from api/tests/unit/infrastructure/serializers/jsonapi/certification-center-membership-serializer_test.js rename to api/tests/unit/infrastructure/serializers/jsonapi/certification-center-membership.serializer.test.js index 3a175df2455..07aa1d9fd2b 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/certification-center-membership-serializer_test.js +++ b/api/tests/unit/infrastructure/serializers/jsonapi/certification-center-membership.serializer.test.js @@ -1,5 +1,5 @@ -import * as certificationCenterMembershipSerializer from '../../../../../lib/infrastructure/serializers/jsonapi/certification-center-membership-serializer.js'; import { CertificationCenterMembership } from '../../../../../src/shared/domain/models/CertificationCenterMembership.js'; +import * as certificationCenterMembershipSerializer from '../../../../../src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js'; import { domainBuilder, expect } from '../../../../test-helper.js'; describe('Unit | Serializer | JSONAPI | certification-center-membership-serializer', function () { From a076f53651669469575619cb05559165d9cd6352 Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Fri, 8 Nov 2024 11:25:18 +0100 Subject: [PATCH 3/4] refactor(api): move findCertificationCenterMembership controller method to src/team/certification-center-membership --- .../certification-center-controller.js | 14 ------ ...tification-center-membership.controller.js | 20 ++++++++ ...ation-center-membership.controller.test.js | 47 +++++++++++++++++++ .../certification-center-controller_test.js | 42 ----------------- 4 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 api/src/team/application/certification-center-membership/certification-center-membership.controller.js create mode 100644 api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js diff --git a/api/lib/application/certification-centers/certification-center-controller.js b/api/lib/application/certification-centers/certification-center-controller.js index c3a9fc02cba..c513f414adf 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -110,19 +110,6 @@ const findCertificationCenterMembershipsByCertificationCenter = async function ( return dependencies.certificationCenterMembershipSerializer.serialize(certificationCenterMemberships); }; -const findCertificationCenterMemberships = async function ( - request, - h, - dependencies = { certificationCenterMembershipSerializer }, -) { - const certificationCenterId = request.params.certificationCenterId; - const certificationCenterMemberships = await teamUsecases.findCertificationCenterMembershipsByCertificationCenter({ - certificationCenterId, - }); - - return dependencies.certificationCenterMembershipSerializer.serializeMembers(certificationCenterMemberships); -}; - const createCertificationCenterMembershipByEmail = async function ( request, h, @@ -155,7 +142,6 @@ const updateReferer = async function (request, h) { const certificationCenterController = { create, createCertificationCenterMembershipByEmail, - findCertificationCenterMemberships, findCertificationCenterMembershipsByCertificationCenter, findPaginatedSessionSummaries, getCertificationCenterDetails, diff --git a/api/src/team/application/certification-center-membership/certification-center-membership.controller.js b/api/src/team/application/certification-center-membership/certification-center-membership.controller.js new file mode 100644 index 00000000000..5e4265c613b --- /dev/null +++ b/api/src/team/application/certification-center-membership/certification-center-membership.controller.js @@ -0,0 +1,20 @@ +import * as certificationCenterMembershipSerializer from '../../../shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js'; +import { usecases } from '../../domain/usecases/index.js'; + +const findCertificationCenterMemberships = async function ( + request, + h, + dependencies = { certificationCenterMembershipSerializer }, +) { + const certificationCenterId = request.params.certificationCenterId; + const certificationCenterMemberships = await usecases.findCertificationCenterMembershipsByCertificationCenter({ + certificationCenterId, + }); + + return dependencies.certificationCenterMembershipSerializer.serializeMembers(certificationCenterMemberships); +}; + +const certificationCenterMembershipController = { + findCertificationCenterMemberships, +}; +export { certificationCenterMembershipController }; diff --git a/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js b/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js new file mode 100644 index 00000000000..cdb51de55b6 --- /dev/null +++ b/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js @@ -0,0 +1,47 @@ +import { certificationCenterMembershipController } from '../../../../../src/team/application/certification-center-membership/certification-center-membership.controller.js'; +import { usecases } from '../../../../../src/team/domain/usecases/index.js'; +import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; + +describe('Unit | Team | Application | Controller | CertificationCenterMembership', function () { + describe('#findCertificationCenterMemberships', function () { + it('returns the serialized membership', async function () { + // given + const user = domainBuilder.buildUser(); + const certificationCenter = domainBuilder.buildCertificationCenter(); + const certificationCenterMembership = domainBuilder.buildCertificationCenterMembership({ + certificationCenter, + user, + }); + const serializedCertificationCenterMembership = Symbol('certification center membership serialized'); + + const request = { + params: { + certificationCenterId: certificationCenter.id, + }, + }; + + sinon + .stub(usecases, 'findCertificationCenterMembershipsByCertificationCenter') + .withArgs({ + certificationCenterId: certificationCenter.id, + }) + .resolves(certificationCenterMembership); + + const certificationCenterMembershipSerializerStub = { + serializeMembers: sinon.stub(), + }; + certificationCenterMembershipSerializerStub.serializeMembers + .withArgs(certificationCenterMembership) + .returns(serializedCertificationCenterMembership); + + // when + const response = await certificationCenterMembershipController.findCertificationCenterMemberships(request, hFake, { + certificationCenterMembershipSerializer: certificationCenterMembershipSerializerStub, + }); + + // then + expect(usecases.findCertificationCenterMembershipsByCertificationCenter).to.have.been.calledOnce; + expect(response).equal(serializedCertificationCenterMembership); + }); + }); +}); 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 6a5b6c42a5c..50972e57d3c 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 @@ -150,48 +150,6 @@ describe('Unit | Controller | certifications-center-controller', function () { }); }); - describe('#findCertificationCenterMemberships', function () { - it('should return the serialized membership', async function () { - // given - const user = domainBuilder.buildUser(); - const certificationCenter = domainBuilder.buildCertificationCenter(); - const certificationCenterMembership = domainBuilder.buildCertificationCenterMembership({ - certificationCenter, - user, - }); - const serializedCertificationCenterMembership = Symbol('certification center membership serialized'); - - const request = { - params: { - certificationCenterId: certificationCenter.id, - }, - }; - - sinon - .stub(teamUsecases, 'findCertificationCenterMembershipsByCertificationCenter') - .withArgs({ - certificationCenterId: certificationCenter.id, - }) - .resolves(certificationCenterMembership); - - const certificationCenterMembershipSerializerStub = { - serializeMembers: sinon.stub(), - }; - certificationCenterMembershipSerializerStub.serializeMembers - .withArgs(certificationCenterMembership) - .returns(serializedCertificationCenterMembership); - - // when - const response = await certificationCenterController.findCertificationCenterMemberships(request, hFake, { - certificationCenterMembershipSerializer: certificationCenterMembershipSerializerStub, - }); - - // then - expect(teamUsecases.findCertificationCenterMembershipsByCertificationCenter).to.have.been.calledOnce; - expect(response).equal(serializedCertificationCenterMembership); - }); - }); - describe('#createCertificationCenterMembershipByEmail', function () { const certificationCenterId = 1; const email = 'user@example.net'; From 4263f751bfa25598dc4068648a5beb3c0e7b12bb Mon Sep 17 00:00:00 2001 From: Emmanuelle Bonnemay Date: Fri, 8 Nov 2024 11:31:55 +0100 Subject: [PATCH 4/4] refactor(api): move route to src/team/certification-center-membership --- .../certification-centers/index.js | 23 -------------- .../certification-center-membership.route.js | 31 +++++++++++++++++++ api/src/team/application/routes.js | 2 ++ ...ification-center-membership.route.test.js} | 8 +++-- ...ation-center-membership.controller.test.js | 10 ++++-- 5 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 api/src/team/application/certification-center-membership/certification-center-membership.route.js rename api/tests/{acceptance/application/certification-centers/certification-centers-route-get_test.js => team/acceptance/application/certification-center-membership.route.test.js} (89%) diff --git a/api/lib/application/certification-centers/index.js b/api/lib/application/certification-centers/index.js index b2196c5d3ef..a03552ce68c 100644 --- a/api/lib/application/certification-centers/index.js +++ b/api/lib/application/certification-centers/index.js @@ -249,29 +249,6 @@ const register = async function (server) { ], }, }, - { - method: 'GET', - path: '/api/certification-centers/{certificationCenterId}/members', - config: { - pre: [ - { - method: securityPreHandlers.checkUserIsMemberOfCertificationCenter, - assign: 'isMemberOfCertificationCenter', - }, - ], - validate: { - params: Joi.object({ - certificationCenterId: identifiersType.certificationCenterId, - }), - }, - handler: certificationCenterController.findCertificationCenterMemberships, - notes: [ - '- **Cette route est restreinte aux utilisateurs appartenant à un centre de certification**\n' + - "- Récupération de tous les membres d'un centre de certification.\n", - ], - tags: ['api', 'certification-center', 'members'], - }, - }, ]); }; diff --git a/api/src/team/application/certification-center-membership/certification-center-membership.route.js b/api/src/team/application/certification-center-membership/certification-center-membership.route.js new file mode 100644 index 00000000000..cadac40e5f9 --- /dev/null +++ b/api/src/team/application/certification-center-membership/certification-center-membership.route.js @@ -0,0 +1,31 @@ +import Joi from 'joi'; + +import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; +import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; +import { certificationCenterMembershipController } from './certification-center-membership.controller.js'; + +export const certificationCenterMembershipRoute = [ + { + method: 'GET', + path: '/api/certification-centers/{certificationCenterId}/members', + config: { + pre: [ + { + method: securityPreHandlers.checkUserIsMemberOfCertificationCenter, + assign: 'isMemberOfCertificationCenter', + }, + ], + validate: { + params: Joi.object({ + certificationCenterId: identifiersType.certificationCenterId, + }), + }, + handler: (request, h) => certificationCenterMembershipController.findCertificationCenterMemberships(request, h), + notes: [ + '- **Cette route est restreinte aux utilisateurs appartenant à un centre de certification**\n' + + "- Récupération de tous les membres d'un centre de certification.\n", + ], + tags: ['api', 'team', 'certification-center', 'members'], + }, + }, +]; diff --git a/api/src/team/application/routes.js b/api/src/team/application/routes.js index 73aa60d78f5..54af524cd71 100644 --- a/api/src/team/application/routes.js +++ b/api/src/team/application/routes.js @@ -1,6 +1,7 @@ import { adminMemberRoutes } from './admin-member/admin-member.route.js'; import { certificationCenterInvitationAdminRoutes } from './certification-center-invitation/certification-center-invitation.admin.route.js'; import { certificationCenterInvitationRoutes } from './certification-center-invitation/certification-center-invitation.route.js'; +import { certificationCenterMembershipRoute } from './certification-center-membership/certification-center-membership.route.js'; import { membershipAdminRoutes } from './membership/membership.admin.route.js'; import { membershipRoutes } from './membership/membership.route.js'; import { organizationInvitationAdminRoutes } from './organization-invitations/organization-invitation.admin.route.js'; @@ -12,6 +13,7 @@ const register = async function (server) { ...adminMemberRoutes, ...certificationCenterInvitationRoutes, ...certificationCenterInvitationAdminRoutes, + ...certificationCenterMembershipRoute, ...membershipAdminRoutes, ...membershipRoutes, ...prescriberInformationsRoute, diff --git a/api/tests/acceptance/application/certification-centers/certification-centers-route-get_test.js b/api/tests/team/acceptance/application/certification-center-membership.route.test.js similarity index 89% rename from api/tests/acceptance/application/certification-centers/certification-centers-route-get_test.js rename to api/tests/team/acceptance/application/certification-center-membership.route.test.js index 4d71f07fb8a..6f555dee7ba 100644 --- a/api/tests/acceptance/application/certification-centers/certification-centers-route-get_test.js +++ b/api/tests/team/acceptance/application/certification-center-membership.route.test.js @@ -5,10 +5,13 @@ import { generateValidRequestAuthorizationHeader, } from '../../../test-helper.js'; -describe('Acceptance | Application | Certification-centers | Routes', function () { +describe('Acceptance | Application | Certification center membership | Routes', function () { + let server, options; + describe('GET /api/certification-centers/{certificationCenterId}/members', function () { it('should return 200 http status code', async function () { // given + server = await createServer(); const certificationCenter = databaseBuilder.factory.buildCertificationCenter(); const certificationCenterMember = databaseBuilder.factory.buildUser(); const user2 = databaseBuilder.factory.buildUser(); @@ -21,9 +24,8 @@ describe('Acceptance | Application | Certification-centers | Routes', function ( userId: user2.id, }); await databaseBuilder.commit(); - const server = await createServer(); - const options = { + options = { headers: { authorization: generateValidRequestAuthorizationHeader(certificationCenterMember.id), }, diff --git a/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js b/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js index cdb51de55b6..e9a6745b1d2 100644 --- a/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js +++ b/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js @@ -35,9 +35,13 @@ describe('Unit | Team | Application | Controller | CertificationCenterMembership .returns(serializedCertificationCenterMembership); // when - const response = await certificationCenterMembershipController.findCertificationCenterMemberships(request, hFake, { - certificationCenterMembershipSerializer: certificationCenterMembershipSerializerStub, - }); + const response = await certificationCenterMembershipController.findCertificationCenterMemberships( + request, + hFake, + { + certificationCenterMembershipSerializer: certificationCenterMembershipSerializerStub, + }, + ); // then expect(usecases.findCertificationCenterMembershipsByCertificationCenter).to.have.been.calledOnce;