Skip to content

Commit

Permalink
[TECH] 🚚 Déplacement de la route session-summaries vers src
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Dec 17, 2024
2 parents e035694 + 17c1234 commit 9624811
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,8 @@ import * as divisionSerializer from '../../../src/prescription/campaign/infrastr
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 * as sessionSummarySerializer from '../../infrastructure/serializers/jsonapi/session-summary-serializer.js';
import * as studentCertificationSerializer from '../../infrastructure/serializers/jsonapi/student-certification-serializer.js';

const findPaginatedSessionSummaries = async function (request) {
const certificationCenterId = request.params.id;
const userId = request.auth.credentials.userId;
const options = request.query;

const { models: sessionSummaries, meta } = await usecases.findPaginatedCertificationCenterSessionSummaries({
userId,
certificationCenterId,
page: options.page,
});

return sessionSummarySerializer.serialize(sessionSummaries, meta);
};

const getStudents = async function (request) {
const certificationCenterId = request.params.certificationCenterId;
const sessionId = request.params.sessionId;
Expand Down Expand Up @@ -91,7 +76,6 @@ const updateReferer = async function (request, h) {
const certificationCenterController = {
createCertificationCenterMembershipByEmail,
findCertificationCenterMembershipsByCertificationCenter,
findPaginatedSessionSummaries,
getDivisions,
getStudents,
updateReferer,
Expand Down
23 changes: 0 additions & 23 deletions api/lib/application/certification-centers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,6 @@ const register = async function (server) {
tags: ['api', 'certification-center', 'students', 'session'],
},
},
{
method: 'GET',
path: '/api/certification-centers/{id}/session-summaries',
config: {
validate: {
params: Joi.object({
id: identifiersType.certificationCenterId,
}),
query: Joi.object({
page: Joi.object({
number: Joi.number().integer().empty('').allow(null).optional(),
size: Joi.number().integer().empty('').allow(null).optional(),
}).default({}),
}),
},
handler: certificationCenterController.findPaginatedSessionSummaries,
tags: ['api', 'certification-center'],
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n',
'- Elle retourne les sessions rattachées au centre de certification.',
],
},
},
]);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { usecases } from '../domain/usecases/index.js';
import * as sessionSummarySerializer from '../infrastructure/serializers/session-summary-serializer.js';

const findPaginatedSessionSummaries = async function (request) {
const certificationCenterId = request.params.id;
const userId = request.auth.credentials.userId;
const options = request.query;

const { models: sessionSummaries, meta } = await usecases.findPaginatedCertificationCenterSessionSummaries({
userId,
certificationCenterId,
page: options.page,
});

return sessionSummarySerializer.serialize(sessionSummaries, meta);
};

const certificationCenterController = {
findPaginatedSessionSummaries,
};

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

import { certificationCenterController } from '../../../../src/certification/session-management/application/certification-centers-session-summaries-controller.js';
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js';

const register = async function (server) {
server.route([
{
method: 'GET',
path: '/api/certification-centers/{id}/session-summaries',
config: {
validate: {
params: Joi.object({
id: identifiersType.certificationCenterId,
}),
query: Joi.object({
page: Joi.object({
number: Joi.number().integer().empty('').allow(null).optional(),
size: Joi.number().integer().empty('').allow(null).optional(),
}).default({}),
}),
},
handler: certificationCenterController.findPaginatedSessionSummaries,
tags: ['api', 'certification-center'],
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n',
'- Elle retourne les sessions rattachées au centre de certification.',
],
},
},
]);
};

const name = 'session-summaries-api';
export { name, register };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ForbiddenAccess } from '../../../src/shared/domain/errors.js';
import { ForbiddenAccess } from '../../../../../src/shared/domain/errors.js';

