Skip to content

Commit

Permalink
[TECH] Migrer la route GET /api/admin/certification-centers/{id} dans…
Browse files Browse the repository at this point in the history
… src (PIX-15465)

 #10652
  • Loading branch information
pix-service-auto-merge authored Nov 27, 2024
2 parents 809830e + e12f3bf commit b19d129
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ const update = async function (request) {
return certificationCenterForAdminSerializer.serialize(updatedCertificationCenter, certificationCenterPilotFeatures);
};

const getCertificationCenterDetails = async function (request) {
const certificationCenterId = request.params.id;

const certificationCenterDetails = await usecases.getCenterForAdmin({ id: certificationCenterId });

return certificationCenterForAdminSerializer.serialize(certificationCenterDetails);
};

const findPaginatedSessionSummaries = async function (request) {
const certificationCenterId = request.params.id;
const userId = request.auth.credentials.userId;
Expand Down Expand Up @@ -133,7 +125,6 @@ const certificationCenterController = {
createCertificationCenterMembershipByEmail,
findCertificationCenterMembershipsByCertificationCenter,
findPaginatedSessionSummaries,
getCertificationCenterDetails,
getDivisions,
getStudents,
update,
Expand Down
29 changes: 0 additions & 29 deletions api/lib/application/certification-centers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,6 @@ import { certificationCenterController } from './certification-center-controller

const register = async function (server) {
const adminRoutes = [
{
method: 'GET',
path: '/api/admin/certification-centers/{id}',
config: {
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
securityPreHandlers.checkAdminMemberHasRoleMetier,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
validate: {
params: Joi.object({
id: identifiersType.certificationCenterId,
}),
},
handler: certificationCenterController.getCertificationCenterDetails,
notes: [
"- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" +
"- Récupération d'un centre de certification\n",
],
tags: ['api', 'certification-center'],
},
},
{
method: 'GET',
path: '/api/admin/certification-centers/{certificationCenterId}/certification-center-memberships',
Expand Down
2 changes: 0 additions & 2 deletions api/lib/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { fileURLToPath } from 'node:url';

import * as complementaryCertificationRepository from '../../../src/certification/complementary-certification/infrastructure/repositories/complementary-certification-repository.js';
import * as sessionCodeService from '../../../src/certification/enrolment/domain/services/session-code-service.js';
import { getCenterForAdmin } from '../../../src/certification/enrolment/domain/usecases/get-center-for-admin.js';
import * as centerRepository from '../../../src/certification/enrolment/infrastructure/repositories/center-repository.js';
import * as certificationCpfCityRepository from '../../../src/certification/enrolment/infrastructure/repositories/certification-cpf-city-repository.js';
import * as sessionEnrolmentRepository from '../../../src/certification/enrolment/infrastructure/repositories/session-repository.js';
Expand Down Expand Up @@ -355,7 +354,6 @@ const path = dirname(fileURLToPath(import.meta.url));
const usecasesWithoutInjectedDependencies = {
...(await importNamedExportsFromDirectory({ path: join(path, './'), ignoredFileNames: ['index.js'] })),
...(await importNamedExportsFromDirectory({ path: join(path, './stages') })),
getCenterForAdmin,
};

const usecases = injectDependencies(usecasesWithoutInjectedDependencies, dependencies);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as organizationLearnerRepository from '../../../../../lib/infrastructure/repositories/organization-learner-repository.js';
import * as dataProtectionOfficerRepository from '../../../../organizational-entities/infrastructure/repositories/data-protection-officer.repository.js';
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
import * as complementaryCertificationApi from '../../../complementary-certification/application/api/complementary-certification-api.js';
import * as sessionManagementRepository from '../../../session-management/infrastructure/repositories/session-repository.js';
Expand Down Expand Up @@ -36,6 +37,7 @@ import * as sessionRepository from './session-repository.js';
* @typedef {countryRepository} CountryRepository
* @typedef {enrolledCandidateRepository} EnrolledCandidateRepository
* @typedef {scoCertificationCandidateRepository} ScoCertificationCandidateRepository
* @typedef {dataProtectionOfficerRepository} DataProtectionOfficerRepository
* @typedef {organizationLearnerRepository} OrganizationLearnerRepository
* @typedef {userRepository} UserRepository
* @typedef {targetProfileHistoryRepository} TargetProfileHistoryRepository
Expand All @@ -52,6 +54,7 @@ const repositoriesWithoutInjectedDependencies = {
certificationCpfCityRepository,
complementaryCertificationRepository,
countryRepository,
dataProtectionOfficerRepository,
enrolledCandidateRepository,
scoCertificationCandidateRepository,
sessionForAttendanceSheetRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { usecases as certificationUsecases } from '../../../certification/enrolment/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';
Expand Down Expand Up @@ -29,9 +30,18 @@ const findPaginatedFilteredCertificationCenters = async function (
return dependencies.certificationCenterSerializer.serialize(organizations, pagination);
};

const getCertificationCenterDetails = async function (request) {
const certificationCenterId = request.params.id;

const certificationCenterDetails = await certificationUsecases.getCenterForAdmin({ id: certificationCenterId });

return certificationCenterForAdminSerializer.serialize(certificationCenterDetails);
};

const certificationCenterAdminController = {
create,
findPaginatedFilteredCertificationCenters,
getCertificationCenterDetails,
};

export { certificationCenterAdminController };
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi';

import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js';
import { identifiersType, optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js';
import { certificationCenterAdminController } from './certification-center.admin.controller.js';

const register = async function (server) {
Expand Down Expand Up @@ -68,6 +68,35 @@ const register = async function (server) {
tags: ['api', 'organizational-entities', 'certification-center'],
},
},
{
method: 'GET',
path: '/api/admin/certification-centers/{id}',
config: {
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
securityPreHandlers.checkAdminMemberHasRoleMetier,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
validate: {
params: Joi.object({
id: identifiersType.certificationCenterId,
}),
},
handler: certificationCenterAdminController.getCertificationCenterDetails,
notes: [
"- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" +
"- Récupération d'un centre de certification\n",
],
tags: ['api', 'organizational-entities', 'certification-center'],
},
},
]);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,126 +17,6 @@ describe('Acceptance | API | Certification Center', function () {
await insertUserWithRoleSuperAdmin();
});

describe('GET /api/admin/certification-centers/{id}', function () {
let expectedCertificationCenter;

beforeEach(async function () {
expectedCertificationCenter = databaseBuilder.factory.buildCertificationCenter({ id: 1234 });
databaseBuilder.factory.buildComplementaryCertification({
id: 4567,
key: 'certif comp',
label: 'Une Certif Comp',
});
databaseBuilder.factory.buildComplementaryCertificationHabilitation({
certificationCenterId: 1234,
complementaryCertificationId: 4567,
});
databaseBuilder.factory.buildCertificationCenter({});
await databaseBuilder.commit();
request = {
method: 'GET',
url: '/api/admin/certification-centers/' + expectedCertificationCenter.id,
};
});

context('when user is Super Admin', function () {
beforeEach(function () {
request.headers = { authorization: generateValidRequestAuthorizationHeader() };
});

it('should return 200 HTTP status', async function () {
// when
const response = await server.inject(request);

// then
expect(response.statusCode).to.equal(200);
});

it('should return the certification center asked', async function () {
// when
const response = await server.inject(request);

// then
expect(response.result).to.deep.equal({
data: {
type: 'certification-centers',
id: '1234',
attributes: {
name: 'some name',
type: 'SUP',
'external-id': 'EX123',
'created-at': undefined,
'data-protection-officer-first-name': undefined,
'data-protection-officer-last-name': undefined,
'data-protection-officer-email': undefined,
'is-v3-pilot': false,
'is-complementary-alone-pilot': false,
},
relationships: {
'certification-center-memberships': {
links: {
related: '/api/admin/certification-centers/1234/certification-center-memberships',
},
},
habilitations: {
data: [
{
id: '4567',
type: 'complementary-certifications',
},
],
},
},
},
included: [
{
id: '4567',
type: 'complementary-certifications',
attributes: { key: 'certif comp', label: 'Une Certif Comp' },
},
],
});
});

it('should return notFoundError when the certificationCenter not exist', async function () {
// given
request.url = '/api/admin/certification-centers/112334';

// when
const response = await server.inject(request);

// then
expect(response.statusCode).to.equal(404);
expect(response.result.errors[0].title).to.equal('Not Found');
expect(response.result.errors[0].detail).to.equal('Center not found');
});
});

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);
});
});
});

describe('GET /api/certification-centers/{certificationCenterId}/sessions/{sessionId}/divisions', function () {
it('should return the divisions', async function () {
// given
Expand Down
Loading

0 comments on commit b19d129

Please sign in to comment.