2026-04-27 15:25:06 +02:00
|
|
|
import 'dotenv/config';
|
|
|
|
|
import { test, expect } from '@playwright/test';
|
|
|
|
|
|
|
|
|
|
import { login, apiHeaders } from '../smoke/helpers';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Real-API end-to-end test for the Documenso documenso-template pathway.
|
|
|
|
|
*
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
* This spec exercises the SEND side of the integration only - it creates a
|
2026-04-27 15:25:06 +02:00
|
|
|
* fully-loaded interest, fires generate-and-sign, and asserts both
|
|
|
|
|
* (a) the CRM persisted a documensoId on the documents row, and
|
|
|
|
|
* (b) Documenso itself returns 200 for the freshly-created document.
|
|
|
|
|
*
|
|
|
|
|
* The receive side (webhook → state update) is validated separately by
|
|
|
|
|
* triggering a real signing event in the Documenso UI and watching
|
|
|
|
|
* /tmp/dev-server.log; it isn't automated here because Documenso has no
|
|
|
|
|
* machine-friendly "sign on behalf of recipient" endpoint we can drive
|
|
|
|
|
* deterministically from CI.
|
|
|
|
|
*
|
|
|
|
|
* Requires DOCUMENSO_API_URL + DOCUMENSO_API_KEY + DOCUMENSO_TEMPLATE_ID_EOI
|
|
|
|
|
* in the environment (loaded via dotenv).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const DOCUMENSO_BASE = process.env.DOCUMENSO_API_URL;
|
|
|
|
|
const DOCUMENSO_API_KEY = process.env.DOCUMENSO_API_KEY;
|
|
|
|
|
|
|
|
|
|
test.describe('Documenso real-API: documenso-template pathway', () => {
|
|
|
|
|
test.skip(!DOCUMENSO_BASE || !DOCUMENSO_API_KEY, 'DOCUMENSO_API_URL / DOCUMENSO_API_KEY not set');
|
|
|
|
|
|
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
|
await login(page, 'super_admin');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('generate-and-sign creates a real Documenso document', async ({ page }) => {
|
|
|
|
|
const stamp = Date.now();
|
|
|
|
|
const headers = await apiHeaders(page);
|
|
|
|
|
|
|
|
|
|
// ─── 1. Seed client (with a contact email so Documenso has a recipient) ──
|
|
|
|
|
const clientRes = await page.request.post('/api/v1/clients', {
|
|
|
|
|
headers,
|
|
|
|
|
data: {
|
|
|
|
|
fullName: `Documenso E2E Client ${stamp}`,
|
|
|
|
|
contacts: [
|
|
|
|
|
{ channel: 'email', value: `documenso-e2e-${stamp}@example.test`, isPrimary: true },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
expect(clientRes.ok(), `client create: ${clientRes.status()} ${await clientRes.text()}`).toBe(
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
const clientId = (await clientRes.json()).data.id as string;
|
|
|
|
|
|
|
|
|
|
// ─── 2. Seed yacht owned by that client ──────────────────────────────────
|
|
|
|
|
const yachtRes = await page.request.post('/api/v1/yachts', {
|
|
|
|
|
headers,
|
|
|
|
|
data: {
|
|
|
|
|
name: `E2E Yacht ${stamp}`,
|
|
|
|
|
owner: { type: 'client', id: clientId },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
expect(yachtRes.ok(), `yacht create: ${yachtRes.status()} ${await yachtRes.text()}`).toBe(true);
|
|
|
|
|
const yachtId = (await yachtRes.json()).data.id as string;
|
|
|
|
|
|
|
|
|
|
// ─── 3. Seed berth ───────────────────────────────────────────────────────
|
|
|
|
|
const berthRes = await page.request.post('/api/v1/berths', {
|
|
|
|
|
headers,
|
|
|
|
|
data: {
|
|
|
|
|
mooringNumber: `E2E-${stamp}`,
|
|
|
|
|
area: 'Test Area',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
expect(berthRes.ok(), `berth create: ${berthRes.status()} ${await berthRes.text()}`).toBe(true);
|
|
|
|
|
const berthId = (await berthRes.json()).data.id as string;
|
|
|
|
|
|
|
|
|
|
// ─── 4. Create the interest linking all three ────────────────────────────
|
|
|
|
|
const interestRes = await page.request.post('/api/v1/interests', {
|
|
|
|
|
headers,
|
|
|
|
|
data: { clientId, yachtId, berthId, pipelineStage: 'open' },
|
|
|
|
|
});
|
|
|
|
|
expect(
|
|
|
|
|
interestRes.ok(),
|
|
|
|
|
`interest create: ${interestRes.status()} ${await interestRes.text()}`,
|
|
|
|
|
).toBe(true);
|
|
|
|
|
const interestId = (await interestRes.json()).data.id as string;
|
|
|
|
|
|
|
|
|
|
// ─── 5. Fire generate-and-sign through the documenso-template pathway ────
|
|
|
|
|
const signRes = await page.request.post(
|
|
|
|
|
'/api/v1/document-templates/documenso-template/generate-and-sign',
|
|
|
|
|
{
|
|
|
|
|
headers,
|
|
|
|
|
data: {
|
|
|
|
|
interestId,
|
|
|
|
|
clientId,
|
|
|
|
|
berthId,
|
|
|
|
|
pathway: 'documenso-template',
|
|
|
|
|
signers: [],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
expect(signRes.ok(), `generate-and-sign: ${signRes.status()} ${await signRes.text()}`).toBe(
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const body = (await signRes.json()) as {
|
|
|
|
|
data: { document: { id: string; documensoId: string | null; status: string } };
|
|
|
|
|
};
|
|
|
|
|
expect(body.data.document.documensoId, 'documensoId on response').toBeTruthy();
|
|
|
|
|
expect(body.data.document.status).toBe('sent');
|
|
|
|
|
|
|
|
|
|
const documensoId = body.data.document.documensoId!;
|
|
|
|
|
|
|
|
|
|
// ─── 6. Verify the document exists on the Documenso side ─────────────────
|
|
|
|
|
const documensoRes = await page.request.get(
|
|
|
|
|
`${DOCUMENSO_BASE}/api/v1/documents/${documensoId}`,
|
|
|
|
|
{
|
|
|
|
|
headers: { Authorization: `Bearer ${DOCUMENSO_API_KEY}` },
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
expect(
|
|
|
|
|
documensoRes.ok(),
|
|
|
|
|
`documenso GET: ${documensoRes.status()} ${await documensoRes.text()}`,
|
|
|
|
|
).toBe(true);
|
|
|
|
|
|
|
|
|
|
const documensoDoc = (await documensoRes.json()) as {
|
|
|
|
|
id: number;
|
|
|
|
|
status: string;
|
|
|
|
|
recipients?: Array<{ email: string; signingStatus: string }>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
expect(String(documensoDoc.id)).toBe(documensoId);
|
|
|
|
|
// Freshly-sent doc should be PENDING (or DRAFT if Documenso queued it).
|
|
|
|
|
expect(['PENDING', 'DRAFT'], `unexpected status ${documensoDoc.status}`).toContain(
|
|
|
|
|
documensoDoc.status,
|
|
|
|
|
);
|
|
|
|
|
// The template is configured with ≥1 recipient role, so we should have
|
|
|
|
|
// at least the client's email populated.
|
|
|
|
|
expect(documensoDoc.recipients?.length ?? 0).toBeGreaterThan(0);
|
|
|
|
|
});
|
|
|
|
|
});
|