From 62133faaf31a2dbaf472ec5b0f97cb3730256dd0 Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Mon, 30 Jan 2023 15:21:29 +0100 Subject: [PATCH] enhancement(TaxForms): bring back delegated links --- server/lib/tax-forms.ts | 27 ++++++++++++++------------- test/server/lib/tax-forms.test.js | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/server/lib/tax-forms.ts b/server/lib/tax-forms.ts index 4792fb034c5a..0786eb7dce88 100644 --- a/server/lib/tax-forms.ts +++ b/server/lib/tax-forms.ts @@ -139,7 +139,7 @@ export async function sendHelloWorksUsTaxForm( workflowId, documentDelivery: true, documentDeliveryType: 'link', - // delegatedAuthentication: true, // See "authenticated link" below. + delegatedAuthentication: true, // See "authenticated link" below. participants, metadata: { accountType: accountToSubmitRequestTo.type, @@ -157,20 +157,21 @@ export async function sendHelloWorksUsTaxForm( }); // Get the authenticated link ("delegated authentication") - // We currently don't have access to this feature with our pricing plan - // try { - // documentLink = await client.workflowInstances.getAuthenticatedLinkForStep({ - // instanceId: instance.id, - // step: step.step, - // }); - // } catch (e) { - // // Fallback to the default `step.url` (unauthenticated link) - // logger.warn(`Tax form: error getting authenticated link for ${instance.id}: ${e.message}`); - // } + const step = instance.steps[0]; + let documentLink = step.url; + try { + documentLink = await client.workflowInstances.getAuthenticatedLinkForStep({ + instanceId: instance.id, + step: step.step, + }); + } catch (e) { + // Fallback to the default `step.url` (unauthenticated link) + reportMessageToSentry('Tax form: error getting authenticated link', { + extra: { error: JSON.stringify(e), instanceId: instance.id }, + }); + } // Save the authenticated link to the database, in case we want to send it again later - const step = instance.steps[0]; - const documentLink = step.url; await document.update({ data: deepMerge(document.data, { helloWorks: { documentLink } }) }); // Send the actual email diff --git a/test/server/lib/tax-forms.test.js b/test/server/lib/tax-forms.test.js index d3db9fa6dffb..1a5722fab49b 100644 --- a/test/server/lib/tax-forms.test.js +++ b/test/server/lib/tax-forms.test.js @@ -437,7 +437,7 @@ describe('server/lib/tax-forms', () => { expect(client.workflowInstances.createInstance.called).to.be.true; const callArgs = client.workflowInstances.createInstance.firstCall.args; expect(callArgs[0].participants['participant_swVuvW'].fullName).to.eq('Mr. Legal Name'); - // when we'll activate authenticated links expect(client.workflowInstances.getAuthenticatedLinkForStep.called).to.be.true; + expect(client.workflowInstances.getAuthenticatedLinkForStep.called).to.be.true; expect(doc.requestStatus).to.eq(REQUESTED); assert.callCount(sendMessageSpy, 1);