All checks were successful
CI / Unit & Component Tests (push) Successful in 5m10s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 5m14s
CI / fail2ban Regex (push) Successful in 50s
CI / Semgrep Security Scan (push) Successful in 27s
CI / Compose Bucket Idempotency (push) Successful in 1m5s
Closes #837 Makes `PersonRelationship` fully editable (type, related person, dates, notes), migrates its dates from `Integer fromYear/toYear` to `LocalDate + DatePrecision` (mirroring the #773 person pattern, ADR-039 / V76), activates the previously-dead `notes` column, and gives the Zeitstrahl's derived **Heirat** events full date precision for free. Both Open Decisions confirmed as adopted: **no `@Version`** (last-write-wins, single-writer archive) and **`DELETE` ownership-mismatch aligned 403 → 404** (anti-enumeration, matching the new `PUT`). ## What's in it - **V78** migrates `person_relationships.from_year/to_year` → `from_date`/`to_date` + NOT-NULL `*_date_precision` (default `UNKNOWN`); pre-check abort on corrupt years, `YYYY-01-01`/`YEAR` backfill, 5 named CHECK constraints, year columns dropped. - **`PUT /api/persons/{id}/relationships/{relId}`** (`@RequirePermission(WRITE_ALL)`) re-runs every create invariant (self / coherence / order / reverse-PARENT_OF / duplicate) and re-flags family membership; orientation preserved per viewpoint. - New `ErrorCode.INVALID_RELATIONSHIP_DATES` registered in all four sites (§3.6). - `TimelineEventService` sources the derived marriage date from `SPOUSE_OF.fromDate` + precision. - Frontend: `RelationshipDateField` (DAY/MONTH/YEAR), upsert-capable `AddRelationshipForm` (pre-fill + notes + in-flight submit lock), `RelationshipChip` Edit affordance, `updateRelationship` server action, read-view date range + notes, `formatRelationshipDateRange` helper. `api.ts` regenerated. - Docs: ADR-044, db-orm/db-relationships diagrams, DEPLOYMENT §5 deploy note, RTM REQ-001…REQ-019. ## Requirements All 19 EARS requirements implemented red/green and marked `Done` in `.specify/rtm.md`. ## Test plan - **Backend** (targeted, green): `RelationshipMigrationTest` (Testcontainers pg16, 8), `RelationshipServiceTest` (22), `RelationshipControllerTest` (15), `RelationshipServiceIntegrationTest` (real DB, 10), `DerivedEventsAssemblyTest` (17), `ArchitectureTest` (14); `clean package` builds. - **Frontend** (green): `relationshipDates.spec.ts`, `AddRelationshipForm.svelte.spec.ts`, `RelationshipChip.svelte.spec.ts`, `PersonRelationshipsCard.svelte.test.ts`, `page.server.spec.ts`, `messages.spec.ts`. `npm run check` = 798 (below the ~834 baseline); `npm run lint` clean. ## Notes for reviewers - **Spec deviation:** the edit form was built by making `AddRelationshipForm` upsert-capable rather than a duplicate `EditRelationshipForm` (DRY); RTM rows reference `AddRelationshipForm.svelte.spec.ts`. - `api.ts` regenerated from the live spec; only relationship-relevant hunks remain (one springdoc `PageableObject` field-reorder pruned). - **Deploy:** V78 is one-way and not rolling-deploy-safe — stop old JAR → start new JAR (Flyway runs first); targeted `pg_restore -t person_relationships` for rollback. No maintenance window. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Marcel <marcel@familienarchiv> Reviewed-on: #841
110 lines
4.0 KiB
TypeScript
110 lines
4.0 KiB
TypeScript
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
import { cleanup, render } from 'vitest-browser-svelte';
|
|
import { page } from 'vitest/browser';
|
|
import AddRelationshipForm from './AddRelationshipForm.svelte';
|
|
|
|
afterEach(cleanup);
|
|
|
|
describe('AddRelationshipForm', () => {
|
|
it('renders the toggle button to open the form', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1' } });
|
|
|
|
await expect.element(page.getByRole('button', { name: /hinzufügen/i })).toBeVisible();
|
|
});
|
|
|
|
it('opens the form when the toggle button is clicked', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1' } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
|
|
expect(document.querySelector('select[name="relationType"]')).not.toBeNull();
|
|
});
|
|
|
|
it('renders all relationship type options when open', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1' } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
|
|
const select = document.querySelector('select[name="relationType"]') as HTMLSelectElement;
|
|
const optionValues = Array.from(select.options).map((o) => o.value);
|
|
expect(optionValues).toContain('PARENT_OF');
|
|
expect(optionValues).toContain('SPOUSE_OF');
|
|
expect(optionValues).toContain('FRIEND');
|
|
expect(optionValues).toContain('OTHER');
|
|
});
|
|
|
|
it('cancel button closes the form', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1' } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
expect(document.querySelector('select[name="relationType"]')).not.toBeNull();
|
|
|
|
const cancelBtn = Array.from(document.querySelectorAll('button')).find((b) =>
|
|
b.textContent?.toLowerCase().includes('abbrechen')
|
|
);
|
|
expect(cancelBtn).toBeDefined();
|
|
cancelBtn?.click();
|
|
|
|
await vi.waitFor(() => {
|
|
expect(document.querySelector('select[name="relationType"]')).toBeNull();
|
|
});
|
|
});
|
|
|
|
it('does not invoke onSubmit before user submission', async () => {
|
|
const onSubmit = vi.fn().mockResolvedValue(undefined);
|
|
render(AddRelationshipForm, { props: { personId: 'p-1', onSubmit } });
|
|
|
|
// Without a person selected, the form cannot be submitted by the user.
|
|
expect(onSubmit).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('renders with use:enhance form action when onSubmit is undefined', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1' } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
|
|
await vi.waitFor(() => {
|
|
expect(document.querySelector('form[action="?/addRelationship"]')).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
it('renders the callback-based form when onSubmit is provided', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1', onSubmit: async () => {} } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
|
|
await vi.waitFor(() => {
|
|
// callback form has no action attribute (just onsubmit handler)
|
|
expect(document.querySelector('form[action="?/addRelationship"]')).toBeNull();
|
|
expect(document.querySelector('form')).not.toBeNull();
|
|
});
|
|
});
|
|
|
|
it('shows the self-error when the related person id equals personId', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-self' } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
const relInput = (await vi.waitFor(() => {
|
|
const el = document.querySelector('input[name="relatedPersonId"]') as HTMLInputElement;
|
|
expect(el).not.toBeNull();
|
|
return el;
|
|
})) as HTMLInputElement;
|
|
relInput.value = 'p-self';
|
|
relInput.dispatchEvent(new Event('input', { bubbles: true }));
|
|
|
|
await expect.element(page.getByText(/selbst|self/i)).toBeVisible();
|
|
});
|
|
|
|
it('keeps submit disabled when no related person is selected', async () => {
|
|
render(AddRelationshipForm, { props: { personId: 'p-1' } });
|
|
|
|
await page.getByRole('button', { name: /hinzufügen/i }).click();
|
|
|
|
await vi.waitFor(() => {
|
|
const submitBtn = document.querySelector('button[type="submit"]') as HTMLButtonElement | null;
|
|
expect(submitBtn).not.toBeNull();
|
|
expect(submitBtn!.disabled).toBe(true);
|
|
});
|
|
});
|
|
});
|