Berth surfaces - New compact mooring-chip header (colored plate + status pill, dock-label in tooltip) replaces the redundant "Berth B1 / Sold / B DOCK" stack - Berth list gains a "Latest deal stage" column showing the most-advanced pipeline stage of any active linked interest (server-aggregated, ranks by PIPELINE_STAGES index) - "Linked prospect" Select on the status-change dialog rebuilt as a Command combobox: search, recent-first sort, stage-coloured pills Pipeline UX - Reverting an interest to Open with linked berths now prompts: keep the links, unlink and reset, or cancel. Silent when no berths are linked - Activity feed + entity-activity feed normalise enum field values via STAGE_LABELS / formatSource: "deposit_10pct → contract_sent" reads as "10% Deposit → Contract Sent" EOI generate dialog - Inline-editable rows for client name, nationality (country combobox), and yacht name — pencil affordance saves directly via clients/yachts PATCH - Replaces the single "Edit on client's page" link with two contextual links framed by short copy explaining what's inline vs what needs the canonical page - Backend EoiContext now includes client.id + yacht.id so the dialog can PATCH without an extra round-trip Company form - New "Connections" section lets the rep attach members (clients) and yachts during create. Yacht attach uses the existing transfer endpoint so audit log + ownership history capture the change - Inline "+ New client" / "+ New yacht" buttons open the canonical forms stacked over the company sheet - After save, the form chains to a yacht pull-in prompt (if any attached client owns yachts not yet linked) and an optional "Create interest" step pre-filled with the first attached client Admin - /admin landing gains a searchable index — typed query flattens groups into a result list matching label + description + group title - "Documenso & EOI" card relabelled to "EOI signing service" (consistent with the user-facing language rename from round 1) Measurement units (migration 0053) - interests gains desired_*_m columns + desired_*_unit discriminators so the rep's literal entry (ft OR m) is preserved verbatim instead of being reconstructed from a single canonical column on every render - yachts + berths gain matching *_unit columns alongside their existing ft + m pairs; defaults to 'ft' so legacy rows still render normally - Interest form POST/PATCH now sends both ft + m + unit; computed m is derived from the ft canonical to keep the recommender SQL unchanged Misc - Active-deals tile + topbar type their Link href as `Route` instead of `any` - Unused REPORT_TYPE_LABELS const dropped from generate-report-form - Test fixtures (fill-eoi-form, documenso-payload, public-berths) updated to include the new id + unit fields on the EoiContext / Berth shapes Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
226 lines
7.3 KiB
TypeScript
226 lines
7.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
|
|
import { buildDocumensoPayload } from '@/lib/services/documenso-payload';
|
|
import type { EoiContext } from '@/lib/services/eoi-context';
|
|
|
|
function makeContext(overrides?: Partial<EoiContext>): EoiContext {
|
|
return {
|
|
client: {
|
|
id: 'client-fixture-1',
|
|
fullName: 'Alice Smith',
|
|
nationality: 'US',
|
|
primaryEmail: 'alice@example.com',
|
|
primaryPhone: '+1-555-0100',
|
|
address: { street: '123 Main St', city: 'Austin', country: 'USA' },
|
|
},
|
|
yacht: {
|
|
id: 'yacht-fixture-1',
|
|
name: 'Sea Breeze',
|
|
lengthFt: '45',
|
|
widthFt: '14',
|
|
draftFt: '6',
|
|
lengthM: null,
|
|
widthM: null,
|
|
draftM: null,
|
|
hullNumber: 'ABC-123',
|
|
flag: 'US',
|
|
yearBuilt: 2020,
|
|
},
|
|
company: null,
|
|
owner: { type: 'client', name: 'Alice Smith' },
|
|
berth: {
|
|
mooringNumber: 'A12',
|
|
area: 'North Dock',
|
|
lengthFt: '50',
|
|
price: '1200',
|
|
priceCurrency: 'USD',
|
|
tenureType: 'permanent',
|
|
},
|
|
eoiBerthRange: 'A12',
|
|
interest: {
|
|
stage: 'open',
|
|
leadCategory: null,
|
|
dateFirstContact: null,
|
|
notes: null,
|
|
},
|
|
port: {
|
|
name: 'Port Nimara',
|
|
defaultCurrency: 'USD',
|
|
},
|
|
date: { today: '2026-04-23', year: '2026' },
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
const OPTIONS = {
|
|
interestId: 'int-123',
|
|
clientRecipientId: 192,
|
|
developerRecipientId: 193,
|
|
approvalRecipientId: 194,
|
|
};
|
|
|
|
describe('buildDocumensoPayload', () => {
|
|
it('builds title as "{fullName}-EOI-NDA"', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.title).toBe('Alice Smith-EOI-NDA');
|
|
});
|
|
|
|
it('builds externalId as "loi-{interestId}"', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.externalId).toBe('loi-int-123');
|
|
});
|
|
|
|
it('formats formValues with all EoiContext fields', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.formValues).toEqual({
|
|
Name: 'Alice Smith',
|
|
Email: 'alice@example.com',
|
|
Address: '123 Main St, Austin, USA',
|
|
'Yacht Name': 'Sea Breeze',
|
|
Length: '45',
|
|
Width: '14',
|
|
Draft: '6',
|
|
'Berth Number': 'A12',
|
|
'Berth Range': 'A12',
|
|
Lease_10: false,
|
|
Purchase: true,
|
|
});
|
|
});
|
|
|
|
it('defaults missing primaryEmail to empty string', () => {
|
|
const ctx = makeContext({ client: { ...makeContext().client, primaryEmail: null } });
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.formValues.Email).toBe('');
|
|
expect(payload.recipients[0]!.email).toBe('');
|
|
});
|
|
|
|
it('defaults missing yacht dimensions to empty strings', () => {
|
|
const baseYacht = makeContext().yacht!;
|
|
const ctx = makeContext({
|
|
yacht: { ...baseYacht, lengthFt: null, widthFt: null, draftFt: null },
|
|
});
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.formValues.Length).toBe('');
|
|
expect(payload.formValues.Width).toBe('');
|
|
expect(payload.formValues.Draft).toBe('');
|
|
});
|
|
|
|
it('renders empty Section 3 when yacht and berth are not linked', () => {
|
|
const ctx = makeContext({ yacht: null, berth: null });
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.formValues['Yacht Name']).toBe('');
|
|
expect(payload.formValues.Length).toBe('');
|
|
expect(payload.formValues.Width).toBe('');
|
|
expect(payload.formValues.Draft).toBe('');
|
|
expect(payload.formValues['Berth Number']).toBe('');
|
|
});
|
|
|
|
it('formats empty address when client has no address', () => {
|
|
const ctx = makeContext({ client: { ...makeContext().client, address: null } });
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.formValues.Address).toBe('');
|
|
});
|
|
|
|
it('skips null parts in address', () => {
|
|
const ctx = makeContext({
|
|
client: {
|
|
...makeContext().client,
|
|
address: { street: '', city: 'Austin', country: 'USA' },
|
|
},
|
|
});
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.formValues.Address).toBe('Austin, USA');
|
|
});
|
|
|
|
it('sets Lease_10=false and Purchase=true (hardcoded)', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.formValues.Lease_10).toBe(false);
|
|
expect(payload.formValues.Purchase).toBe(true);
|
|
});
|
|
|
|
it('includes client, developer, and approver recipients in signing order', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.recipients).toHaveLength(3);
|
|
expect(payload.recipients[0]).toEqual({
|
|
id: 192,
|
|
name: 'Alice Smith',
|
|
email: 'alice@example.com',
|
|
role: 'SIGNER',
|
|
signingOrder: 1,
|
|
});
|
|
expect(payload.recipients[1]).toEqual({
|
|
id: 193,
|
|
name: 'David Mizrahi',
|
|
email: 'dm@portnimara.com',
|
|
role: 'SIGNER',
|
|
signingOrder: 2,
|
|
});
|
|
expect(payload.recipients[2]).toEqual({
|
|
id: 194,
|
|
name: 'Abbie May',
|
|
email: 'sales@portnimara.com',
|
|
role: 'APPROVER',
|
|
signingOrder: 3,
|
|
});
|
|
});
|
|
|
|
it('allows overriding developer/approver recipient names', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), {
|
|
...OPTIONS,
|
|
developerName: 'Custom Dev',
|
|
developerEmail: 'dev@custom.com',
|
|
approverName: 'Custom Approver',
|
|
approverEmail: 'approve@custom.com',
|
|
});
|
|
expect(payload.recipients[1]!.name).toBe('Custom Dev');
|
|
expect(payload.recipients[1]!.email).toBe('dev@custom.com');
|
|
expect(payload.recipients[2]!.name).toBe('Custom Approver');
|
|
expect(payload.recipients[2]!.email).toBe('approve@custom.com');
|
|
});
|
|
|
|
it('builds message with port name and greeting', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.meta.message).toContain('Dear Alice Smith');
|
|
expect(payload.meta.message).toContain('Port Nimara');
|
|
expect(payload.meta.message).toContain('Best Regards');
|
|
// No company on-behalf block for client-owned yachts
|
|
expect(payload.meta.message).not.toContain('On behalf of');
|
|
});
|
|
|
|
it('adds company on-behalf block for company-owned yachts', () => {
|
|
const ctx = makeContext({
|
|
company: {
|
|
name: 'Aegean Holdings',
|
|
legalName: 'Aegean Holdings SA',
|
|
taxId: null,
|
|
billingAddress: null,
|
|
},
|
|
owner: { type: 'company', name: 'Aegean Holdings', legalName: 'Aegean Holdings SA' },
|
|
});
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.meta.message).toContain('On behalf of Aegean Holdings SA');
|
|
});
|
|
|
|
it('uses company name when legalName is missing in on-behalf block', () => {
|
|
const ctx = makeContext({
|
|
company: { name: 'Blue Seas', legalName: null, taxId: null, billingAddress: null },
|
|
owner: { type: 'company', name: 'Blue Seas' },
|
|
});
|
|
const payload = buildDocumensoPayload(ctx, OPTIONS);
|
|
expect(payload.meta.message).toContain('On behalf of Blue Seas');
|
|
});
|
|
|
|
it('uses default redirect URL when not provided', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), OPTIONS);
|
|
expect(payload.meta.redirectUrl).toBe('https://portnimara.com');
|
|
});
|
|
|
|
it('uses custom redirect URL when provided', () => {
|
|
const payload = buildDocumensoPayload(makeContext(), {
|
|
...OPTIONS,
|
|
redirectUrl: 'https://custom.example.com',
|
|
});
|
|
expect(payload.meta.redirectUrl).toBe('https://custom.example.com');
|
|
});
|
|
});
|