diff --git a/api/src/profile/application/api/attestations-api.js b/api/src/profile/application/api/attestations-api.js index acb408d3f17..99a58e74024 100644 --- a/api/src/profile/application/api/attestations-api.js +++ b/api/src/profile/application/api/attestations-api.js @@ -11,9 +11,7 @@ export const generateAttestations = async function ({ userIds, dependencies = { pdfWithFormSerializer }, }) { - const data = await usecases.getAttestationDataForUsers({ attestationKey, userIds }); - - const templateName = 'sixth-grade-attestation-template'; + const { data, templateName } = await usecases.getAttestationDataForUsers({ attestationKey, userIds }); const templatePath = path.join(__dirname, `../../infrastructure/serializers/pdf/templates/${templateName}.pdf`); diff --git a/api/src/profile/application/attestation-controller.js b/api/src/profile/application/attestation-controller.js index 99f34b552e9..fe3821086ef 100644 --- a/api/src/profile/application/attestation-controller.js +++ b/api/src/profile/application/attestation-controller.js @@ -11,9 +11,11 @@ const getUserAttestation = async function (request, h, dependencies = { pdfWithF const userId = request.params.userId; const locale = dependencies.requestResponseUtils.extractLocaleFromRequest(request); const attestationKey = request.params.attestationKey; - // TODO: Modifier le usecase pour qu'il retourne le templateName - const templateName = 'sixth-grade-attestation-template'; - const data = await usecases.getAttestationDataForUsers({ attestationKey, userIds: [userId], locale }); + const { data, templateName } = await usecases.getAttestationDataForUsers({ + attestationKey, + userIds: [userId], + locale, + }); const templatePath = path.join(__dirname, `../infrastructure/serializers/pdf/templates/${templateName}.pdf`); diff --git a/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js b/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js index 07ef50603d0..0063b77551c 100644 --- a/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js +++ b/api/tests/prescription/organization-learner/acceptance/application/organization-learner-route_test.js @@ -26,7 +26,9 @@ describe('Prescription | Organization Learner | Acceptance | Application | Organ organizationId, organizationRole: Membership.roles.MEMBER, }); - const attestation = databaseBuilder.factory.buildAttestation(); + const attestation = databaseBuilder.factory.buildAttestation({ + templateName: 'sixth-grade-attestation-template', + }); const organizationLearner = databaseBuilder.factory.buildOrganizationLearner({ organizationId, division: '6emeA', diff --git a/api/tests/profile/unit/application/api/attestations-api_test.js b/api/tests/profile/unit/application/api/attestations-api_test.js index 29842968f93..bd0564f252c 100644 --- a/api/tests/profile/unit/application/api/attestations-api_test.js +++ b/api/tests/profile/unit/application/api/attestations-api_test.js @@ -18,7 +18,9 @@ describe('Profile | Unit | Application | Api | attestations', function () { sinon.stub(usecases, 'getAttestationDataForUsers'); - usecases.getAttestationDataForUsers.withArgs({ attestationKey, userIds }).resolves(data); + usecases.getAttestationDataForUsers + .withArgs({ attestationKey, userIds }) + .resolves({ data, templateName: 'sixth-grade-attestation-template' }); dependencies.pdfWithFormSerializer.serialize .withArgs(sinon.match(/(\w*\/)*sixth-grade-attestation-template.pdf/), data) diff --git a/api/tests/profile/unit/application/attestation-controller_test.js b/api/tests/profile/unit/application/attestation-controller_test.js index 5cf74f6a175..ea0b1bfbaf4 100644 --- a/api/tests/profile/unit/application/attestation-controller_test.js +++ b/api/tests/profile/unit/application/attestation-controller_test.js @@ -23,14 +23,14 @@ describe('Profile | Unit | Controller | attestation-controller', function () { sinon.stub(hFake, 'response'); hFake.response.callThrough(); - const expectedUsecaseResponse = Symbol('expectedUsecaseResponse'); + const expectedUsecaseResponse = { data: Symbol('data'), templateName: 'sixth-grade-attestation-template' }; const expectedBuffer = Symbol('expectedBuffer'); usecases.getAttestationDataForUsers .withArgs({ attestationKey, userIds: [userId], locale }) .resolves(expectedUsecaseResponse); pdfWithFormSerializerStub.serialize - .withArgs(sinon.match(/(\w*\/)*sixth-grade-attestation-template.pdf/), expectedUsecaseResponse) + .withArgs(sinon.match(/(\w*\/)*sixth-grade-attestation-template.pdf/), expectedUsecaseResponse.data) .resolves(expectedBuffer); // when