feat(berths): website auto-promote toggle + manual-override soft-pin priority
All checks were successful
Build & Push Docker Images / lint (push) Successful in 2m47s
Build & Push Docker Images / build-and-push (push) Successful in 6m49s

- website_berth_autopromote_enabled (default OFF): a website registration for a
  specific, currently-available berth auto-creates a prospect (client + optional
  yacht + interest) and links the berth is_specific_interest=true, flipping the
  public map to Under Offer; general/residence/contact submissions stay
  capture-only. Marks the submission converted so a rep never double-creates it.
- derivePublicStatus now honours a manual pin (soft pin): a manually-set status
  wins over the interest-derived Under Offer, but a real permanent tenancy or an
  explicit sold still override it.
- berth rules engine respects a manual pin EXCEPT for sale triggers (-> sold),
  so a confirmed sale still wins but soft auto-changes never stomp a pin.
- Reset-to-automatic action (service + API POST /berths/[id]/status/reset + UI)
  to drop a manual pin; lock badge on every manual override (list + detail);
  divergence banner prompting reset when a pinned-Available berth has a deal.
- migration stage map updated to the §4b signed-off mapping: GQI -> enquiry
  unless it named a berth/size marker (-> qualified); SQI -> qualified.

Tests: +public-berths soft-pin cases, +website-intake-promote helpers,
+migration GQI marker rule. 1582 unit/integration green; tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-02 20:10:04 +02:00
parent 04ddd59662
commit 15a139e86f
14 changed files with 802 additions and 19 deletions

View File

@@ -180,15 +180,59 @@ describe('transformSnapshot - fixture regression', () => {
expect(sourceIds).toEqual([188, 236, 336, 536, 585, 624, 625, 681, 682, 683, 717, 999]);
});
it('maps the legacy 8-stage enum to new pipeline stages', () => {
it('maps the legacy 8-stage enum to new pipeline stages (§4b signed-off)', () => {
const plan = transformSnapshot(FIXTURE);
const stagesById = new Map(plan.interests.map((i) => [i.sourceId, i.pipelineStage]));
expect(stagesById.get(681)).toBe('qualified'); // General Qualified Interest
expect(stagesById.get(682)).toBe('nurturing'); // Specific Qualified Interest
// 681 is "General Qualified Interest" with no berth/size marker → enquiry.
expect(stagesById.get(681)).toBe('enquiry');
// 682 is "Specific Qualified Interest" → qualified.
expect(stagesById.get(682)).toBe('qualified');
expect(stagesById.get(336)).toBe('contract'); // Contract Signed
expect(stagesById.get(585)).toBe('eoi'); // Signed EOI and NDA
});
it('§4b marker rule: a GQI that named a berth or size is qualified, not a plain enquiry', () => {
const snap: NocoDbSnapshot = {
fetchedAt: '2026-06-02T00:00:00.000Z',
berths: [],
residentialInterests: [],
websiteInterestSubmissions: [],
websiteContactFormSubmissions: [],
websiteBerthEoiSupplements: [],
interests: [
row({
Id: 9001,
'Full Name': 'Bare Enquiry',
'Email Address': 'bare@example.com',
'Phone Number': '+15550000001',
'Sales Process Level': 'General Qualified Interest',
}),
row({
Id: 9002,
'Full Name': 'Named Berth',
'Email Address': 'berth@example.com',
'Phone Number': '+15550000002',
'Sales Process Level': 'General Qualified Interest',
'Berth Number': 'A1',
}),
row({
Id: 9003,
'Full Name': 'Wants Size',
'Email Address': 'size@example.com',
'Phone Number': '+15550000003',
'Sales Process Level': 'General Qualified Interest',
'Berth Size Desired': '20m',
}),
],
};
const stagesById = new Map(
transformSnapshot(snap).interests.map((i) => [i.sourceId, i.pipelineStage]),
);
expect(stagesById.get(9001)).toBe('enquiry'); // no marker
expect(stagesById.get(9002)).toBe('qualified'); // named a berth
expect(stagesById.get(9003)).toBe('qualified'); // entered a desired size
});
it('attaches different yachts to one merged Constanzo client', () => {
const plan = transformSnapshot(FIXTURE);
const constanzoClient = plan.clients.find(

View File

@@ -117,6 +117,31 @@ describe('derivePublicStatus', () => {
expect(derivePublicStatus('available', true)).toBe('Under Offer');
});
});
describe('manual override (soft pin)', () => {
it('a manual "available" pin wins over an active specific-interest link', () => {
// The key behaviour: a rep deliberately keeping a berth Available is NOT
// overridden by an interest-derived "Under Offer".
expect(derivePublicStatus('available', true, false, 'manual')).toBe('Available');
});
it('a manual "under_offer" pin shows Under Offer', () => {
expect(derivePublicStatus('under_offer', false, false, 'manual')).toBe('Under Offer');
});
it('a manual "sold" pin shows Sold', () => {
expect(derivePublicStatus('sold', false, false, 'manual')).toBe('Sold');
});
it('a real permanent tenancy still overrides a manual "available" pin (soft pin)', () => {
expect(derivePublicStatus('available', false, true, 'manual')).toBe('Sold');
expect(derivePublicStatus('available', true, true, 'manual')).toBe('Sold');
});
it('"automated" override mode falls through to normal derivation (interest promotes)', () => {
expect(derivePublicStatus('available', true, false, 'automated')).toBe('Under Offer');
});
it('null/omitted override mode preserves pre-pin behaviour', () => {
expect(derivePublicStatus('available', true, false, null)).toBe('Under Offer');
expect(derivePublicStatus('available', true, false)).toBe('Under Offer');
});
});
});
describe('isPermanentTenureType', () => {

View File

@@ -0,0 +1,46 @@
import { describe, it, expect } from 'vitest';
import {
extractPromotionIntent,
isBerthPromotable,
} from '@/lib/services/website-intake-promote.service';
describe('extractPromotionIntent', () => {
it('detects a specific berth on a berth_inquiry', () => {
expect(extractPromotionIntent('berth_inquiry', { first_name: 'Jane', berth: 'A1' })).toEqual({
hasSpecificBerth: true,
mooringNumber: 'A1',
});
});
it('returns no berth for a berth_inquiry with no mooring', () => {
expect(extractPromotionIntent('berth_inquiry', { first_name: 'Jane' })).toEqual({
hasSpecificBerth: false,
mooringNumber: null,
});
});
it('ignores residence / contact kinds entirely', () => {
expect(extractPromotionIntent('residence_inquiry', { berth: 'A1' })).toEqual({
hasSpecificBerth: false,
mooringNumber: null,
});
expect(extractPromotionIntent('contact_form', { berth: 'A1' })).toEqual({
hasSpecificBerth: false,
mooringNumber: null,
});
});
});
describe('isBerthPromotable', () => {
it('only an exactly-available berth is promotable', () => {
expect(isBerthPromotable('available')).toBe(true);
});
it('under_offer / sold / unknown / null are NOT promotable (never stomp)', () => {
expect(isBerthPromotable('under_offer')).toBe(false);
expect(isBerthPromotable('sold')).toBe(false);
expect(isBerthPromotable('something')).toBe(false);
expect(isBerthPromotable(null)).toBe(false);
expect(isBerthPromotable(undefined)).toBe(false);
});
});