2026-04-23 23:40:56 +02:00
|
|
|
import { describe, it, expect } from 'vitest';
|
feat(yachts): list + owner-scoped list + autocomplete
Adds `listYachts`, `listYachtsForOwner`, and `autocomplete` to the
yacht service so UIs can page/filter yachts per port, look up all
yachts tied to a given client/company, and power search-as-you-type.
`listYachts` delegates to the shared port-scoped `buildListQuery`,
supporting search over name/hullNumber/registration plus ownerType,
ownerId and status filters; `autocomplete` caps at 10 results and is
tenant-scoped; `listYachtsForOwner` returns all yachts whose current
owner matches, newest first. Extends `makeYacht` factory to accept
flat `name`, `status`, `hullNumber`, `registration` overrides.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:03:36 +02:00
|
|
|
import {
|
|
|
|
|
createYacht,
|
|
|
|
|
updateYacht,
|
|
|
|
|
archiveYacht,
|
|
|
|
|
listYachts,
|
|
|
|
|
listYachtsForOwner,
|
|
|
|
|
autocomplete,
|
|
|
|
|
} from '@/lib/services/yachts.service';
|
|
|
|
|
import {
|
|
|
|
|
makeClient,
|
|
|
|
|
makeCompany,
|
|
|
|
|
makePort,
|
|
|
|
|
makeYacht,
|
|
|
|
|
makeAuditMeta,
|
|
|
|
|
} from '../../helpers/factories';
|
2026-04-23 23:40:56 +02:00
|
|
|
import { db } from '@/lib/db';
|
2026-04-23 23:52:24 +02:00
|
|
|
import { yachts, yachtOwnershipHistory } from '@/lib/db/schema';
|
2026-04-23 23:40:56 +02:00
|
|
|
import { eq } from 'drizzle-orm';
|
|
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('yachts.service - createYacht', () => {
|
2026-04-23 23:40:56 +02:00
|
|
|
it('creates a yacht with a client owner and opens an ownership history row', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
|
|
|
|
|
const yacht = await createYacht(
|
|
|
|
|
port.id,
|
|
|
|
|
{
|
|
|
|
|
name: 'Sea Breeze',
|
|
|
|
|
owner: { type: 'client', id: client.id },
|
|
|
|
|
},
|
|
|
|
|
makeAuditMeta(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(yacht.currentOwnerType).toBe('client');
|
|
|
|
|
expect(yacht.currentOwnerId).toBe(client.id);
|
|
|
|
|
|
|
|
|
|
const history = await db
|
|
|
|
|
.select()
|
|
|
|
|
.from(yachtOwnershipHistory)
|
|
|
|
|
.where(eq(yachtOwnershipHistory.yachtId, yacht.id));
|
|
|
|
|
expect(history).toHaveLength(1);
|
|
|
|
|
expect(history[0]!.endDate).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects when ownerType=client but ownerId does not exist', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
await expect(
|
|
|
|
|
createYacht(
|
|
|
|
|
port.id,
|
|
|
|
|
{ name: 'Phantom', owner: { type: 'client', id: 'nonexistent' } },
|
|
|
|
|
makeAuditMeta(),
|
|
|
|
|
),
|
|
|
|
|
).rejects.toThrow(/owner not found/i);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects when ownerType=company but ownerId does not exist', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
await expect(
|
|
|
|
|
createYacht(
|
|
|
|
|
port.id,
|
|
|
|
|
{ name: 'Phantom', owner: { type: 'company', id: 'nonexistent' } },
|
|
|
|
|
makeAuditMeta(),
|
|
|
|
|
),
|
|
|
|
|
).rejects.toThrow(/owner not found/i);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects owner from a different tenant (cross-tenant guard)', async () => {
|
|
|
|
|
const portA = await makePort();
|
|
|
|
|
const portB = await makePort();
|
|
|
|
|
const clientInB = await makeClient({ portId: portB.id });
|
|
|
|
|
await expect(
|
|
|
|
|
createYacht(
|
|
|
|
|
portA.id,
|
|
|
|
|
{ name: 'Wrong Port', owner: { type: 'client', id: clientInB.id } },
|
|
|
|
|
makeAuditMeta(),
|
|
|
|
|
),
|
|
|
|
|
).rejects.toThrow(/owner not found/i);
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-04-23 23:52:24 +02:00
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('yachts.service - updateYacht', () => {
|
2026-04-23 23:52:24 +02:00
|
|
|
it('updates name and notes', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
const yacht = await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
overrides: { name: 'Original Name' },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const updated = await updateYacht(
|
|
|
|
|
yacht.id,
|
|
|
|
|
port.id,
|
|
|
|
|
{ name: 'New Name', notes: 'Updated notes' },
|
|
|
|
|
makeAuditMeta(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(updated.name).toBe('New Name');
|
|
|
|
|
expect(updated.notes).toBe('Updated notes');
|
|
|
|
|
|
|
|
|
|
const [row] = await db.select().from(yachts).where(eq(yachts.id, yacht.id));
|
|
|
|
|
expect(row!.name).toBe('New Name');
|
|
|
|
|
expect(row!.notes).toBe('Updated notes');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects when id does not exist or is cross-tenant', async () => {
|
|
|
|
|
const portA = await makePort();
|
|
|
|
|
const portB = await makePort();
|
|
|
|
|
const clientInB = await makeClient({ portId: portB.id });
|
|
|
|
|
const yachtInB = await makeYacht({
|
|
|
|
|
portId: portB.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: clientInB.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
updateYacht(yachtInB.id, portA.id, { name: 'Hijack' }, makeAuditMeta()),
|
|
|
|
|
).rejects.toThrow(/yacht/i);
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
updateYacht('nonexistent-id', portA.id, { name: 'Phantom' }, makeAuditMeta()),
|
|
|
|
|
).rejects.toThrow(/yacht/i);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects attempt to change currentOwnerId via update', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
const yacht = await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
updateYacht(
|
|
|
|
|
yacht.id,
|
|
|
|
|
port.id,
|
|
|
|
|
{ currentOwnerId: 'some-other-id' } as unknown as { name: string },
|
|
|
|
|
makeAuditMeta(),
|
|
|
|
|
),
|
|
|
|
|
).rejects.toThrow(/transfer to change ownership/i);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('yachts.service - archiveYacht', () => {
|
2026-04-23 23:52:24 +02:00
|
|
|
it('sets archivedAt to a non-null timestamp', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
const yacht = await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await archiveYacht(yacht.id, port.id, makeAuditMeta());
|
|
|
|
|
|
|
|
|
|
const [row] = await db.select().from(yachts).where(eq(yachts.id, yacht.id));
|
|
|
|
|
expect(row!.archivedAt).not.toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws NotFound for cross-tenant or missing yacht', async () => {
|
|
|
|
|
const portA = await makePort();
|
|
|
|
|
const portB = await makePort();
|
|
|
|
|
const clientInB = await makeClient({ portId: portB.id });
|
|
|
|
|
const yachtInB = await makeYacht({
|
|
|
|
|
portId: portB.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: clientInB.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await expect(archiveYacht(yachtInB.id, portA.id, makeAuditMeta())).rejects.toThrow(/yacht/i);
|
|
|
|
|
});
|
|
|
|
|
});
|
feat(yachts): list + owner-scoped list + autocomplete
Adds `listYachts`, `listYachtsForOwner`, and `autocomplete` to the
yacht service so UIs can page/filter yachts per port, look up all
yachts tied to a given client/company, and power search-as-you-type.
`listYachts` delegates to the shared port-scoped `buildListQuery`,
supporting search over name/hullNumber/registration plus ownerType,
ownerId and status filters; `autocomplete` caps at 10 results and is
tenant-scoped; `listYachtsForOwner` returns all yachts whose current
owner matches, newest first. Extends `makeYacht` factory to accept
flat `name`, `status`, `hullNumber`, `registration` overrides.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:03:36 +02:00
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('yachts.service - listYachts', () => {
|
feat(yachts): list + owner-scoped list + autocomplete
Adds `listYachts`, `listYachtsForOwner`, and `autocomplete` to the
yacht service so UIs can page/filter yachts per port, look up all
yachts tied to a given client/company, and power search-as-you-type.
`listYachts` delegates to the shared port-scoped `buildListQuery`,
supporting search over name/hullNumber/registration plus ownerType,
ownerId and status filters; `autocomplete` caps at 10 results and is
tenant-scoped; `listYachtsForOwner` returns all yachts whose current
owner matches, newest first. Extends `makeYacht` factory to accept
flat `name`, `status`, `hullNumber`, `registration` overrides.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:03:36 +02:00
|
|
|
it('is scoped to port (tenant isolation)', async () => {
|
|
|
|
|
const portA = await makePort();
|
|
|
|
|
const portB = await makePort();
|
|
|
|
|
const clientA = await makeClient({ portId: portA.id });
|
|
|
|
|
const clientB = await makeClient({ portId: portB.id });
|
|
|
|
|
await makeYacht({ portId: portA.id, ownerType: 'client', ownerId: clientA.id, name: 'In A' });
|
|
|
|
|
await makeYacht({ portId: portB.id, ownerType: 'client', ownerId: clientB.id, name: 'In B' });
|
|
|
|
|
|
|
|
|
|
const result = await listYachts(portA.id, {
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 20,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
includeArchived: false,
|
|
|
|
|
});
|
|
|
|
|
expect(result.data.some((y) => y.name === 'In A')).toBe(true);
|
|
|
|
|
expect(result.data.some((y) => y.name === 'In B')).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('filters by ownerType + ownerId', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
const other = await makeClient({ portId: port.id });
|
|
|
|
|
await makeYacht({ portId: port.id, ownerType: 'client', ownerId: client.id, name: 'Mine' });
|
|
|
|
|
await makeYacht({ portId: port.id, ownerType: 'client', ownerId: other.id, name: 'Theirs' });
|
|
|
|
|
|
|
|
|
|
const result = await listYachts(port.id, {
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 20,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
includeArchived: false,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
});
|
|
|
|
|
expect(result.data.map((y) => y.name)).toContain('Mine');
|
|
|
|
|
expect(result.data.map((y) => y.name)).not.toContain('Theirs');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('filters by status', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
name: 'Active One',
|
|
|
|
|
status: 'active',
|
|
|
|
|
});
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
name: 'Retired One',
|
|
|
|
|
status: 'retired',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await listYachts(port.id, {
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 20,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
includeArchived: false,
|
|
|
|
|
status: 'retired',
|
|
|
|
|
});
|
|
|
|
|
expect(result.data.map((y) => y.name)).toContain('Retired One');
|
|
|
|
|
expect(result.data.map((y) => y.name)).not.toContain('Active One');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('searches by name (ILIKE)', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
name: 'Sea Breeze',
|
|
|
|
|
});
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
name: 'Wind Dancer',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await listYachts(port.id, {
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 20,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
includeArchived: false,
|
|
|
|
|
search: 'breeze',
|
|
|
|
|
});
|
|
|
|
|
expect(result.data.map((y) => y.name)).toContain('Sea Breeze');
|
|
|
|
|
expect(result.data.map((y) => y.name)).not.toContain('Wind Dancer');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('yachts.service - listYachtsForOwner', () => {
|
feat(yachts): list + owner-scoped list + autocomplete
Adds `listYachts`, `listYachtsForOwner`, and `autocomplete` to the
yacht service so UIs can page/filter yachts per port, look up all
yachts tied to a given client/company, and power search-as-you-type.
`listYachts` delegates to the shared port-scoped `buildListQuery`,
supporting search over name/hullNumber/registration plus ownerType,
ownerId and status filters; `autocomplete` caps at 10 results and is
tenant-scoped; `listYachtsForOwner` returns all yachts whose current
owner matches, newest first. Extends `makeYacht` factory to accept
flat `name`, `status`, `hullNumber`, `registration` overrides.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:03:36 +02:00
|
|
|
it('returns all yachts owned by a given client', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
await makeYacht({ portId: port.id, ownerType: 'client', ownerId: client.id, name: 'Y1' });
|
|
|
|
|
await makeYacht({ portId: port.id, ownerType: 'client', ownerId: client.id, name: 'Y2' });
|
|
|
|
|
|
|
|
|
|
const result = await listYachtsForOwner(port.id, 'client', client.id);
|
|
|
|
|
expect(result.map((y) => y.name).sort()).toEqual(['Y1', 'Y2']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns all yachts owned by a given company', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const company = await makeCompany({ portId: port.id });
|
|
|
|
|
await makeYacht({ portId: port.id, ownerType: 'company', ownerId: company.id, name: 'CY1' });
|
|
|
|
|
|
|
|
|
|
const result = await listYachtsForOwner(port.id, 'company', company.id);
|
|
|
|
|
expect(result.map((y) => y.name)).toEqual(['CY1']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('is tenant-scoped', async () => {
|
|
|
|
|
const portA = await makePort();
|
|
|
|
|
const portB = await makePort();
|
|
|
|
|
const clientA = await makeClient({ portId: portA.id });
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: portA.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: clientA.id,
|
|
|
|
|
name: 'Only-A',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await listYachtsForOwner(portB.id, 'client', clientA.id);
|
|
|
|
|
expect(result).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
chore(autonomous-session): consolidate uncommitted work from prior session
Bundles the prior autonomous-session output that was sitting unstaged:
- Em-dash sweep across src/ + tests/ (en-dash/em-dash to hyphen, ~2280 instances)
- country-flag-icons rollout (CountryFlag component, replaces emoji glyphs that
never rendered on Windows; lazy-loads the 3x2 SVG index as a single chunk
after the per-subpath dynamic-import approach silently failed in webpack)
- Admin IA Phase 1+2: 7-domain regroup, 41 to 38 pages, /admin/berths index,
redirects (ocr to ai, reports to dashboard, invitations to users),
docs/admin-ia-proposal.md
- Per-template email tester (registry + endpoint + UI on Email admin page)
- Cancel-document mode picker (delete-from-Documenso vs keep-for-audit)
- Dashboard PDF report: 25 widgets, SVG charts, date-range picker, 11 resolvers
- Customize-widgets per-region sortables at xl+ (charts/rails/feed); single
flat sortable below xl when the layout stacks; per-viewport saved orders
- Audit doc updates capturing each shipped item
- Lint fixes: react-compiler immutability in DonutChart (reduce instead of
let-reassign), set-state-in-effect disables in CountryFlag and
UploadForSigning preview-bytes effect, unused 'confirm' destructures in
interest contract + reservation tabs, unescaped apostrophe in test-template
card copy
2026-05-23 00:52:59 +02:00
|
|
|
describe('yachts.service - autocomplete', () => {
|
feat(yachts): list + owner-scoped list + autocomplete
Adds `listYachts`, `listYachtsForOwner`, and `autocomplete` to the
yacht service so UIs can page/filter yachts per port, look up all
yachts tied to a given client/company, and power search-as-you-type.
`listYachts` delegates to the shared port-scoped `buildListQuery`,
supporting search over name/hullNumber/registration plus ownerType,
ownerId and status filters; `autocomplete` caps at 10 results and is
tenant-scoped; `listYachtsForOwner` returns all yachts whose current
owner matches, newest first. Extends `makeYacht` factory to accept
flat `name`, `status`, `hullNumber`, `registration` overrides.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 00:03:36 +02:00
|
|
|
it('matches by name (ILIKE)', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
await makeYacht({ portId: port.id, ownerType: 'client', ownerId: client.id, name: 'Phoenix' });
|
|
|
|
|
|
|
|
|
|
const result = await autocomplete(port.id, 'phoe');
|
|
|
|
|
expect(result.some((y) => y.name === 'Phoenix')).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('matches by hullNumber or registration', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
name: 'Something',
|
|
|
|
|
hullNumber: 'HULL-ABC-123',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await autocomplete(port.id, 'HULL-ABC');
|
|
|
|
|
expect(result.some((y) => y.hullNumber === 'HULL-ABC-123')).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('is tenant-scoped and caps at 10 results', async () => {
|
|
|
|
|
const port = await makePort();
|
|
|
|
|
const other = await makePort();
|
|
|
|
|
const client = await makeClient({ portId: port.id });
|
|
|
|
|
const otherClient = await makeClient({ portId: other.id });
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 12; i++) {
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: port.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: client.id,
|
|
|
|
|
name: `MatchMe-${i}`,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
await makeYacht({
|
|
|
|
|
portId: other.id,
|
|
|
|
|
ownerType: 'client',
|
|
|
|
|
ownerId: otherClient.id,
|
|
|
|
|
name: 'MatchMe-other',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await autocomplete(port.id, 'matchme');
|
|
|
|
|
expect(result.length).toBe(10);
|
|
|
|
|
expect(result.every((y) => y.name.startsWith('MatchMe-') && !y.name.endsWith('-other'))).toBe(
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|