feat(interests): CM-2 Part B — EOI/doc generation honours berth price override

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-19 10:41:42 +02:00
parent 039ef25fe5
commit 38e392e38b
2 changed files with 51 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest';
import { buildEoiContext } from '@/lib/services/eoi-context';
import { setBerthPriceOverride } from '@/lib/services/interest-berths.service';
import { makePort, makeClient, makeCompany, makeBerth, makeYacht } from '../../helpers/factories';
import { db } from '@/lib/db';
import {
@@ -338,6 +339,32 @@ describe('buildEoiContext', () => {
await expect(buildEoiContext(interest.id, port.id)).rejects.toThrow(/client address/i);
});
it('renders the deal-specific override price for the primary berth', async () => {
const port = await makePort();
const client = await makeClient({ portId: port.id });
await seedClientEoiPrereqs({ clientId: client.id, portId: port.id });
const berth = await makeBerth({
portId: port.id,
overrides: { mooringNumber: 'P-1', price: '3880800', priceCurrency: 'USD' },
});
const interest = await insertInterest({
portId: port.id,
clientId: client.id,
berthId: berth.id,
});
// Base list price flows through first.
let ctx = await buildEoiContext(interest.id, port.id);
expect(ctx.berth?.price).toBe('3880800');
expect(ctx.berth?.priceCurrency).toBe('USD');
// The deal-specific override supersedes the list price for this interest.
await setBerthPriceOverride(interest.id, berth.id, 1500000, 'EUR', port.id);
ctx = await buildEoiContext(interest.id, port.id);
expect(ctx.berth?.price).toBe('1500000');
expect(ctx.berth?.priceCurrency).toBe('EUR');
});
it('throws NotFoundError for non-existent interest', async () => {
const port = await makePort();
await expect(buildEoiContext('fake-id', port.id)).rejects.toThrow(NotFoundError);