From 2370bc43c53f6a15d28b82ba1882f28e2b69a76b Mon Sep 17 00:00:00 2001 From: Guillaume Lagorce Date: Mon, 23 Dec 2024 14:53:20 +0100 Subject: [PATCH] feat: read parcoursup certification result from datamart --- .../repositories/certification-repository.js | 13 +++++++++-- .../application/certification-route_test.js | 4 ++++ .../certification-repository_test.js | 23 +++++++++++++++---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/api/src/parcoursup/infrastructure/repositories/certification-repository.js b/api/src/parcoursup/infrastructure/repositories/certification-repository.js index e4391f7eedd..9db96f30a1b 100644 --- a/api/src/parcoursup/infrastructure/repositories/certification-repository.js +++ b/api/src/parcoursup/infrastructure/repositories/certification-repository.js @@ -1,7 +1,16 @@ +import { datamartKnex } from '../../../../db/knex-database-connection.js'; +import { NotFoundError } from '../../../shared/domain/errors.js'; import { CertificationResult } from '../../domain/read-models/CertificationResult.js'; -const get = ({ ine }) => { - return new CertificationResult({ ine }); +const get = async ({ ine }) => { + const certificationResultDto = await datamartKnex('data_export_parcoursup_certif_result') + .where({ national_student_id: ine }) + .limit(1) + .first(); + if (!certificationResultDto) { + throw new NotFoundError('Aucune certification n‘existe pour l‘INE demandé'); + } + return new CertificationResult({ ine: certificationResultDto.national_student_id }); }; export { get }; diff --git a/api/tests/parcoursup/acceptance/application/certification-route_test.js b/api/tests/parcoursup/acceptance/application/certification-route_test.js index 875811eec12..5cb8da16a96 100644 --- a/api/tests/parcoursup/acceptance/application/certification-route_test.js +++ b/api/tests/parcoursup/acceptance/application/certification-route_test.js @@ -1,6 +1,7 @@ import { createServer, databaseBuilder, + datamartBuilder, expect, generateValidRequestAuthorizationHeaderForApplication, } from '../../../test-helper.js'; @@ -20,6 +21,9 @@ describe('Parcoursup | Acceptance | Application | certification-route', function it('should return 200 HTTP status code and a certification for a given INE', async function () { // given const ine = '123456789OK'; + datamartBuilder.factory.buildCertificationResult({ nationalStudentId: ine }); + await datamartBuilder.commit(); + const options = { method: 'GET', url: `/api/parcoursup/students/${ine}/certification`, diff --git a/api/tests/parcoursup/integration/repositories/certification-repository_test.js b/api/tests/parcoursup/integration/repositories/certification-repository_test.js index c95fb303452..73f98024988 100644 --- a/api/tests/parcoursup/integration/repositories/certification-repository_test.js +++ b/api/tests/parcoursup/integration/repositories/certification-repository_test.js @@ -1,5 +1,6 @@ import * as certificationRepository from '../../../../../api/src/parcoursup/infrastructure/repositories/certification-repository.js'; -import { domainBuilder, expect } from '../../../test-helper.js'; +import { NotFoundError } from '../../../../src/shared/domain/errors.js'; +import { catchErr, datamartBuilder, domainBuilder, expect } from '../../../test-helper.js'; describe('Parcoursup | Infrastructure | Integration | Repositories | certification', function () { describe('#get', function () { @@ -7,16 +8,30 @@ describe('Parcoursup | Infrastructure | Integration | Repositories | certificati it('should return the certification', async function () { // given const ine = '1234'; + datamartBuilder.factory.buildCertificationResult({ nationalStudentId: ine }); + await datamartBuilder.commit(); // when - const result = await certificationRepository.get({ - ine, - }); + const result = await certificationRepository.get({ ine }); // then const expectedCertification = domainBuilder.parcoursup.buildCertificationResult({ ine }); expect(result).to.deep.equal(expectedCertification); }); }); + + describe('when no certifications are found for given ine', function () { + it('should throw Not Found Error', async function () { + // given + const ine = '1234'; + + // when + const err = await catchErr(certificationRepository.get)({ ine }); + + // then + expect(err).to.be.instanceOf(NotFoundError); + expect(err.message).to.deep.equal('Aucune certification n‘existe pour l‘INE demandé'); + }); + }); }); });