From c1532df403ca4336f14b8710b9fc78edb76d2f82 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 09:11:57 +0100 Subject: [PATCH 01/10] refactor(api): rename export certification center controller to correct certification center admin controller --- .../certification-center.admin.controller.js | 4 ++-- .../certification-center/certification-center.admin.route.js | 4 ++-- .../certification-center.admin.controller.test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js index 9c82e21a7a7..3cf6dd0de4d 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js @@ -15,8 +15,8 @@ const findPaginatedFilteredCertificationCenters = async function ( return dependencies.certificationCenterSerializer.serialize(organizations, pagination); }; -const certificationCenterController = { +const certificationCenterAdminController = { findPaginatedFilteredCertificationCenters, }; -export { certificationCenterController }; +export { certificationCenterAdminController }; diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js index 6219dd8db8e..71e2b6c9ebc 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js @@ -2,7 +2,7 @@ import Joi from 'joi'; import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; import { optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js'; -import { certificationCenterController } from './certification-center.admin.controller.js'; +import { certificationCenterAdminController } from './certification-center.admin.controller.js'; const register = async function (server) { server.route([ @@ -10,7 +10,7 @@ const register = async function (server) { method: 'GET', path: '/api/admin/certification-centers', config: { - handler: certificationCenterController.findPaginatedFilteredCertificationCenters, + handler: certificationCenterAdminController.findPaginatedFilteredCertificationCenters, pre: [ { method: (request, h) => diff --git a/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js b/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js index cee21e16509..788ef04227e 100644 --- a/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js +++ b/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js @@ -1,4 +1,4 @@ -import { certificationCenterController } from '../../../../../src/organizational-entities/application/certification-center/certification-center.admin.controller.js'; +import { certificationCenterAdminController } from '../../../../../src/organizational-entities/application/certification-center/certification-center.admin.controller.js'; import { usecases } from '../../../../../src/organizational-entities/domain/usecases/index.js'; import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; @@ -41,7 +41,7 @@ describe('Unit | Organizational Entities | Application | Controller | Admin | ce }); // when - const response = await certificationCenterController.findPaginatedFilteredCertificationCenters( + const response = await certificationCenterAdminController.findPaginatedFilteredCertificationCenters( request, hFake, dependencies, From f302a6287aa203237ec9665bf531748b8fc72150 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 09:18:43 +0100 Subject: [PATCH 02/10] refactor(api) remove duplicate tests for GET /api/admin/certification-centers route --- .../certification-center.admin.route.test.js | 151 +++++++++++++++-- .../certification-center.controller.test.js | 154 ------------------ 2 files changed, 134 insertions(+), 171 deletions(-) delete mode 100644 api/tests/organizational-entities/acceptance/application/certification-center/certification-center.controller.test.js diff --git a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js index 0a744a95f09..784da3d841e 100644 --- a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js +++ b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js @@ -6,32 +6,149 @@ import { insertUserWithRoleSuperAdmin, } from '../../../../test-helper.js'; -describe('Acceptance | Route | Certification Centers', function () { - let server; +describe('Acceptance | Organization Entities | Route | Certification Centers', function () { + let server, request; beforeEach(async function () { server = await createServer(); + await insertUserWithRoleSuperAdmin(); }); describe('GET /api/admin/certification-centers', function () { - it('should return an HTTP code 200 and a list of certification centers', async function () { - // given - const adminMember = await insertUserWithRoleSuperAdmin(); - databaseBuilder.factory.buildCertificationCenter(); - - await databaseBuilder.commit(); - - //when - const { result, statusCode } = await server.inject({ - headers: { - authorization: generateValidRequestAuthorizationHeader(adminMember.id), - }, + beforeEach(async function () { + request = { method: 'GET', - url: `/api/admin/certification-centers`, + url: '/api/admin/certification-centers', + }; + }); + + context('when user is Super Admin', function () { + beforeEach(function () { + request.headers = { authorization: generateValidRequestAuthorizationHeader() }; + }); + + it('returns a list of certificationCenter, with their name and id', async function () { + // given + databaseBuilder.factory.buildCertificationCenter({ + id: 1, + name: 'Centres des tests jolis', + type: 'SUP', + externalId: '12345', + createdAt: new Date('2020-01-01'), + }); + databaseBuilder.factory.buildCertificationCenter({ + id: 2, + name: 'Centres des tests pas moches', + type: 'SCO', + externalId: '222', + createdAt: new Date('2020-01-05'), + }); + databaseBuilder.factory.buildComplementaryCertification({ + id: 12, + label: 'Pix+Edu 1er degré', + key: 'EDU_1ER_DEGRE', + }); + databaseBuilder.factory.buildComplementaryCertificationHabilitation({ + certificationCenterId: 1, + complementaryCertificationId: 12, + }); + await databaseBuilder.commit(); + + // when + const response = await server.inject(request); + + // then + expect(response.statusCode).to.equal(200); + expect(response.result).to.deep.equal({ + data: [ + { + id: '1', + type: 'certification-centers', + attributes: { + 'created-at': new Date('2020-01-01'), + 'external-id': '12345', + name: 'Centres des tests jolis', + type: 'SUP', + }, + relationships: { + habilitations: { + data: [ + { + id: '12', + type: 'complementary-certifications', + }, + ], + }, + 'certification-center-memberships': { + links: { + related: '/api/certification-centers/1/certification-center-memberships', + }, + }, + }, + }, + { + id: '2', + type: 'certification-centers', + attributes: { + 'created-at': new Date('2020-01-05'), + 'external-id': '222', + name: 'Centres des tests pas moches', + type: 'SCO', + }, + relationships: { + habilitations: { + data: [], + }, + 'certification-center-memberships': { + links: { + related: '/api/certification-centers/2/certification-center-memberships', + }, + }, + }, + }, + ], + included: [ + { + id: '12', + type: 'complementary-certifications', + attributes: { + label: 'Pix+Edu 1er degré', + key: 'EDU_1ER_DEGRE', + }, + }, + ], + meta: { + page: 1, + pageCount: 1, + pageSize: 10, + rowCount: 2, + }, + }); }); + }); - expect(statusCode).to.equal(200); - expect(result.data.length).to.equal(1); + context('when user is not SuperAdmin', function () { + beforeEach(function () { + request.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; + }); + + it('returns a 403 HTTP status code ', async function () { + // when + const response = await server.inject(request); + + // then + expect(response.statusCode).to.equal(403); + }); + }); + + context('when user is not connected', function () { + it('should return 401 HTTP status code if user is not authenticated', async function () { + // when + const response = await server.inject(request); + + // then + expect(response.statusCode).to.equal(401); + }); }); }); }); diff --git a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.controller.test.js b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.controller.test.js deleted file mode 100644 index 5cb1dc93f91..00000000000 --- a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.controller.test.js +++ /dev/null @@ -1,154 +0,0 @@ -import { - createServer, - databaseBuilder, - expect, - generateValidRequestAuthorizationHeader, - insertUserWithRoleSuperAdmin, -} from '../../../../test-helper.js'; - -describe('Acceptance | API | Certification Center', function () { - let server, request; - - beforeEach(async function () { - server = await createServer(); - await insertUserWithRoleSuperAdmin(); - }); - - describe('GET /api/admin/certification-centers', function () { - beforeEach(async function () { - request = { - method: 'GET', - url: '/api/admin/certification-centers', - }; - }); - - context('when user is Super Admin', function () { - beforeEach(function () { - request.headers = { authorization: generateValidRequestAuthorizationHeader() }; - }); - - it('should return a list of certificationCenter, with their name and id', async function () { - // given - databaseBuilder.factory.buildCertificationCenter({ - id: 1, - name: 'Centres des tests jolis', - type: 'SUP', - externalId: '12345', - createdAt: new Date('2020-01-01'), - }); - databaseBuilder.factory.buildCertificationCenter({ - id: 2, - name: 'Centres des tests pas moches', - type: 'SCO', - externalId: '222', - createdAt: new Date('2020-01-05'), - }); - databaseBuilder.factory.buildComplementaryCertification({ - id: 12, - label: 'Pix+Edu 1er degré', - key: 'EDU_1ER_DEGRE', - }); - databaseBuilder.factory.buildComplementaryCertificationHabilitation({ - certificationCenterId: 1, - complementaryCertificationId: 12, - }); - await databaseBuilder.commit(); - - // when - const response = await server.inject(request); - - // then - expect(response.statusCode).to.equal(200); - expect(response.result).to.deep.equal({ - data: [ - { - id: '1', - type: 'certification-centers', - attributes: { - 'created-at': new Date('2020-01-01'), - 'external-id': '12345', - name: 'Centres des tests jolis', - type: 'SUP', - }, - relationships: { - habilitations: { - data: [ - { - id: '12', - type: 'complementary-certifications', - }, - ], - }, - 'certification-center-memberships': { - links: { - related: '/api/certification-centers/1/certification-center-memberships', - }, - }, - }, - }, - { - id: '2', - type: 'certification-centers', - attributes: { - 'created-at': new Date('2020-01-05'), - 'external-id': '222', - name: 'Centres des tests pas moches', - type: 'SCO', - }, - relationships: { - habilitations: { - data: [], - }, - 'certification-center-memberships': { - links: { - related: '/api/certification-centers/2/certification-center-memberships', - }, - }, - }, - }, - ], - included: [ - { - id: '12', - type: 'complementary-certifications', - attributes: { - label: 'Pix+Edu 1er degré', - key: 'EDU_1ER_DEGRE', - }, - }, - ], - meta: { - page: 1, - pageCount: 1, - pageSize: 10, - rowCount: 2, - }, - }); - }); - }); - - context('when user is not SuperAdmin', function () { - beforeEach(function () { - request.headers = { authorization: generateValidRequestAuthorizationHeader(1111) }; - }); - - it('should return 403 HTTP status code ', async function () { - // when - const response = await server.inject(request); - - // then - expect(response.statusCode).to.equal(403); - }); - }); - - context('when user is not connected', function () { - it('should return 401 HTTP status code if user is not authenticated', async function () { - // when - const response = await server.inject(request); - - // then - expect(response.statusCode).to.equal(401); - }); - }); - }); -}); From 2830c0019e87430381ba78c8ead4a1c7f97dd33b Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 09:23:37 +0100 Subject: [PATCH 03/10] refactor(api): move POST /api/admin/certification-centers route in src/organizational-entities --- .../certification-centers/index.js | 24 ----- .../certification-center.admin.route.js | 27 +++++- .../certification-center-controller_test.js | 88 ------------------- .../certification-center.admin.route.test.js | 88 +++++++++++++++++++ 4 files changed, 114 insertions(+), 113 deletions(-) diff --git a/api/lib/application/certification-centers/index.js b/api/lib/application/certification-centers/index.js index a03552ce68c..c37830c8ee4 100644 --- a/api/lib/application/certification-centers/index.js +++ b/api/lib/application/certification-centers/index.js @@ -6,30 +6,6 @@ import { certificationCenterController } from './certification-center-controller const register = async function (server) { const adminRoutes = [ - { - method: 'POST', - path: '/api/admin/certification-centers', - config: { - handler: certificationCenterController.create, - pre: [ - { - method: (request, h) => - securityPreHandlers.hasAtLeastOneAccessOf([ - securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, - securityPreHandlers.checkAdminMemberHasRoleCertif, - securityPreHandlers.checkAdminMemberHasRoleSupport, - securityPreHandlers.checkAdminMemberHasRoleMetier, - ])(request, h), - assign: 'hasAuthorizationToAccessAdminScope', - }, - ], - notes: [ - "- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" + - '- Création d‘un nouveau centre de certification\n', - ], - tags: ['api', 'certification-center'], - }, - }, { method: 'GET', path: '/api/admin/certification-centers/{id}', diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js index 71e2b6c9ebc..27421b54af8 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js @@ -1,5 +1,6 @@ import Joi from 'joi'; +import { certificationCenterController } from '../../../../lib/application/certification-centers/certification-center-controller.js'; import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; import { optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js'; import { certificationCenterAdminController } from './certification-center.admin.controller.js'; @@ -41,7 +42,31 @@ const register = async function (server) { "- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" + '- Liste des centres de certification\n', ], - tags: ['api', 'certification-center'], + tags: ['api', 'organizational-entities', 'certification-center'], + }, + }, + { + method: 'POST', + path: '/api/admin/certification-centers', + config: { + handler: certificationCenterController.create, + pre: [ + { + method: (request, h) => + securityPreHandlers.hasAtLeastOneAccessOf([ + securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, + securityPreHandlers.checkAdminMemberHasRoleCertif, + securityPreHandlers.checkAdminMemberHasRoleSupport, + securityPreHandlers.checkAdminMemberHasRoleMetier, + ])(request, h), + assign: 'hasAuthorizationToAccessAdminScope', + }, + ], + notes: [ + "- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" + + '- Création d‘un nouveau centre de certification\n', + ], + tags: ['api', 'organizational-entities', 'certification-center'], }, }, ]); diff --git a/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js b/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js index 3cb5e620a05..8745b0f1f12 100644 --- a/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js +++ b/api/tests/acceptance/application/certification-centers/certification-center-controller_test.js @@ -17,94 +17,6 @@ describe('Acceptance | API | Certification Center', function () { await insertUserWithRoleSuperAdmin(); }); - describe('POST /api/admin/certification-centers', function () { - let complementaryCertification; - - beforeEach(async function () { - // given - complementaryCertification = databaseBuilder.factory.buildComplementaryCertification(); - await databaseBuilder.commit(); - }); - - afterEach(async function () { - complementaryCertification = null; - }); - - context('when user is Super Admin', function () { - it('returns 200 HTTP status with the certification center created', async function () { - // when - const response = await server.inject({ - method: 'POST', - url: '/api/admin/certification-centers', - headers: { authorization: generateValidRequestAuthorizationHeader() }, - payload: { - data: { - type: 'certification-center', - attributes: { - name: 'Nouveau Centre de Certif', - type: 'SCO', - 'data-protection-officer-email': 'adrienne.quepourra@example.net', - 'is-v3-pilot': true, - }, - relationships: { - habilitations: { - data: [ - { - type: 'complementary-certifications', - id: `${complementaryCertification.id}`, - }, - ], - }, - }, - }, - }, - }); - - // then - expect(response.statusCode).to.equal(200); - expect(response.result.data.attributes.name).to.equal('Nouveau Centre de Certif'); - expect(response.result.data.attributes['data-protection-officer-email']).to.equal( - 'adrienne.quepourra@example.net', - ); - expect(response.result.data.attributes['is-v3-pilot']).to.equal(true); - expect(response.result.data.id).to.be.ok; - }); - }); - - context('when user is not SuperAdmin', function () { - it('should return 403 HTTP status code ', async function () { - // when - const response = await server.inject({ - method: 'POST', - url: '/api/admin/certification-centers', - headers: { authorization: generateValidRequestAuthorizationHeader(111) }, - payload: { - data: { - type: 'certification-center', - attributes: { - name: 'Nouveau Centre de Certif', - type: 'SCO', - }, - relationships: { - habilitations: { - data: [ - { - type: 'complementary-certifications', - id: `${complementaryCertification.id}`, - }, - ], - }, - }, - }, - }, - }); - - // then - expect(response.statusCode).to.equal(403); - }); - }); - }); - describe('GET /api/admin/certification-centers/{id}', function () { let expectedCertificationCenter; diff --git a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js index 784da3d841e..eafca44311e 100644 --- a/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js +++ b/api/tests/organizational-entities/acceptance/application/certification-center/certification-center.admin.route.test.js @@ -151,4 +151,92 @@ describe('Acceptance | Organization Entities | Route | Certification Centers', f }); }); }); + + describe('POST /api/admin/certification-centers', function () { + let complementaryCertification; + + beforeEach(async function () { + // given + complementaryCertification = databaseBuilder.factory.buildComplementaryCertification(); + await databaseBuilder.commit(); + }); + + afterEach(async function () { + complementaryCertification = null; + }); + + context('when user is Super Admin', function () { + it('returns 200 HTTP status with the certification center created', async function () { + // when + const response = await server.inject({ + method: 'POST', + url: '/api/admin/certification-centers', + headers: { authorization: generateValidRequestAuthorizationHeader() }, + payload: { + data: { + type: 'certification-center', + attributes: { + name: 'Nouveau Centre de Certif', + type: 'SCO', + 'data-protection-officer-email': 'adrienne.quepourra@example.net', + 'is-v3-pilot': true, + }, + relationships: { + habilitations: { + data: [ + { + type: 'complementary-certifications', + id: `${complementaryCertification.id}`, + }, + ], + }, + }, + }, + }, + }); + + // then + expect(response.statusCode).to.equal(200); + expect(response.result.data.attributes.name).to.equal('Nouveau Centre de Certif'); + expect(response.result.data.attributes['data-protection-officer-email']).to.equal( + 'adrienne.quepourra@example.net', + ); + expect(response.result.data.attributes['is-v3-pilot']).to.equal(true); + expect(response.result.data.id).to.be.ok; + }); + }); + + context('when user is not SuperAdmin', function () { + it('should return 403 HTTP status code ', async function () { + // when + const response = await server.inject({ + method: 'POST', + url: '/api/admin/certification-centers', + headers: { authorization: generateValidRequestAuthorizationHeader(111) }, + payload: { + data: { + type: 'certification-center', + attributes: { + name: 'Nouveau Centre de Certif', + type: 'SCO', + }, + relationships: { + habilitations: { + data: [ + { + type: 'complementary-certifications', + id: `${complementaryCertification.id}`, + }, + ], + }, + }, + }, + }, + }); + + // then + expect(response.statusCode).to.equal(403); + }); + }); + }); }); From c7f6895850a1807fd961b1c00cb3ed916da9352f Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 09:38:40 +0100 Subject: [PATCH 04/10] refactor(api): move create certification center controller in src/organizational-entities --- .../certification-center-controller.js | 11 ----------- .../certification-center.admin.controller.js | 15 +++++++++++++++ .../certification-center.admin.route.js | 3 +-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/api/lib/application/certification-centers/certification-center-controller.js b/api/lib/application/certification-centers/certification-center-controller.js index c513f414adf..296e4508359 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -12,16 +12,6 @@ import * as studentCertificationSerializer from '../../infrastructure/serializer const { map } = lodash; -const create = async function (request) { - const certificationCenter = certificationCenterForAdminSerializer.deserialize(request.payload); - const complementaryCertificationIds = map(request.payload.data.relationships?.habilitations?.data, 'id'); - const createdCertificationCenter = await usecases.createCertificationCenter({ - certificationCenter, - complementaryCertificationIds, - }); - return certificationCenterForAdminSerializer.serialize(createdCertificationCenter); -}; - const update = async function (request) { const certificationCenterId = request.params.id; const certificationCenterInformation = certificationCenterForAdminSerializer.deserialize(request.payload); @@ -140,7 +130,6 @@ const updateReferer = async function (request, h) { }; const certificationCenterController = { - create, createCertificationCenterMembershipByEmail, findCertificationCenterMembershipsByCertificationCenter, findPaginatedSessionSummaries, diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js index 3cf6dd0de4d..fa3ce3829fb 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js @@ -1,6 +1,20 @@ +import { usecases as libUsecases } from '../../../../lib/domain/usecases/index.js'; +import * as certificationCenterForAdminSerializer from '../../../../lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js'; import { usecases } from '../../domain/usecases/index.js'; import * as certificationCenterSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center.serializer.js'; +const create = async function (request) { + const certificationCenter = certificationCenterForAdminSerializer.deserialize(request.payload); + const complementaryCertificationIds = request.payload.data.relationships?.habilitations?.data.map( + (complementaryCertification) => complementaryCertification.id, + ); + const createdCertificationCenter = await libUsecases.createCertificationCenter({ + certificationCenter, + complementaryCertificationIds, + }); + return certificationCenterForAdminSerializer.serialize(createdCertificationCenter); +}; + const findPaginatedFilteredCertificationCenters = async function ( request, h, @@ -16,6 +30,7 @@ const findPaginatedFilteredCertificationCenters = async function ( }; const certificationCenterAdminController = { + create, findPaginatedFilteredCertificationCenters, }; diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js index 27421b54af8..ec5ae5d0503 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.route.js @@ -1,6 +1,5 @@ import Joi from 'joi'; -import { certificationCenterController } from '../../../../lib/application/certification-centers/certification-center-controller.js'; import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; import { optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js'; import { certificationCenterAdminController } from './certification-center.admin.controller.js'; @@ -49,7 +48,7 @@ const register = async function (server) { method: 'POST', path: '/api/admin/certification-centers', config: { - handler: certificationCenterController.create, + handler: certificationCenterAdminController.create, pre: [ { method: (request, h) => From 0e57ee103dd2c69c4f2d3abca2dab7c9752c5c10 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 10:20:56 +0100 Subject: [PATCH 05/10] refactor(api): move certification center for admin serializer --- .../certification-center-controller.js | 2 +- .../certification-center.admin.controller.js | 2 +- .../certification-center-for-admin.serializer.js} | 2 +- .../certification-center-for-admin.serializer.test.js} | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename api/{lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js => src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js} (94%) rename api/tests/{unit/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer_test.js => organizational-entities/unit/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.test.js} (94%) diff --git a/api/lib/application/certification-centers/certification-center-controller.js b/api/lib/application/certification-centers/certification-center-controller.js index 296e4508359..0ddbe09effb 100644 --- a/api/lib/application/certification-centers/certification-center-controller.js +++ b/api/lib/application/certification-centers/certification-center-controller.js @@ -1,12 +1,12 @@ import lodash from 'lodash'; import { usecases as certificationConfigurationUsecases } from '../../../src/certification/configuration/domain/usecases/index.js'; +import * as certificationCenterForAdminSerializer from '../../../src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.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 sessionSummarySerializer from '../../infrastructure/serializers/jsonapi/session-summary-serializer.js'; import * as studentCertificationSerializer from '../../infrastructure/serializers/jsonapi/student-certification-serializer.js'; diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js index fa3ce3829fb..277b63bf171 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js @@ -1,7 +1,7 @@ import { usecases as libUsecases } from '../../../../lib/domain/usecases/index.js'; -import * as certificationCenterForAdminSerializer from '../../../../lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js'; import { usecases } from '../../domain/usecases/index.js'; import * as certificationCenterSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center.serializer.js'; +import * as certificationCenterForAdminSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js'; const create = async function (request) { const certificationCenter = certificationCenterForAdminSerializer.deserialize(request.payload); diff --git a/api/lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js b/api/src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js similarity index 94% rename from api/lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js rename to api/src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js index 86be1d0c4d0..f0f46b98f24 100644 --- a/api/lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js +++ b/api/src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js @@ -2,7 +2,7 @@ import jsonapiSerializer from 'jsonapi-serializer'; const { Serializer } = jsonapiSerializer; -import { CenterForAdmin } from '../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; +import { CenterForAdmin } from '../../../../../certification/enrolment/domain/models/CenterForAdmin.js'; const deserialize = function ({ data }) { const center = { diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer_test.js b/api/tests/organizational-entities/unit/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.test.js similarity index 94% rename from api/tests/unit/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer_test.js rename to api/tests/organizational-entities/unit/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.test.js index 567d4060994..9d8d51b8734 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer_test.js +++ b/api/tests/organizational-entities/unit/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.test.js @@ -1,7 +1,7 @@ -import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js'; -import { domainBuilder, expect } from '../../../../test-helper.js'; +import * as serializer from '../../../../../../../src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js'; +import { domainBuilder, expect } from '../../../../../../test-helper.js'; -describe('Unit | Serializer | JSONAPI | certification-center-for-admin-serializer', function () { +describe('Unit | Organizational Entities | Infrastructure | Serializer | JSONAPI | certification-center-for-admin-serializer', function () { let certificationCenterJsonApi; let centerForAdmin; let dataProtectionOfficer; From c97172daee2e8bfdc2750f4f6f0f1db2c36b2c02 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 11:54:22 +0100 Subject: [PATCH 06/10] refactor(api): move create certification center usecase in src/organizational-entities --- .../certification-center.admin.controller.js | 3 +-- .../create-certification-center.usecase.js} | 14 ++++++++++++-- .../domain/usecases/index.js | 10 ++++++++++ .../create-certification-center.usecase.test.js} | 14 +++++++------- 4 files changed, 30 insertions(+), 11 deletions(-) rename api/{lib/domain/usecases/create-certification-center.js => src/organizational-entities/domain/usecases/create-certification-center.usecase.js} (70%) rename api/tests/{unit/domain/usecases/create-certification-center_test.js => organizational-entities/unit/domain/usecases/create-certification-center.usecase.test.js} (84%) diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js index 277b63bf171..07dfb56b272 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js @@ -1,4 +1,3 @@ -import { usecases as libUsecases } from '../../../../lib/domain/usecases/index.js'; import { usecases } from '../../domain/usecases/index.js'; import * as certificationCenterSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center.serializer.js'; import * as certificationCenterForAdminSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js'; @@ -8,7 +7,7 @@ const create = async function (request) { const complementaryCertificationIds = request.payload.data.relationships?.habilitations?.data.map( (complementaryCertification) => complementaryCertification.id, ); - const createdCertificationCenter = await libUsecases.createCertificationCenter({ + const createdCertificationCenter = await usecases.createCertificationCenter({ certificationCenter, complementaryCertificationIds, }); diff --git a/api/lib/domain/usecases/create-certification-center.js b/api/src/organizational-entities/domain/usecases/create-certification-center.usecase.js similarity index 70% rename from api/lib/domain/usecases/create-certification-center.js rename to api/src/organizational-entities/domain/usecases/create-certification-center.usecase.js index a35926eb84d..e5ac978bff0 100644 --- a/api/lib/domain/usecases/create-certification-center.js +++ b/api/src/organizational-entities/domain/usecases/create-certification-center.usecase.js @@ -1,6 +1,16 @@ -import { ComplementaryCertificationHabilitation } from '../../../src/shared/domain/models/ComplementaryCertificationHabilitation.js'; -import * as certificationCenterCreationValidator from '../validators/certification-center-creation-validator.js'; +import * as certificationCenterCreationValidator from '../../../../lib/domain/validators/certification-center-creation-validator.js'; +import { ComplementaryCertificationHabilitation } from '../../../shared/domain/models/ComplementaryCertificationHabilitation.js'; +/** + * + * @param{object} params + * @param{CertificationCenter} params.certificationCenter + * @param{string[]} params.complementaryCertificationIds + * @param{ComplementaryCertificationHabilitationRepository} params.complementaryCertificationHabilitationRepository + * @param{CertificationCenterForAdminRepository} params.certificationCenterForAdminRepository + * @param{DataProtectionOfficerRepository} params.dataProtectionOfficerRepository + * @returns {Promise<*>} + */ const createCertificationCenter = async function ({ certificationCenter, complementaryCertificationIds, diff --git a/api/src/organizational-entities/domain/usecases/index.js b/api/src/organizational-entities/domain/usecases/index.js index 9680b9c2afb..a6e02452cd0 100644 --- a/api/src/organizational-entities/domain/usecases/index.js +++ b/api/src/organizational-entities/domain/usecases/index.js @@ -1,6 +1,9 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; +import * as certificationCenterForAdminRepository from '../../../../lib/infrastructure/repositories/certification-center-for-admin-repository.js'; +import * as complementaryCertificationHabilitationRepository from '../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js'; +import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import * as organizationTagRepository from '../../../../lib/infrastructure/repositories/organization-tag-repository.js'; import * as schoolRepository from '../../../school/infrastructure/repositories/school-repository.js'; import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js'; @@ -14,6 +17,9 @@ const path = dirname(fileURLToPath(import.meta.url)); /** * @typedef {import ('../../infrastructure/repositories/certification-center.repository.js')} CertificationCenterRepository + * @typedef {import ('../../../../lib/infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository + * @typedef {import ('../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository + * @typedef {import ('../../../../lib/infrastructure/repositories/data-protection-officer-repository.js')} DataProtectionOfficerRepository * @typedef {import ('../../infrastructure/repositories/organization-feature-repository.js')} OrganizationFeatureRepository * @typedef {import ('../../infrastructure/repositories/organization-for-admin.repository.js')} OrganizationForAdminRepository * @typedef {import ('../../infrastructure/repositories/tag.repository.js')} TagRepository @@ -22,6 +28,9 @@ const path = dirname(fileURLToPath(import.meta.url)); const repositories = { certificationCenterRepository, + certificationCenterForAdminRepository, + dataProtectionOfficerRepository, + complementaryCertificationHabilitationRepository, organizationForAdminRepository, organizationFeatureRepository, schoolRepository, @@ -39,6 +48,7 @@ const usecasesWithoutInjectedDependencies = { * @typedef OrganizationalEntitiesUsecases * @property {addOrganizationFeatureInBatch} addOrganizationFeatureInBatch * @property {attachChildOrganizationToOrganization} attachChildOrganizationToOrganization + * @property {createCertificationCenter} createCertificationCenter * @property {createTag} createTag * @property {findPaginatedFilteredCertificationCenters} findPaginatedFilteredCertificationCenters * @property {getOrganizationDetails} getOrganizationDetails diff --git a/api/tests/unit/domain/usecases/create-certification-center_test.js b/api/tests/organizational-entities/unit/domain/usecases/create-certification-center.usecase.test.js similarity index 84% rename from api/tests/unit/domain/usecases/create-certification-center_test.js rename to api/tests/organizational-entities/unit/domain/usecases/create-certification-center.usecase.test.js index f1b275346b1..a635493c357 100644 --- a/api/tests/unit/domain/usecases/create-certification-center_test.js +++ b/api/tests/organizational-entities/unit/domain/usecases/create-certification-center.usecase.test.js @@ -1,10 +1,10 @@ -import { createCertificationCenter } from '../../../../lib/domain/usecases/create-certification-center.js'; -import { DataProtectionOfficer } from '../../../../src/organizational-entities/domain/models/DataProtectionOfficer.js'; -import { domainBuilder, expect, sinon } from '../../../test-helper.js'; +import { DataProtectionOfficer } from '../../../../../src/organizational-entities/domain/models/DataProtectionOfficer.js'; +import { createCertificationCenter } from '../../../../../src/organizational-entities/domain/usecases/create-certification-center.usecase.js'; +import { domainBuilder, expect, sinon } from '../../../../test-helper.js'; -describe('Unit | UseCase | create-certification-center', function () { +describe('Unit | Organizational Entities | Domain | UseCase | create-certification-center', function () { describe('#createCertificationCenter', function () { - it('should save and return the certification center', async function () { + it('saves and returns the certification center', async function () { // given const certificationCenter = domainBuilder.buildCertificationCenter(); const certificationCenterForAdminRepository = { save: sinon.stub().returns(certificationCenter) }; @@ -35,7 +35,7 @@ describe('Unit | UseCase | create-certification-center', function () { expect(createdCertificationCenter).to.deepEqualInstance(certificationCenter); }); - it('should save the complementary certification habilitations', async function () { + it('saves the complementary certification habilitations', async function () { // given const certificationCenter = domainBuilder.buildCertificationCenter(); const complementaryCertificationIds = ['1234', '4567']; @@ -68,7 +68,7 @@ describe('Unit | UseCase | create-certification-center', function () { expect(complementaryCertificationHabilitationRepository.save).to.be.calledTwice; }); - it('should create a data protection officer while saving and returning the certification center', async function () { + it('creates a data protection officer while saving and returning the certification center', async function () { // given const certificationCenter = domainBuilder.buildCertificationCenter(); const dataProtectionOfficer = { From 513a6a3d832c9b1596602f33bd49dd5bdd6cbfe9 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 12:18:31 +0100 Subject: [PATCH 07/10] refactor(api): move certification center for admin repository in src/organizational-entities --- api/lib/domain/usecases/index.js | 2 +- .../organizational-entities/domain/usecases/index.js | 4 ++-- .../certification-center-for-admin.repository.js} | 4 ++-- .../usecases/update-certification-center_test.js | 2 +- ...certification-center-for-admin-repository_test.js | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) rename api/{lib/infrastructure/repositories/certification-center-for-admin-repository.js => src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js} (87%) rename api/tests/{ => organizational-entities}/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js (78%) diff --git a/api/lib/domain/usecases/index.js b/api/lib/domain/usecases/index.js index 16a633dc2c2..fc950ec8844 100644 --- a/api/lib/domain/usecases/index.js +++ b/api/lib/domain/usecases/index.js @@ -62,6 +62,7 @@ import { resetPasswordDemandRepository } from '../../../src/identity-access-mana import * as userRepository from '../../../src/identity-access-management/infrastructure/repositories/user.repository.js'; import { userEmailRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-email.repository.js'; import { userToCreateRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-to-create.repository.js'; +import * as certificationCenterForAdminRepository from '../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; import { organizationForAdminRepository } from '../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../../src/organizational-entities/infrastructure/repositories/tag.repository.js'; import * as campaignManagementRepository from '../../../src/prescription/campaign/infrastructure/repositories/campaign-management-repository.js'; @@ -128,7 +129,6 @@ import * as campaignParticipationRepository from '../../infrastructure/repositor import { campaignParticipationResultRepository } from '../../infrastructure/repositories/campaign-participation-result-repository.js'; import * as campaignRepository from '../../infrastructure/repositories/campaign-repository.js'; import * as certifiableProfileForLearningContentRepository from '../../infrastructure/repositories/certifiable-profile-for-learning-content-repository.js'; -import * as certificationCenterForAdminRepository from '../../infrastructure/repositories/certification-center-for-admin-repository.js'; import * as certificationPointOfContactRepository from '../../infrastructure/repositories/certification-point-of-contact-repository.js'; import * as certificationRepository from '../../infrastructure/repositories/certification-repository.js'; import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js'; diff --git a/api/src/organizational-entities/domain/usecases/index.js b/api/src/organizational-entities/domain/usecases/index.js index a6e02452cd0..e409609857c 100644 --- a/api/src/organizational-entities/domain/usecases/index.js +++ b/api/src/organizational-entities/domain/usecases/index.js @@ -1,7 +1,6 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import * as certificationCenterForAdminRepository from '../../../../lib/infrastructure/repositories/certification-center-for-admin-repository.js'; import * as complementaryCertificationHabilitationRepository from '../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js'; import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import * as organizationTagRepository from '../../../../lib/infrastructure/repositories/organization-tag-repository.js'; @@ -9,6 +8,7 @@ import * as schoolRepository from '../../../school/infrastructure/repositories/s import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js'; import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; import * as certificationCenterRepository from '../../infrastructure/repositories/certification-center.repository.js'; +import * as certificationCenterForAdminRepository from '../../infrastructure/repositories/certification-center-for-admin.repository.js'; import * as organizationFeatureRepository from '../../infrastructure/repositories/organization-feature-repository.js'; import { organizationForAdminRepository } from '../../infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../infrastructure/repositories/tag.repository.js'; @@ -17,7 +17,7 @@ const path = dirname(fileURLToPath(import.meta.url)); /** * @typedef {import ('../../infrastructure/repositories/certification-center.repository.js')} CertificationCenterRepository - * @typedef {import ('../../../../lib/infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository + * @typedef {import ('../../infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository * @typedef {import ('../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository * @typedef {import ('../../../../lib/infrastructure/repositories/data-protection-officer-repository.js')} DataProtectionOfficerRepository * @typedef {import ('../../infrastructure/repositories/organization-feature-repository.js')} OrganizationFeatureRepository diff --git a/api/lib/infrastructure/repositories/certification-center-for-admin-repository.js b/api/src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js similarity index 87% rename from api/lib/infrastructure/repositories/certification-center-for-admin-repository.js rename to api/src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js index e70ddfd1e31..d076c5dd0c1 100644 --- a/api/lib/infrastructure/repositories/certification-center-for-admin-repository.js +++ b/api/src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js @@ -1,5 +1,5 @@ -import { CenterForAdmin } from '../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; -import { DomainTransaction } from '../DomainTransaction.js'; +import { CenterForAdmin } from '../../../certification/enrolment/domain/models/CenterForAdmin.js'; +import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js'; const save = async function (certificationCenter) { const knexConn = DomainTransaction.getConnection(); diff --git a/api/tests/integration/domain/usecases/update-certification-center_test.js b/api/tests/integration/domain/usecases/update-certification-center_test.js index a31d69f8adc..104b7601f20 100644 --- a/api/tests/integration/domain/usecases/update-certification-center_test.js +++ b/api/tests/integration/domain/usecases/update-certification-center_test.js @@ -1,9 +1,9 @@ import { updateCertificationCenter } from '../../../../lib/domain/usecases/update-certification-center.js'; -import * as certificationCenterForAdminRepository from '../../../../lib/infrastructure/repositories/certification-center-for-admin-repository.js'; import * as complementaryCertificationHabilitationRepository from '../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js'; import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import { CenterForAdmin } from '../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; import * as centerRepository from '../../../../src/certification/enrolment/infrastructure/repositories/center-repository.js'; +import * as certificationCenterForAdminRepository from '../../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; import { databaseBuilder, domainBuilder, expect } from '../../../test-helper.js'; describe('Integration | UseCases | update-certification-center', function () { diff --git a/api/tests/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js b/api/tests/organizational-entities/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js similarity index 78% rename from api/tests/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js rename to api/tests/organizational-entities/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js index 91fc395c39f..3077152dc24 100644 --- a/api/tests/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js +++ b/api/tests/organizational-entities/integration/infrastructure/repositories/certification-center-for-admin-repository_test.js @@ -1,8 +1,8 @@ -import * as CertificationCenterForAdminRepository from '../../../../lib/infrastructure/repositories/certification-center-for-admin-repository.js'; -import { CenterForAdmin } from '../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; -import { databaseBuilder, expect, knex, sinon } from '../../../test-helper.js'; +import { CenterForAdmin } from '../../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; +import * as CertificationCenterForAdminRepository from '../../../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; +import { databaseBuilder, expect, knex, sinon } from '../../../../test-helper.js'; -describe('Integration | Repository | certification-center-for-admin', function () { +describe('Integration | Organizational Entities | Infrastructure | Repository | certification-center-for-admin', function () { let clock; const now = new Date('2021-11-16'); @@ -15,7 +15,7 @@ describe('Integration | Repository | certification-center-for-admin', function ( }); describe('#save', function () { - it('should save the given certification center', async function () { + it('saves the given certification center', async function () { // given const certificationCenterId = 1; const certificationCenterName = 'CertificationCenterName'; @@ -54,7 +54,7 @@ describe('Integration | Repository | certification-center-for-admin', function ( await databaseBuilder.commit(); }); - it('should update the given certification center', async function () { + it('updates the given certification center', async function () { // when await CertificationCenterForAdminRepository.update({ id: center.id, From 60c9d7a8491bf0f5385c5d7795a8ccb74e48021d Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 14:13:02 +0100 Subject: [PATCH 08/10] refactor(api): move complementary certification habilitation repository in src/organizational-entities --- api/lib/domain/usecases/index.js | 2 +- .../organizational-entities/domain/usecases/index.js | 4 ++-- ...lementary-certification-habilitation.repository.js} | 2 +- .../usecases/update-certification-center_test.js | 2 +- ...tary-certification-habilitation.repository.test.js} | 10 +++++----- 5 files changed, 10 insertions(+), 10 deletions(-) rename api/{lib/infrastructure/repositories/complementary-certification-habilitation-repository.js => src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js} (91%) rename api/tests/{integration/infrastructure/repositories/complementary-certification-habilitation-repository_test.js => organizational-entities/integration/infrastructure/repositories/complementary-certification-habilitation.repository.test.js} (84%) diff --git a/api/lib/domain/usecases/index.js b/api/lib/domain/usecases/index.js index fc950ec8844..7ca8b7d9ce1 100644 --- a/api/lib/domain/usecases/index.js +++ b/api/lib/domain/usecases/index.js @@ -63,6 +63,7 @@ import * as userRepository from '../../../src/identity-access-management/infrast import { userEmailRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-email.repository.js'; import { userToCreateRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-to-create.repository.js'; import * as certificationCenterForAdminRepository from '../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; +import * as complementaryCertificationHabilitationRepository from '../../../src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js'; import { organizationForAdminRepository } from '../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../../src/organizational-entities/infrastructure/repositories/tag.repository.js'; import * as campaignManagementRepository from '../../../src/prescription/campaign/infrastructure/repositories/campaign-management-repository.js'; @@ -132,7 +133,6 @@ import * as certifiableProfileForLearningContentRepository from '../../infrastru import * as certificationPointOfContactRepository from '../../infrastructure/repositories/certification-point-of-contact-repository.js'; import * as certificationRepository from '../../infrastructure/repositories/certification-repository.js'; import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js'; -import * as complementaryCertificationHabilitationRepository from '../../infrastructure/repositories/complementary-certification-habilitation-repository.js'; import * as dataProtectionOfficerRepository from '../../infrastructure/repositories/data-protection-officer-repository.js'; import * as flashAssessmentResultRepository from '../../infrastructure/repositories/flash-assessment-result-repository.js'; import * as frameworkRepository from '../../infrastructure/repositories/framework-repository.js'; diff --git a/api/src/organizational-entities/domain/usecases/index.js b/api/src/organizational-entities/domain/usecases/index.js index e409609857c..9dac136f0fd 100644 --- a/api/src/organizational-entities/domain/usecases/index.js +++ b/api/src/organizational-entities/domain/usecases/index.js @@ -1,7 +1,6 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import * as complementaryCertificationHabilitationRepository from '../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js'; import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import * as organizationTagRepository from '../../../../lib/infrastructure/repositories/organization-tag-repository.js'; import * as schoolRepository from '../../../school/infrastructure/repositories/school-repository.js'; @@ -9,6 +8,7 @@ import { injectDependencies } from '../../../shared/infrastructure/utils/depende import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; import * as certificationCenterRepository from '../../infrastructure/repositories/certification-center.repository.js'; import * as certificationCenterForAdminRepository from '../../infrastructure/repositories/certification-center-for-admin.repository.js'; +import * as complementaryCertificationHabilitationRepository from '../../infrastructure/repositories/complementary-certification-habilitation.repository.js'; import * as organizationFeatureRepository from '../../infrastructure/repositories/organization-feature-repository.js'; import { organizationForAdminRepository } from '../../infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../infrastructure/repositories/tag.repository.js'; @@ -18,7 +18,7 @@ const path = dirname(fileURLToPath(import.meta.url)); /** * @typedef {import ('../../infrastructure/repositories/certification-center.repository.js')} CertificationCenterRepository * @typedef {import ('../../infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository - * @typedef {import ('../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository + * @typedef {import ('../../infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository * @typedef {import ('../../../../lib/infrastructure/repositories/data-protection-officer-repository.js')} DataProtectionOfficerRepository * @typedef {import ('../../infrastructure/repositories/organization-feature-repository.js')} OrganizationFeatureRepository * @typedef {import ('../../infrastructure/repositories/organization-for-admin.repository.js')} OrganizationForAdminRepository diff --git a/api/lib/infrastructure/repositories/complementary-certification-habilitation-repository.js b/api/src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js similarity index 91% rename from api/lib/infrastructure/repositories/complementary-certification-habilitation-repository.js rename to api/src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js index 081b454d8c6..767d76bc17c 100644 --- a/api/lib/infrastructure/repositories/complementary-certification-habilitation-repository.js +++ b/api/src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js @@ -1,4 +1,4 @@ -import { DomainTransaction } from '../DomainTransaction.js'; +import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js'; const COMPLEMENTARY_CERTIFICATION_HABILITATIONS_TABLE_NAME = 'complementary-certification-habilitations'; diff --git a/api/tests/integration/domain/usecases/update-certification-center_test.js b/api/tests/integration/domain/usecases/update-certification-center_test.js index 104b7601f20..f1ef853b7e2 100644 --- a/api/tests/integration/domain/usecases/update-certification-center_test.js +++ b/api/tests/integration/domain/usecases/update-certification-center_test.js @@ -1,9 +1,9 @@ import { updateCertificationCenter } from '../../../../lib/domain/usecases/update-certification-center.js'; -import * as complementaryCertificationHabilitationRepository from '../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js'; import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import { CenterForAdmin } from '../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; import * as centerRepository from '../../../../src/certification/enrolment/infrastructure/repositories/center-repository.js'; import * as certificationCenterForAdminRepository from '../../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; +import * as complementaryCertificationHabilitationRepository from '../../../../src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js'; import { databaseBuilder, domainBuilder, expect } from '../../../test-helper.js'; describe('Integration | UseCases | update-certification-center', function () { diff --git a/api/tests/integration/infrastructure/repositories/complementary-certification-habilitation-repository_test.js b/api/tests/organizational-entities/integration/infrastructure/repositories/complementary-certification-habilitation.repository.test.js similarity index 84% rename from api/tests/integration/infrastructure/repositories/complementary-certification-habilitation-repository_test.js rename to api/tests/organizational-entities/integration/infrastructure/repositories/complementary-certification-habilitation.repository.test.js index 947b523e416..0105ef30ac1 100644 --- a/api/tests/integration/infrastructure/repositories/complementary-certification-habilitation-repository_test.js +++ b/api/tests/organizational-entities/integration/infrastructure/repositories/complementary-certification-habilitation.repository.test.js @@ -1,9 +1,9 @@ -import * as complementaryCertificationHabilitationRepository from '../../../../lib/infrastructure/repositories/complementary-certification-habilitation-repository.js'; -import { databaseBuilder, expect, knex } from '../../../test-helper.js'; +import * as complementaryCertificationHabilitationRepository from '../../../../../src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js'; +import { databaseBuilder, expect, knex } from '../../../../test-helper.js'; -describe('Integration | Infrastructure | Repository | complementary-certification-habilitation-repository', function () { +describe('Integration | Organizational Entities | Infrastructure | Repository | complementary-certification-habilitation', function () { context('#save', function () { - it('should create the complementary certitification habilitation', async function () { + it('creates the complementary certitification habilitation', async function () { // given const certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id; const complementaryCertificationId = databaseBuilder.factory.buildComplementaryCertification().id; @@ -26,7 +26,7 @@ describe('Integration | Infrastructure | Repository | complementary-certificatio }); context('#deleteByCertificationCenterId', function () { - it('should delete all complementary certitification habilitations for a given certification center id', async function () { + it('deletes all complementary certitification habilitations for a given certification center id', async function () { // given const certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id; const otherCertificationCenterId = databaseBuilder.factory.buildCertificationCenter().id; From 2515bafb390d2042d72ad0d20f1c274e9f7444c3 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Wed, 13 Nov 2024 14:20:16 +0100 Subject: [PATCH 09/10] refactor(api): move data protection officer repository in src/organizational-entities --- api/lib/domain/usecases/index.js | 2 +- ...nizations-with-tags-and-target-profiles.js | 2 +- .../domain/usecases/index.js | 4 +- .../data-protection-officer.repository.js} | 4 +- ...r-update-certification-centers-dpo-info.js | 2 +- .../usecases/create-organization_test.js | 2 +- ...ions-with-tags-and-target-profiles_test.js | 2 +- ...ata-protection-officer-information_test.js | 2 +- .../update-certification-center_test.js | 2 +- ...data-protection-officer-repository_test.js | 179 ------------------ ...data-protection-officer.repository.test.js | 173 +++++++++++++++++ 11 files changed, 184 insertions(+), 190 deletions(-) rename api/{lib/infrastructure/repositories/data-protection-officer-repository.js => src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js} (91%) delete mode 100644 api/tests/integration/infrastructure/repositories/data-protection-officer-repository_test.js create mode 100644 api/tests/organizational-entities/integration/infrastructure/repositories/data-protection-officer.repository.test.js diff --git a/api/lib/domain/usecases/index.js b/api/lib/domain/usecases/index.js index 7ca8b7d9ce1..b87ffa2189e 100644 --- a/api/lib/domain/usecases/index.js +++ b/api/lib/domain/usecases/index.js @@ -64,6 +64,7 @@ import { userEmailRepository } from '../../../src/identity-access-management/inf import { userToCreateRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-to-create.repository.js'; import * as certificationCenterForAdminRepository from '../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; import * as complementaryCertificationHabilitationRepository from '../../../src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js'; +import * as dataProtectionOfficerRepository from '../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; import { organizationForAdminRepository } from '../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../../src/organizational-entities/infrastructure/repositories/tag.repository.js'; import * as campaignManagementRepository from '../../../src/prescription/campaign/infrastructure/repositories/campaign-management-repository.js'; @@ -133,7 +134,6 @@ import * as certifiableProfileForLearningContentRepository from '../../infrastru import * as certificationPointOfContactRepository from '../../infrastructure/repositories/certification-point-of-contact-repository.js'; import * as certificationRepository from '../../infrastructure/repositories/certification-repository.js'; import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js'; -import * as dataProtectionOfficerRepository from '../../infrastructure/repositories/data-protection-officer-repository.js'; import * as flashAssessmentResultRepository from '../../infrastructure/repositories/flash-assessment-result-repository.js'; import * as frameworkRepository from '../../infrastructure/repositories/framework-repository.js'; import { repositories } from '../../infrastructure/repositories/index.js'; diff --git a/api/scripts/create-organizations-with-tags-and-target-profiles.js b/api/scripts/create-organizations-with-tags-and-target-profiles.js index 18977190e56..0d9548b9e2b 100644 --- a/api/scripts/create-organizations-with-tags-and-target-profiles.js +++ b/api/scripts/create-organizations-with-tags-and-target-profiles.js @@ -8,9 +8,9 @@ import { disconnect } from '../db/knex-database-connection.js'; import { createOrganizationsWithTagsAndTargetProfiles } from '../lib/domain/usecases/create-organizations-with-tags-and-target-profiles.js'; import * as organizationValidator from '../lib/domain/validators/organization-with-tags-and-target-profiles-script.js'; import { DomainTransaction as domainTransaction } from '../lib/infrastructure/DomainTransaction.js'; -import * as dataProtectionOfficerRepository from '../lib/infrastructure/repositories/data-protection-officer-repository.js'; import * as organizationTagRepository from '../lib/infrastructure/repositories/organization-tag-repository.js'; import * as targetProfileShareRepository from '../lib/infrastructure/repositories/target-profile-share-repository.js'; +import * as dataProtectionOfficerRepository from '../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; import { tagRepository } from '../src/organizational-entities/infrastructure/repositories/tag.repository.js'; import * as organizationRepository from '../src/shared/infrastructure/repositories/organization-repository.js'; import { temporaryStorage } from '../src/shared/infrastructure/temporary-storage/index.js'; diff --git a/api/src/organizational-entities/domain/usecases/index.js b/api/src/organizational-entities/domain/usecases/index.js index 9dac136f0fd..baea1f155a1 100644 --- a/api/src/organizational-entities/domain/usecases/index.js +++ b/api/src/organizational-entities/domain/usecases/index.js @@ -1,7 +1,6 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import * as organizationTagRepository from '../../../../lib/infrastructure/repositories/organization-tag-repository.js'; import * as schoolRepository from '../../../school/infrastructure/repositories/school-repository.js'; import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js'; @@ -9,6 +8,7 @@ import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/ import * as certificationCenterRepository from '../../infrastructure/repositories/certification-center.repository.js'; import * as certificationCenterForAdminRepository from '../../infrastructure/repositories/certification-center-for-admin.repository.js'; import * as complementaryCertificationHabilitationRepository from '../../infrastructure/repositories/complementary-certification-habilitation.repository.js'; +import * as dataProtectionOfficerRepository from '../../infrastructure/repositories/data-protection-officer.repository.js'; import * as organizationFeatureRepository from '../../infrastructure/repositories/organization-feature-repository.js'; import { organizationForAdminRepository } from '../../infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../infrastructure/repositories/tag.repository.js'; @@ -19,7 +19,7 @@ const path = dirname(fileURLToPath(import.meta.url)); * @typedef {import ('../../infrastructure/repositories/certification-center.repository.js')} CertificationCenterRepository * @typedef {import ('../../infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository * @typedef {import ('../../infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository - * @typedef {import ('../../../../lib/infrastructure/repositories/data-protection-officer-repository.js')} DataProtectionOfficerRepository + * @typedef {import ('../../infrastructure/repositories/data-protection-officer-repository.js')} DataProtectionOfficerRepository * @typedef {import ('../../infrastructure/repositories/organization-feature-repository.js')} OrganizationFeatureRepository * @typedef {import ('../../infrastructure/repositories/organization-for-admin.repository.js')} OrganizationForAdminRepository * @typedef {import ('../../infrastructure/repositories/tag.repository.js')} TagRepository diff --git a/api/lib/infrastructure/repositories/data-protection-officer-repository.js b/api/src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js similarity index 91% rename from api/lib/infrastructure/repositories/data-protection-officer-repository.js rename to api/src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js index 80c81057705..48145d3ffc5 100644 --- a/api/lib/infrastructure/repositories/data-protection-officer-repository.js +++ b/api/src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js @@ -1,5 +1,5 @@ -import { DataProtectionOfficer } from '../../../src/organizational-entities/domain/models/DataProtectionOfficer.js'; -import { DomainTransaction } from '../DomainTransaction.js'; +import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js'; +import { DataProtectionOfficer } from '../../domain/models/DataProtectionOfficer.js'; const DATA_PROTECTION_OFFICERS_TABLE_NAME = 'data-protection-officers'; diff --git a/api/src/organizational-entities/scripts/add-or-update-certification-centers-dpo-info.js b/api/src/organizational-entities/scripts/add-or-update-certification-centers-dpo-info.js index 615ab1f354f..fffd28e5481 100644 --- a/api/src/organizational-entities/scripts/add-or-update-certification-centers-dpo-info.js +++ b/api/src/organizational-entities/scripts/add-or-update-certification-centers-dpo-info.js @@ -1,10 +1,10 @@ import Joi from 'joi'; import { updateCertificationCenterDataProtectionOfficerInformation } from '../../../lib/domain/usecases/update-certification-center-data-protection-officer-information.js'; -import * as dataProtectionOfficerRepository from '../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import { csvFileParser } from '../../shared/application/scripts/parsers.js'; import { Script } from '../../shared/application/scripts/script.js'; import { ScriptRunner } from '../../shared/application/scripts/script-runner.js'; +import * as dataProtectionOfficerRepository from '../infrastructure/repositories/data-protection-officer.repository.js'; const columnsSchemas = [ { name: 'certificationCenterId', schema: Joi.number() }, diff --git a/api/tests/integration/domain/usecases/create-organization_test.js b/api/tests/integration/domain/usecases/create-organization_test.js index 466e493f529..ec5a3a8a411 100644 --- a/api/tests/integration/domain/usecases/create-organization_test.js +++ b/api/tests/integration/domain/usecases/create-organization_test.js @@ -1,7 +1,7 @@ import { createOrganization } from '../../../../lib/domain/usecases/create-organization.js'; import * as organizationCreationValidator from '../../../../lib/domain/validators/organization-creation-validator.js'; -import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import { OrganizationForAdmin } from '../../../../src/organizational-entities/domain/models/OrganizationForAdmin.js'; +import * as dataProtectionOfficerRepository from '../../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; import { organizationForAdminRepository } from '../../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js'; import * as schoolRepository from '../../../../src/school/infrastructure/repositories/school-repository.js'; import { databaseBuilder, expect } from '../../../test-helper.js'; diff --git a/api/tests/integration/domain/usecases/create-organizations-with-tags-and-target-profiles_test.js b/api/tests/integration/domain/usecases/create-organizations-with-tags-and-target-profiles_test.js index b19f618288f..8216e9613e0 100644 --- a/api/tests/integration/domain/usecases/create-organizations-with-tags-and-target-profiles_test.js +++ b/api/tests/integration/domain/usecases/create-organizations-with-tags-and-target-profiles_test.js @@ -2,9 +2,9 @@ import lodash from 'lodash'; import { createOrganizationsWithTagsAndTargetProfiles } from '../../../../lib/domain/usecases/create-organizations-with-tags-and-target-profiles.js'; import * as organizationValidator from '../../../../lib/domain/validators/organization-with-tags-and-target-profiles-script.js'; -import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import * as organizationTagRepository from '../../../../lib/infrastructure/repositories/organization-tag-repository.js'; import * as targetProfileShareRepository from '../../../../lib/infrastructure/repositories/target-profile-share-repository.js'; +import * as dataProtectionOfficerRepository from '../../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; import { organizationForAdminRepository } from '../../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js'; import { tagRepository } from '../../../../src/organizational-entities/infrastructure/repositories/tag.repository.js'; import * as schoolRepository from '../../../../src/school/infrastructure/repositories/school-repository.js'; diff --git a/api/tests/integration/domain/usecases/update-certification-center-data-protection-officer-information_test.js b/api/tests/integration/domain/usecases/update-certification-center-data-protection-officer-information_test.js index 89484d3e768..087c0066147 100644 --- a/api/tests/integration/domain/usecases/update-certification-center-data-protection-officer-information_test.js +++ b/api/tests/integration/domain/usecases/update-certification-center-data-protection-officer-information_test.js @@ -1,6 +1,6 @@ import { updateCertificationCenterDataProtectionOfficerInformation } from '../../../../lib/domain/usecases/update-certification-center-data-protection-officer-information.js'; -import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import { DataProtectionOfficer } from '../../../../src/organizational-entities/domain/models/DataProtectionOfficer.js'; +import * as dataProtectionOfficerRepository from '../../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; import { databaseBuilder, expect } from '../../../test-helper.js'; describe('Integration | UseCases | update-certification-center-data-protection-officer-information', function () { diff --git a/api/tests/integration/domain/usecases/update-certification-center_test.js b/api/tests/integration/domain/usecases/update-certification-center_test.js index f1ef853b7e2..4c6342d6386 100644 --- a/api/tests/integration/domain/usecases/update-certification-center_test.js +++ b/api/tests/integration/domain/usecases/update-certification-center_test.js @@ -1,9 +1,9 @@ import { updateCertificationCenter } from '../../../../lib/domain/usecases/update-certification-center.js'; -import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; import { CenterForAdmin } from '../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; import * as centerRepository from '../../../../src/certification/enrolment/infrastructure/repositories/center-repository.js'; import * as certificationCenterForAdminRepository from '../../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js'; import * as complementaryCertificationHabilitationRepository from '../../../../src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js'; +import * as dataProtectionOfficerRepository from '../../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; import { databaseBuilder, domainBuilder, expect } from '../../../test-helper.js'; describe('Integration | UseCases | update-certification-center', function () { diff --git a/api/tests/integration/infrastructure/repositories/data-protection-officer-repository_test.js b/api/tests/integration/infrastructure/repositories/data-protection-officer-repository_test.js deleted file mode 100644 index cddeafe254f..00000000000 --- a/api/tests/integration/infrastructure/repositories/data-protection-officer-repository_test.js +++ /dev/null @@ -1,179 +0,0 @@ -import * as dataProtectionOfficerRepository from '../../../../lib/infrastructure/repositories/data-protection-officer-repository.js'; -import { DataProtectionOfficer } from '../../../../src/organizational-entities/domain/models/DataProtectionOfficer.js'; -import { databaseBuilder, expect, knex } from '../../../test-helper.js'; - -describe('Integration | Repository | data-protection-officer', function () { - const now = new Date('2022-09-27T16:30:00Z'); - - describe('#batchAddDataProtectionOfficerToOrganization', function () { - it('should add rows in the table "data-protection-officers"', async function () { - // given - const firstOrganization = databaseBuilder.factory.buildOrganization(); - const secondOrganization = databaseBuilder.factory.buildOrganization(); - - await databaseBuilder.commit(); - - const dataProtectionOfficerA = { - firstName: 'Djamal', - lastName: 'Dormi', - email: 'test@example.net', - organizationId: firstOrganization.id, - }; - const dataProtectionOfficerB = { - firstName: 'Alain', - lastName: 'Terieur', - email: 'test@example.net', - organizationId: secondOrganization.id, - }; - - // when - await dataProtectionOfficerRepository.batchAddDataProtectionOfficerToOrganization([ - dataProtectionOfficerA, - dataProtectionOfficerB, - ]); - - // then - const foundDataProtectionOfficers = await knex('data-protection-officers').select(); - expect(foundDataProtectionOfficers.length).to.equal(2); - expect(foundDataProtectionOfficers[0]).to.contain({ - ...dataProtectionOfficerA, - organizationId: firstOrganization.id, - }); - expect(foundDataProtectionOfficers[1]).to.contain({ - ...dataProtectionOfficerB, - organizationId: secondOrganization.id, - }); - }); - }); - - describe('#create', function () { - context('on success', function () { - it('should return a DPO domain object', async function () { - // given - const user = databaseBuilder.factory.buildUser(); - const organization = databaseBuilder.factory.buildOrganization({ - name: 'InYak', - createdBy: user.id, - }); - await databaseBuilder.commit(); - - // when - const dataProtectionOfficer = new DataProtectionOfficer({ - firstName: 'Justin', - lastName: 'Ptipeu', - email: 'justin.ptipeu@example.net', - organizationId: organization.id, - }); - const dataProtectionOfficerSaved = await dataProtectionOfficerRepository.create(dataProtectionOfficer); - - // then - expect(dataProtectionOfficerSaved).to.be.an.instanceof(DataProtectionOfficer); - expect(dataProtectionOfficerSaved).to.deep.equal({ - id: dataProtectionOfficerSaved.id, - firstName: 'Justin', - lastName: 'Ptipeu', - email: 'justin.ptipeu@example.net', - organizationId: organization.id, - certificationCenterId: null, - createdAt: dataProtectionOfficerSaved.createdAt, - updatedAt: dataProtectionOfficerSaved.updatedAt, - }); - }); - }); - }); - - describe('#get', function () { - context('on success', function () { - context('when DPO exists', function () { - it('should return a DPO domain object', async function () { - // given - const user = databaseBuilder.factory.buildUser(); - const organization = databaseBuilder.factory.buildOrganization({ - name: 'InYak', - createdBy: user.id, - }); - const dataProtectionOfficer = databaseBuilder.factory.buildDataProtectionOfficer.withOrganizationId({ - firstName: 'Justin', - lastName: 'Ptipeu', - email: 'justin.ptipeu@example.net', - organizationId: organization.id, - }); - await databaseBuilder.commit(); - - // when - const dataProtectionOfficerFound = await dataProtectionOfficerRepository.get({ - organizationId: organization.id, - }); - - // then - expect(dataProtectionOfficerFound).to.be.an.instanceof(DataProtectionOfficer); - expect(dataProtectionOfficerFound).to.deep.equal({ - id: dataProtectionOfficer.id, - firstName: 'Justin', - lastName: 'Ptipeu', - email: 'justin.ptipeu@example.net', - organizationId: organization.id, - certificationCenterId: null, - createdAt: dataProtectionOfficer.createdAt, - updatedAt: dataProtectionOfficer.updatedAt, - }); - }); - }); - - context('when DPO does not exist', function () { - it('should return undefined', async function () { - // given & when - const dataProtectionOfficerFound = await dataProtectionOfficerRepository.get({ organizationId: 1234 }); - - // then - expect(dataProtectionOfficerFound).to.be.undefined; - }); - }); - }); - }); - - describe('#update', function () { - context('on success', function () { - it('should return a DPO domain object', async function () { - // given - const user = databaseBuilder.factory.buildUser(); - const organization = databaseBuilder.factory.buildOrganization({ - name: 'UruYak', - createdBy: user.id, - }); - const dataProtectionOfficer = databaseBuilder.factory.buildDataProtectionOfficer.withOrganizationId({ - firstName: 'Justin', - lastName: 'Ptipeu', - email: 'justin.ptipeu@example.net', - organizationId: organization.id, - createdAt: now, - updatedAt: now, - }); - await databaseBuilder.commit(); - - // when - const dataProtectionOfficerToUpdate = new DataProtectionOfficer({ - id: dataProtectionOfficer.id, - firstName: '', - lastName: '', - email: '', - organizationId: organization.id, - }); - const dataProtectionOfficerSaved = await dataProtectionOfficerRepository.update(dataProtectionOfficerToUpdate); - - // then - expect(dataProtectionOfficerSaved).to.be.an.instanceof(DataProtectionOfficer); - expect(dataProtectionOfficerSaved).to.deep.equal({ - id: dataProtectionOfficerSaved.id, - firstName: '', - lastName: '', - email: '', - organizationId: organization.id, - certificationCenterId: null, - createdAt: now, - updatedAt: dataProtectionOfficerSaved.updatedAt, - }); - }); - }); - }); -}); diff --git a/api/tests/organizational-entities/integration/infrastructure/repositories/data-protection-officer.repository.test.js b/api/tests/organizational-entities/integration/infrastructure/repositories/data-protection-officer.repository.test.js new file mode 100644 index 00000000000..e2c4667affe --- /dev/null +++ b/api/tests/organizational-entities/integration/infrastructure/repositories/data-protection-officer.repository.test.js @@ -0,0 +1,173 @@ +import { DataProtectionOfficer } from '../../../../../src/organizational-entities/domain/models/DataProtectionOfficer.js'; +import * as dataProtectionOfficerRepository from '../../../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js'; +import { databaseBuilder, expect, knex } from '../../../../test-helper.js'; + +describe('Integration | Organizational Entities | Repository | data-protection-officer', function () { + const now = new Date('2022-09-27T16:30:00Z'); + + describe('#batchAddDataProtectionOfficerToOrganization', function () { + it('adds rows in the table "data-protection-officers"', async function () { + // given + const firstOrganization = databaseBuilder.factory.buildOrganization(); + const secondOrganization = databaseBuilder.factory.buildOrganization(); + + await databaseBuilder.commit(); + + const dataProtectionOfficerA = { + firstName: 'Djamal', + lastName: 'Dormi', + email: 'test@example.net', + organizationId: firstOrganization.id, + }; + const dataProtectionOfficerB = { + firstName: 'Alain', + lastName: 'Terieur', + email: 'test@example.net', + organizationId: secondOrganization.id, + }; + + // when + await dataProtectionOfficerRepository.batchAddDataProtectionOfficerToOrganization([ + dataProtectionOfficerA, + dataProtectionOfficerB, + ]); + + // then + const foundDataProtectionOfficers = await knex('data-protection-officers').select(); + expect(foundDataProtectionOfficers.length).to.equal(2); + expect(foundDataProtectionOfficers[0]).to.contain({ + ...dataProtectionOfficerA, + organizationId: firstOrganization.id, + }); + expect(foundDataProtectionOfficers[1]).to.contain({ + ...dataProtectionOfficerB, + organizationId: secondOrganization.id, + }); + }); + }); + + describe('#create', function () { + it('returns a DPO domain object', async function () { + // given + const user = databaseBuilder.factory.buildUser(); + const organization = databaseBuilder.factory.buildOrganization({ + name: 'InYak', + createdBy: user.id, + }); + await databaseBuilder.commit(); + + // when + const dataProtectionOfficer = new DataProtectionOfficer({ + firstName: 'Justin', + lastName: 'Ptipeu', + email: 'justin.ptipeu@example.net', + organizationId: organization.id, + }); + const dataProtectionOfficerSaved = await dataProtectionOfficerRepository.create(dataProtectionOfficer); + + // then + expect(dataProtectionOfficerSaved).to.be.an.instanceof(DataProtectionOfficer); + expect(dataProtectionOfficerSaved).to.deep.equal({ + id: dataProtectionOfficerSaved.id, + firstName: 'Justin', + lastName: 'Ptipeu', + email: 'justin.ptipeu@example.net', + organizationId: organization.id, + certificationCenterId: null, + createdAt: dataProtectionOfficerSaved.createdAt, + updatedAt: dataProtectionOfficerSaved.updatedAt, + }); + }); + }); + + describe('#get', function () { + context('when DPO exists', function () { + it('returns a DPO domain object', async function () { + // given + const user = databaseBuilder.factory.buildUser(); + const organization = databaseBuilder.factory.buildOrganization({ + name: 'InYak', + createdBy: user.id, + }); + const dataProtectionOfficer = databaseBuilder.factory.buildDataProtectionOfficer.withOrganizationId({ + firstName: 'Justin', + lastName: 'Ptipeu', + email: 'justin.ptipeu@example.net', + organizationId: organization.id, + }); + await databaseBuilder.commit(); + + // when + const dataProtectionOfficerFound = await dataProtectionOfficerRepository.get({ + organizationId: organization.id, + }); + + // then + expect(dataProtectionOfficerFound).to.be.an.instanceof(DataProtectionOfficer); + expect(dataProtectionOfficerFound).to.deep.equal({ + id: dataProtectionOfficer.id, + firstName: 'Justin', + lastName: 'Ptipeu', + email: 'justin.ptipeu@example.net', + organizationId: organization.id, + certificationCenterId: null, + createdAt: dataProtectionOfficer.createdAt, + updatedAt: dataProtectionOfficer.updatedAt, + }); + }); + }); + + context('when DPO does not exist', function () { + it('returns undefined', async function () { + // given & when + const dataProtectionOfficerFound = await dataProtectionOfficerRepository.get({ organizationId: 1234 }); + + // then + expect(dataProtectionOfficerFound).to.be.undefined; + }); + }); + }); + + describe('#update', function () { + it('returns a DPO domain object', async function () { + // given + const user = databaseBuilder.factory.buildUser(); + const organization = databaseBuilder.factory.buildOrganization({ + name: 'UruYak', + createdBy: user.id, + }); + const dataProtectionOfficer = databaseBuilder.factory.buildDataProtectionOfficer.withOrganizationId({ + firstName: 'Justin', + lastName: 'Ptipeu', + email: 'justin.ptipeu@example.net', + organizationId: organization.id, + createdAt: now, + updatedAt: now, + }); + await databaseBuilder.commit(); + + // when + const dataProtectionOfficerToUpdate = new DataProtectionOfficer({ + id: dataProtectionOfficer.id, + firstName: '', + lastName: '', + email: '', + organizationId: organization.id, + }); + const dataProtectionOfficerSaved = await dataProtectionOfficerRepository.update(dataProtectionOfficerToUpdate); + + // then + expect(dataProtectionOfficerSaved).to.be.an.instanceof(DataProtectionOfficer); + expect(dataProtectionOfficerSaved).to.deep.equal({ + id: dataProtectionOfficerSaved.id, + firstName: '', + lastName: '', + email: '', + organizationId: organization.id, + certificationCenterId: null, + createdAt: now, + updatedAt: dataProtectionOfficerSaved.updatedAt, + }); + }); + }); +}); From 0cbf4d60ec8e61e9665b0567d83f0b0af6882c24 Mon Sep 17 00:00:00 2001 From: Eric Lim Date: Mon, 18 Nov 2024 14:55:20 +0100 Subject: [PATCH 10/10] refactor(api): add unit test for create controller --- .../certification-center.admin.controller.js | 7 +- ...tification-center.admin.controller.test.js | 119 +++++++++++++++++- 2 files changed, 122 insertions(+), 4 deletions(-) diff --git a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js index 07dfb56b272..25c686a8b3c 100644 --- a/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js +++ b/api/src/organizational-entities/application/certification-center/certification-center.admin.controller.js @@ -4,9 +4,10 @@ import * as certificationCenterForAdminSerializer from '../../infrastructure/ser const create = async function (request) { const certificationCenter = certificationCenterForAdminSerializer.deserialize(request.payload); - const complementaryCertificationIds = request.payload.data.relationships?.habilitations?.data.map( - (complementaryCertification) => complementaryCertification.id, - ); + const complementaryCertificationIds = + request.payload.data.relationships?.habilitations?.data.map( + (complementaryCertification) => complementaryCertification.id, + ) || []; const createdCertificationCenter = await usecases.createCertificationCenter({ certificationCenter, complementaryCertificationIds, diff --git a/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js b/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js index 788ef04227e..af7fb9c159c 100644 --- a/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js +++ b/api/tests/organizational-entities/unit/application/certification-center/certification-center.admin.controller.test.js @@ -1,10 +1,127 @@ +import { CenterForAdmin } from '../../../../../src/certification/enrolment/domain/models/CenterForAdmin.js'; import { certificationCenterAdminController } from '../../../../../src/organizational-entities/application/certification-center/certification-center.admin.controller.js'; import { usecases } from '../../../../../src/organizational-entities/domain/usecases/index.js'; import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Organizational Entities | Application | Controller | Admin | certification center', function () { + describe('#create', function () { + let request; + + context('when payload contains all certification center fields', function () { + beforeEach(function () { + request = { + payload: { + data: { + attributes: { + name: 'name', + type: 'PRO', + 'data-protection-officer-email': 'email@example.net', + 'data-protection-officer-first-name': 'Firstname', + 'data-protection-officer-last-name': 'Lastname', + 'external-id': '12345', + 'is-complementary-alone-pilot': true, + 'is-v3-pilot': false, + }, + id: '1', + relationships: { + habilitations: { + data: [ + { + id: '2', + type: 'complementary-certifications', + }, + { + id: '3', + type: 'complementary-certifications', + }, + ], + }, + }, + }, + }, + }; + }); + + it('calls "createCertificationCenter" use case with the right parameters', async function () { + // given + const createCertificationCenterStub = sinon.stub(usecases, 'createCertificationCenter'); + + // when + await certificationCenterAdminController.create(request); + + // then + const center = { + id: '1', + createdAt: null, + externalId: '12345', + habilitations: [], + isV3Pilot: false, + isComplementaryAlonePilot: true, + name: 'name', + type: 'PRO', + }; + const dataProtectionOfficer = { + firstName: 'Firstname', + lastName: 'Lastname', + email: 'email@example.net', + }; + const expectedCenterForAdmin = new CenterForAdmin({ + center, + dataProtectionOfficer, + }); + const expectedComplementaryCertificationIds = ['2', '3']; + + expect(createCertificationCenterStub).to.have.been.calledOnceWith({ + certificationCenter: expectedCenterForAdmin, + complementaryCertificationIds: expectedComplementaryCertificationIds, + }); + }); + }); + context('when payload contains only required fields', function () { + beforeEach(function () { + request = { + payload: { + data: { + attributes: { + name: 'name', + type: 'PRO', + 'external-id': null, + }, + }, + }, + }; + }); + + it('calls "createCertificationCenter" use case with the right parameters', async function () { + // given + const createCertificationCenterStub = sinon.stub(usecases, 'createCertificationCenter'); + + // when + await certificationCenterAdminController.create(request); + + // then + const center = { + createdAt: null, + externalId: null, + name: 'name', + type: 'PRO', + }; + const dataProtectionOfficer = {}; + const expectedCenterForAdmin = new CenterForAdmin({ + center, + dataProtectionOfficer, + }); + + expect(createCertificationCenterStub).to.have.been.calledOnceWith({ + certificationCenter: expectedCenterForAdmin, + complementaryCertificationIds: [], + }); + }); + }); + }); + describe('#findPaginatedFilteredCertificationCenters', function () { - it('should return the serialized certification centers', async function () { + it('returns the serialized certification centers', async function () { // given const certificationCenter1 = domainBuilder.buildCertificationCenter(); const serializedCertificationCenters = Symbol('serialized certification centers and pagination as meta');