const findPaginatedCertificationCenterSessionSummaries = async function ({
userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';

import { pickChallengeService } from '../../../../../src/evaluation/domain/services/pick-challenge-service.js';
import * as flashAlgorithmService from '../../../../certification/flash-certification/domain/services/algorithm-methods/flash.js';
import * as userRepository from '../../../../identity-access-management/infrastructure/repositories/user.repository.js';
import * as placementProfileService from '../../../../shared/domain/services/placement-profile-service.js';
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
Expand All @@ -23,6 +24,7 @@ import {
cpfExportRepository,
flashAlgorithmConfigurationRepository,
sessionRepositories,
sessionSummaryRepository,
sharedCompetenceMarkRepository,
} from '../../infrastructure/repositories/index.js';
import { cpfExportsStorage } from '../../infrastructure/storage/cpf-exports-storage.js';
Expand Down Expand Up @@ -68,6 +70,7 @@ import * as sessionPublicationService from '../services/session-publication-serv
* @typedef {import('../../../shared/domain/services/certification-cpf-service.js')} CertificationCpfService
* @typedef {import('../../infrastructure/repositories/index.js').CertificationCandidateRepository} CertificationCandidateRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationCompanionAlertRepository} CertificationCompanionAlertRepository
* @typedef {import('../../../../identity-access-management/infrastructure/repositories/user.respository.js').UserRepository} UserRepository
**/

/**
Expand Down Expand Up @@ -96,6 +99,7 @@ import * as sessionPublicationService from '../services/session-publication-serv
* @typedef {complementaryCertificationCourseResultRepository} ComplementaryCertificationCourseResultRepository
* @typedef {sessionJuryCommentRepository} SessionJuryCommentRepository
* @typedef {sessionRepository} SessionRepository
* @typedef {sessionSummaryRepository} SessionSummaryRepository
* @typedef {certificationReportRepository} CertificationReportRepository
* @typedef {certificationCpfCountryRepository} CertificationCpfCountryRepository
* @typedef {certificationCpfCityRepository} CertificationCpfCityRepository
Expand All @@ -111,9 +115,11 @@ import * as sessionPublicationService from '../services/session-publication-serv
* @typedef {cpfExportRepository} CpfExportRepository
* @typedef {certificationCandidateRepository} CertificationCandidateRepository
* @typedef {certificationCompanionAlertRepository} CertificationCompanionAlertRepository
* @typedef {userRepository} UserRepository
**/
const dependencies = {
...sessionRepositories,
sessionSummaryRepository,
assessmentRepository,
assessmentResultRepository,
answerRepository,
Expand All @@ -135,6 +141,7 @@ const dependencies = {
pickChallengeService,
sessionPublicationService,
sharedSessionRepository,
userRepository,
};

const path = dirname(fileURLToPath(import.meta.url));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import * as sessionForInvigilatorKitRepository from './session-for-invigilator-k
import * as sessionForSupervisingRepository from './session-for-supervising-repository.js';
import * as sessionJuryCommentRepository from './session-jury-comment-repository.js';
import * as sessionRepository from './session-repository.js';
import * as sessionSummaryRepository from './session-summary-repository.js';
import * as supervisorAccessRepository from './supervisor-access-repository.js';
import * as v3CertificationCourseDetailsForAdministrationRepository from './v3-certification-course-details-for-administration-repository.js';

Expand All @@ -53,6 +54,7 @@ import * as v3CertificationCourseDetailsForAdministrationRepository from './v3-c
* @typedef {certificationIssueReportRepository} CertificationIssueReportRepository
* @typedef {sessionForSupervisingRepository} SessionForSupervisingRepository
* @typedef {sessionJuryCommentRepository} SessionJuryCommentRepository
* @typedef {sessionSummaryRepository} SessionSummaryRepository
* @typedef {sessionRepository} SessionRepository
* @typedef {supervisorAccessRepository} SupervisorAccessRepository
* @typedef {certificationReportRepository} CertificationReportRepository
Expand Down Expand Up @@ -88,6 +90,7 @@ const repositoriesWithoutInjectedDependencies = {
sessionForInvigilatorKitRepository,
issueReportCategoryRepository,
sessionRepository,
sessionSummaryRepository,
sessionForSupervisingRepository,
sessionJuryCommentRepository,
certificationRepository,
Expand Down Expand Up @@ -126,5 +129,6 @@ export {
cpfExportRepository,
flashAlgorithmConfigurationRepository,
sessionRepositories,
sessionSummaryRepository,
sharedCompetenceMarkRepository,
};
2 changes: 2 additions & 0 deletions api/src/certification/session-management/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as cancellation from './application/cancellation-route.js';
import * as certificationCandidate from './application/certification-candidate-route.js';
import * as sessionSummaries from './application/certification-centers-session-summaries-route.js';
import * as certificationCourse from './application/certification-course-route.js';
import * as certificationDetails from './application/certification-details-route.js';
import * as certificationIssueReport from './application/certification-issue-report-route.js';
Expand Down Expand Up @@ -36,6 +37,7 @@ const certificationSessionRoutes = [
juryCertification,
juryComment,
session,
sessionSummaries,
sessionForSupervising,
sessionLiveAlert,
sessionPublication,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { certificationCenterController } from '../../../../../src/certification/session-management/application/certification-centers-session-summaries-controller.js';
import { usecases } from '../../../../../src/certification/session-management/domain/usecases/index.js';
import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js';

describe('Unit | Controller | certifications-center-controller', function () {
describe('#findPaginatedSessionSummaries', function () {
beforeEach(function () {
sinon.stub(usecases, 'findPaginatedCertificationCenterSessionSummaries');
});

it('should return a list of JSON API session summaries with pagination information', async function () {
// given
const request = {
params: { id: 456 },
auth: { credentials: { userId: 123 } },
query: {
page: {
number: 1,
size: 10,
},
},
};
const sessionSummary = domainBuilder.buildSessionSummary.created({
id: 1,
address: 'ici',
room: 'la-bas',
date: '2020-01-01',
time: '16:00',
examiner: 'Moi',
enrolledCandidatesCount: 5,
effectiveCandidatesCount: 4,
});
usecases.findPaginatedCertificationCenterSessionSummaries
.withArgs({
userId: 123,
certificationCenterId: 456,
page: { number: 1, size: 10 },
})
.resolves({
models: [sessionSummary],
meta: { page: 1, pageSize: 10, itemsCount: 1, pagesCount: 1, hasSessions: true },
});

// when
const serializedSessionSummaries = await certificationCenterController.findPaginatedSessionSummaries(
request,
hFake,
);

// then
expect(serializedSessionSummaries).to.deep.equal({
data: [
{
id: '1',
type: 'session-summaries',
attributes: {
address: 'ici',
room: 'la-bas',
date: '2020-01-01',
time: '16:00',
examiner: 'Moi',
'effective-candidates-count': 4,
'enrolled-candidates-count': 5,
status: 'created',
},
},
],
meta: {
hasSessions: true,
itemsCount: 1,
page: 1,
pageSize: 10,
pagesCount: 1,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { certificationCenterController } from '../../../../../src/certification/session-management/application/certification-centers-session-summaries-controller.js';
import * as moduleUnderTest from '../../../../../src/certification/session-management/application/certification-centers-session-summaries-route.js';
import { expect, HttpTestServer, sinon } from '../../../../test-helper.js';

describe('Certification | Session-management | Unit | Application | Routes | session-summaries', function () {
describe('GET /api/certification-centers/{certificationCenterId}/session-summaries', function () {
it('should return 200', async function () {
// given
sinon.stub(certificationCenterController, 'findPaginatedSessionSummaries').returns('ok');
const httpTestServer = new HttpTestServer();
await httpTestServer.register(moduleUnderTest);

// when
const response = await httpTestServer.request('GET', '/api/certification-centers/123/session-summaries');

// then
expect(response.statusCode).to.equal(200);
sinon.assert.calledOnce(certificationCenterController.findPaginatedSessionSummaries);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { findPaginatedCertificationCenterSessionSummaries } from '../../../../lib/domain/usecases/find-paginated-certification-center-session-summaries.js';
import { ForbiddenAccess } from '../../../../src/shared/domain/errors.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../test-helper.js';
import { findPaginatedCertificationCenterSessionSummaries } from '../../../../../../src/certification/session-management/domain/usecases/find-paginated-certification-center-session-summaries.js';
import { ForbiddenAccess } from '../../../../../../src/shared/domain/errors.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js';

describe('Unit | Domain | Use Cases | find-paginated-certification-center-session-summaries', function () {
const sessionSummaryRepository = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/session-summary-serializer.js';
import { domainBuilder, expect } from '../../../../test-helper.js';
import * as serializer from '../../../../../../src/certification/session-management/infrastructure/serializers/session-summary-serializer.js';
import { domainBuilder, expect } from '../../../../../test-helper.js';

describe('Unit | Serializer | JSONAPI | session-summary-serializer', function () {
describe('#serialize()', function () {
Expand Down
Loading

0 comments on commit 9624811

Please sign in to comment.