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 8778a1e70af..c513f414adf 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -2,10 +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'; @@ -102,26 +103,13 @@ const findCertificationCenterMembershipsByCertificationCenter = async function ( dependencies = { certificationCenterMembershipSerializer }, ) { const certificationCenterId = request.params.certificationCenterId; - const certificationCenterMemberships = await usecases.findCertificationCenterMembershipsByCertificationCenter({ + const certificationCenterMemberships = await teamUsecases.findCertificationCenterMembershipsByCertificationCenter({ certificationCenterId, }); return dependencies.certificationCenterMembershipSerializer.serialize(certificationCenterMemberships); }; -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 createCertificationCenterMembershipByEmail = async function ( request, h, @@ -154,7 +142,6 @@ const updateReferer = async function (request, h) { const certificationCenterController = { create, createCertificationCenterMembershipByEmail, - findCertificationCenterMemberships, findCertificationCenterMembershipsByCertificationCenter, findPaginatedSessionSummaries, getCertificationCenterDetails, 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/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/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/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/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/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/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/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..e9a6745b1d2 --- /dev/null +++ b/api/tests/team/unit/application/certification-center-membership/certification-center-membership.controller.test.js @@ -0,0 +1,51 @@ +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/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..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 @@ -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, }) @@ -149,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(usecases, '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(usecases.findCertificationCenterMembershipsByCertificationCenter).to.have.been.calledOnce; - expect(response).equal(serializedCertificationCenterMembership); - }); - }); - describe('#createCertificationCenterMembershipByEmail', function () { const certificationCenterId = 1; const email = 'user@example.net'; 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 () {