Files
pn-new-crm/tests/unit/website-intake-promote.test.ts
Matt 15a139e86f
All checks were successful
Build & Push Docker Images / lint (push) Successful in 2m47s
Build & Push Docker Images / build-and-push (push) Successful in 6m49s
feat(berths): website auto-promote toggle + manual-override soft-pin priority
- 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>
2026-06-02 20:10:04 +02:00

47 lines
1.5 KiB
TypeScript

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);
});
});