Flag-gated (website_intake_email_enabled, default OFF) sending of registrant confirmation + staff alert for inquiries captured at /api/public/website-inquiries, reusing the branded berth + residential templates and adding contact-form client-confirmation + sales-alert templates. In-app (bell) notifications fire on every fresh capture, independent of the flag. Recipients resolve from the existing inquiry_/residential_notification_recipients settings; fires only on a fresh (non-deduped) insert so retries never re-send. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
|
|
import { extractInquiryFields } from '@/lib/services/website-intake-fields';
|
|
|
|
describe('extractInquiryFields', () => {
|
|
it('maps a berth inquiry payload (berth -> mooringNumber)', () => {
|
|
const f = extractInquiryFields({
|
|
first_name: 'Jane',
|
|
last_name: 'Doe',
|
|
email: 'jane@example.com',
|
|
phone: '+15551234',
|
|
berth: 'A1',
|
|
interest: 'berths',
|
|
});
|
|
expect(f).toMatchObject({
|
|
firstName: 'Jane',
|
|
lastName: 'Doe',
|
|
fullName: 'Jane Doe',
|
|
email: 'jane@example.com',
|
|
phone: '+15551234',
|
|
mooringNumber: 'A1',
|
|
placeOfResidence: null,
|
|
});
|
|
});
|
|
|
|
it('maps a residence inquiry payload (address -> placeOfResidence, no mooring)', () => {
|
|
const f = extractInquiryFields({
|
|
first_name: 'Sam',
|
|
last_name: 'Lee',
|
|
email: 's@example.com',
|
|
phone: '2',
|
|
address: 'London',
|
|
interest: 'residences',
|
|
});
|
|
expect(f.mooringNumber).toBeNull();
|
|
expect(f.placeOfResidence).toBe('London');
|
|
expect(f.fullName).toBe('Sam Lee');
|
|
});
|
|
|
|
it('maps a contact form payload (interest[] -> joined interestType + comments)', () => {
|
|
const f = extractInquiryFields({
|
|
first_name: 'Ann',
|
|
last_name: 'Poe',
|
|
email: 'a@example.com',
|
|
interest: ['owner', 'broker'],
|
|
comments: 'Please call me',
|
|
});
|
|
expect(f.interestType).toBe('owner, broker');
|
|
expect(f.comments).toBe('Please call me');
|
|
expect(f.phone).toBe('');
|
|
});
|
|
|
|
it('trims whitespace and degrades missing/garbage fields safely', () => {
|
|
const f = extractInquiryFields({ first_name: ' Jo ', last_name: 42 as unknown });
|
|
expect(f.firstName).toBe('Jo');
|
|
expect(f.fullName).toBe('Jo');
|
|
expect(f.email).toBe('');
|
|
expect(f.mooringNumber).toBeNull();
|
|
expect(f.interestType).toBeNull();
|
|
});
|
|
|
|
it('returns all-empty for an empty payload', () => {
|
|
expect(extractInquiryFields({})).toMatchObject({
|
|
firstName: '',
|
|
lastName: '',
|
|
fullName: '',
|
|
email: '',
|
|
phone: '',
|
|
mooringNumber: null,
|
|
placeOfResidence: null,
|
|
comments: null,
|
|
interestType: null,
|
|
});
|
|
});
|
|
});
|