Skip to content

Commit

Permalink
feat(api): retrieve templateName from usecase on attestationsApi & at…
Browse files Browse the repository at this point in the history
…testationController
  • Loading branch information
Alexandre-Monney committed Oct 14, 2024
1 parent f30045a commit 0360840
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 1 addition & 3 deletions api/src/profile/application/api/attestations-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down
8 changes: 5 additions & 3 deletions api/src/profile/application/attestation-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0360840

Please sign in to comment.