X
SF Formations Test Coverage
SF Formation coverage lives in apps/dashboard/__tests__/sf-formations and
validates the helper layer that powers the multi-step incorporation workflow.
The tests keep entity metadata, navigation rules, and member validation aligned
with the business requirements defined in @/lib/sf-formation-utils.
Suite highlights
- Slugging & metadata:
toSlugensures entity names convert to predictable identifiers (lowercase, underscore-separated, punctuation removed) so schema lookups never fail due to casing. - Jurisdiction mapping:
getCountryCodemaps each supported entity type to the two-letter ISO code mandated by workspace rules (NL,US,BE, etc.), while returningundefinedfor unknown entities to prevent bogus payloads. - Ownership math:
getMemberSharesnormalizes string/number percentages and surfacesNaNwhen values cannot be parsed, helping the UI surface validation errors early. - Stepper flow:
isFinalStepandgenerateStepperStepskeep navigation consistent when schemas change, converting snake_case step keys into user friendly titles. - Contract detection:
hasContractPackageFieldprotects the case creation flow by checking if the form requires contract package selection. - Supabase queries:
buildCaseConditionsbuilds the standard condition array for{APP_CONFIG.api.suitsbooks}/fetch/datarequests so downstream consumers can reuse the helper safely. - Naming & members:
getCompanyNamecentralizes fallback logic when the primary name is missing, andisValidMemberenforces required personal fields before generating payloads. - Integration path: The bottom portion of the file strings the helpers together to simulate full submissions, catching regressions in how payloads are assembled for database writes.
Running the suite
pnpm vitest run apps/dashboard/__tests__/sf-formations/form.test.ts
```typescript
### Tips when extending
- Keep new helpers pure and add them to `@/lib/sf-formation-utils`; mirror the
naming conventions so `import` paths stay consistent with the existing tests.
- If a helper reaches out to external services, follow the workspace API rules
by stubbing fetches via `{APP_CONFIG.api.suitsbooks}` endpoints inside the
test before shipping.
- Expand the integration block whenever the end-to-end data shape changes—this
is the fastest way to confirm contract payloads still satisfy downstream
automations.