Skip to content

Commit

Permalink
feat: read parcoursup certification result from datamart
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYGUL committed Dec 26, 2024
1 parent 53ed843 commit 2370bc4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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 };
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
createServer,
databaseBuilder,
datamartBuilder,
expect,
generateValidRequestAuthorizationHeaderForApplication,
} from '../../../test-helper.js';
Expand All @@ -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`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
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 () {
describe('when a certification is found', function () {
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é');
});
});
});
});

0 comments on commit 2370bc4

Please sign in to comment.