forked from Yara724/api
fix: make user branch selection and signature completion reliable
This commit is contained in:
@@ -8,7 +8,7 @@ Expert/registrar/FileMaker-created flows retain their existing branch/ownership
|
||||
|
||||
All routes below use existing user authentication and the user-role guard:
|
||||
|
||||
- `GET /v2/blame-request-management/:requestId/claim-branches`: authorize case access, resolve the beneficiary/payer, and return `{required, branchId, locked, branches}`. Only the beneficiary receives branch options. Each option contains `id`, `name`, `code`, `city`, `state`, `address`, and optional `phoneNumber`. Options are active branches from the payer only; the client cannot supply an insurer ID.
|
||||
- `GET /v2/blame-request-management/:requestId/claim-branches`: authorize case access, resolve the beneficiary/payer, and return `{required, branchId, locked, branches, claimRequestId?}`. `claimRequestId` is included when a claim already exists for the beneficiary so reloading claim entry can resume it. Locked claims do not fetch branch options. Only the beneficiary receives branch options. Each option contains `id`, `name`, `code`, `city`, `state`, `address`, and optional `phoneNumber`. Options are active branches from the payer only; the client cannot supply an insurer ID.
|
||||
- `PUT /v2/blame-request-management/:requestId/claim-branch`: `{branchId}` saves a validated branch while waiting for signatures or after signing, before any claim exists. This supports historical cases that were already signed when the feature deployed. Other parties cannot select a branch. Existing claims freeze routing; this endpoint cannot move them to another branch.
|
||||
- Existing `PUT /v2/blame-request-management/sign/:requestId` accepts an additional multipart `branchId`. When the damaged user accepts in a user-led flow, a valid branch is mandatory (either supplied now or previously saved). Branch validation occurs before creating the signature record. Confirmation and branch ID are saved in the same blame update. The guilty party signs normally without choosing a branch. Rejection does not require a branch.
|
||||
|
||||
@@ -28,7 +28,7 @@ Existing claims are not migrated or reassigned. Their current access/ownership r
|
||||
|
||||
The city and branch selectors appear above the signature canvas, only for the damaged user. A city change clears the branch selection. Same-named cities in different provinces have separate choices. The selected branch's address and phone are displayed. Loading, fetch failure/retry, empty lists and locked routing have explicit Persian states. Confirmation is disabled until the selection is valid. The signature dialog scrolls vertically on small screens.
|
||||
|
||||
The final screen reuses the selector for cases already signed before rollout; the backend selection rule also protects direct claim entry. Later v6 claim-result signing no longer asks for another branch, avoiding a competing choice. Existing expert-created flows retain their existing result-signing UI.
|
||||
The final screen displays the saved branch by name. It only shows the selector for signed cases without a valid active selection (including historical cases); the backend selection rule also protects direct claim entry. Later v6 claim-result signing no longer asks for another branch, avoiding a competing choice. Existing expert-created flows retain their existing result-signing UI.
|
||||
|
||||
## Deployment and verification
|
||||
|
||||
@@ -55,3 +55,50 @@ The matrix covers v1 car-body, v6 car-body, both possible v1 third-party damaged
|
||||
Browser tests draw a signature, verify its multipart request includes the selected branch, continue to claim creation once, and verify the claim can proceed. Changing city clears the previous branch. Existing signed cases entering `/claim` without a branch return to the branch picker. Separate v1/v6 guilty-party checks confirm no branch selection is requested and no claim-creation button appears. Existing suites cover the flow 2–5 ownership and file-maker/reviewer handoff rules.
|
||||
|
||||
No new application defect was found in this verification pass; the additional HTTP integration tests/configuration were retained as regression coverage. External-provider availability, production branch/staff configuration, real database connectivity/indexes and live SMS delivery were not exercised. Those still require deployment QA; these results do not claim an exhaustive proof of every possible application state.
|
||||
|
||||
## Reliability corrections — 2026-11-16
|
||||
|
||||
The original implementation hydrated the complete case (voice/video URLs, expert profile and claim hints) just to authorize branch loading, then loaded that case again. The branch endpoint now reuses the exact authorization, user binding and workflow recovery logic directly, with no media/profile hydration. Legacy branch city/state values are normalized before sorting.
|
||||
|
||||
The frontend branch query has a 15-second timeout and explicit retry. A disabled query no longer renders a loader; an unparseable local JWT no longer silently disables the query forever. Options are cached for 30 seconds by actor and case; every save/signature and claim creation still validates the selected branch on the server. Empty active-branch lists remain a real setup error, with an explicit Persian explanation. They cannot be bypassed by accepting an arbitrary branch.
|
||||
|
||||
Accepting a signature now returns the persisted status, the viewer's `nextAction`, their confirmation, `claimBranch`, and `claimCreation`. The frontend applies that acknowledgement to both the case and branch caches immediately. It does not wait for an additional case GET before navigating. That cache update is essential: without it the next screen still has the pre-signature `branchId: null` and asks for the same branch again. A normal signed case therefore has one city/branch selection, on the blame-signature screen. Later acceptance of the financial assessment remains a separate legal decision and does not ask v1/v6 users for another branch.
|
||||
|
||||
User-led signatures use conditional writes: the case must still be waiting and the viewer must not already have a confirmation. A repeated identical acceptance returns the stored confirmation and branch without replacing them. A conflicting decision cannot overwrite an existing signature. Signature upload filenames use UUIDs so two users uploading `signature.png` in the same millisecond cannot overwrite each other's image. Completing the case is conditional on the persisted required signatures and waiting status; it uses `$addToSet` for workflow history. The same completion logic recovers interrupted records where all required accepted signatures exist but status remains waiting, on detail/list/branch reads or a safe retry. Stopped files and expert-created flows are excluded from this recovery. A notification failure after saving cannot turn a persisted signature into a failed submission.
|
||||
|
||||
Case status polling continues while waiting for the other party, and the next action switches to claim creation only for the beneficiary. The culprit can sign without a branch and cannot create the claim. Case-detail requests are cancellable and bounded; intentional cancellation does not show a false error toast. Failed signing shows the actual Persian error and preserves the canvas while rechecking the saved state. Closing the signature dialog returns to a page with a signing link. Claim entry offers retry, and an existing claim returned by the branch preflight is resumed instead of creating a second claim.
|
||||
|
||||
### Regression commands
|
||||
|
||||
```bash
|
||||
# API unit/regression suite, plus authenticated HTTP scenarios (mock repositories/providers).
|
||||
npm test -- --runInBand
|
||||
npm run test:e2e -- --runInBand
|
||||
|
||||
# In ui-user:
|
||||
npm run test:ui
|
||||
npx tsc --noEmit
|
||||
```
|
||||
|
||||
The HTTP suite also has an optional combined browser tier. Start the user UI with a temporary test-only API URL, then run the test with Playwright installed. The browser forwards only that mock API prefix to the actual test HTTP controllers; JWT/role guards, case/branch/signature services and claim creation run normally. Database operations and SMS/Fanavaran remain isolated fixtures.
|
||||
|
||||
```bash
|
||||
# ui-user terminal (use a separate dev build if another dev server is running):
|
||||
NEXT_PUBLIC_BASE_URL=http://127.0.0.1:3217/mock-api NEXT_PUBLIC_BASE_PATH='' npm run dev -- --hostname 127.0.0.1 --port 3217
|
||||
|
||||
# api terminal; PLAYWRIGHT_MODULE may point to a locally installed Playwright package.
|
||||
CLAIM_BRANCH_UI_URL=http://127.0.0.1:3217 PLAYWRIGHT_MODULE=/path/to/playwright npm run test:e2e -- --runInBand
|
||||
# Optional: CLAIM_BRANCH_BROWSER_EXECUTABLE=/path/to/chrome-or-brave
|
||||
```
|
||||
|
||||
Deploy API and ui-user together. No environment/schema migration is needed. Existing active branches and expert branch assignments are still required. No production data, real provider availability or live SMS delivery is exercised by these isolated tests.
|
||||
|
||||
### Verification of the corrections
|
||||
|
||||
- API: **97 suites / 874 tests passed**.
|
||||
- Authenticated HTTP + combined mobile browser tier: **30 scenarios passed**, including four real UI → controller → persistence scenarios for v1/v6 × car-body/third-party. Database repositories and providers are mocked.
|
||||
- Additional isolated browser matrix: **13 normal/legacy/error scenarios and 6 recovery scenarios passed**, covering desktop/mobile layouts, delayed GETs after signing, guilty-party access, historic signed cases, branch errors/timeouts, empty options, waiting for the other signature, failed signing, double-clicks and cancellation. These use Chromium/Brave with emulated desktop/mobile viewports and drawn canvas signatures.
|
||||
- Complete user UI regression script, API/user TypeScript checks and whitespace checks passed.
|
||||
- The default Next.js production build (`npm run build`) passed with normal build-worker permissions. The initial sandboxed compilation was stopped after stalling; no deployment configuration was changed.
|
||||
|
||||
The tests do not change production data or contact SMS/Fanavaran. The browser tier is intentionally opt-in so a developer without Playwright can still run all HTTP tests; use the command above to include it.
|
||||
|
||||
Reference in New Issue
Block a user