-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read parcoursup certification result from datamart
- Loading branch information
Showing
3 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 11 additions & 2 deletions
13
api/src/parcoursup/infrastructure/repositories/certification-repository.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 19 additions & 4 deletions
23
api/tests/parcoursup/integration/repositories/certification-repository_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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é'); | ||
}); | ||
}); | ||
}); | ||
}); |