feat(eoi): template-aware generate-EOI dialog

The EOI dialog now lists "Documenso Standard EOI" (default) plus any
seeded in-app EOI templates and routes the submit to the dual-path
generate-and-sign endpoint with the correct pathway:

  - "documenso-template" sentinel id → pathway: documenso-template
  - any other template id → pathway: inapp

Signers are derived server-side from EoiContext for both pathways when
the template type is EOI (interest's client + hardcoded developer +
approver), so the dialog doesn't collect them. Non-EOI templates still
require explicit signers.

Drops the legacy `client.yachtLengthFt` prerequisite check (yacht is now
a first-class entity) and replaces it with hasYacht based on
interest.yachtId. Tests updated; 646/646 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-04-26 13:42:08 +02:00
parent 2ff24a7132
commit f4ec51002c
4 changed files with 171 additions and 58 deletions

View File

@@ -206,16 +206,53 @@ describe('generateAndSign — inapp pathway', () => {
expect(docRow?.fileId).toBeTruthy();
});
it('throws ValidationError when signers array is empty', async () => {
it('auto-derives signers for EOI templates when none are provided', async () => {
const client = await import('@/lib/services/documenso-client');
vi.mocked(client.createDocument).mockResolvedValue({
id: 'doc-auto-signers',
status: 'PENDING',
recipients: [],
});
vi.mocked(client.sendDocument).mockResolvedValue({
id: 'doc-auto-signers',
status: 'PENDING',
recipients: [],
});
await generateAndSign(
setup.inAppTemplateId,
setup.portId,
{ clientId: setup.clientId, interestId: setup.interestId },
[],
'inapp',
{ ...meta, portId: setup.portId },
);
expect(client.createDocument).toHaveBeenCalledOnce();
const recipients = vi.mocked(client.createDocument).mock.calls[0]![2];
expect(recipients).toHaveLength(3);
expect(recipients[0]?.name).toBe('Dual Path Client');
expect(recipients[1]?.name).toBe('David Mizrahi');
expect(recipients[2]?.role).toBe('approver');
});
it('throws ValidationError when non-EOI template has no signers', async () => {
const [other] = await db
.insert(documentTemplates)
.values({
portId: setup.portId,
name: 'Plain Letter',
templateType: 'welcome_letter',
bodyHtml: '<p>x</p>',
createdBy: 'test',
})
.returning();
await expect(
generateAndSign(
setup.inAppTemplateId,
setup.portId,
{ clientId: setup.clientId, interestId: setup.interestId },
[],
'inapp',
{ ...meta, portId: setup.portId },
),
generateAndSign(other!.id, setup.portId, { clientId: setup.clientId }, [], 'inapp', {
...meta,
portId: setup.portId,
}),
).rejects.toThrow(ValidationError);
});