XYLEX Group
DevelopmentTestsSF Formations Tests

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: toSlug ensures entity names convert to predictable identifiers (lowercase, underscore-separated, punctuation removed) so schema lookups never fail due to casing.
  • Jurisdiction mapping: getCountryCode maps each supported entity type to the two-letter ISO code mandated by workspace rules (NL, US, BE, etc.), while returning undefined for unknown entities to prevent bogus payloads.
  • Ownership math: getMemberShares normalizes string/number percentages and surfaces NaN when values cannot be parsed, helping the UI surface validation errors early.
  • Stepper flow: isFinalStep and generateStepperSteps keep navigation consistent when schemas change, converting snake_case step keys into user friendly titles.
  • Contract detection: hasContractPackageField protects the case creation flow by checking if the form requires contract package selection.
  • Supabase queries: buildCaseConditions builds the standard condition array for {APP_CONFIG.api.suitsbooks}/fetch/data requests so downstream consumers can reuse the helper safely.
  • Naming & members: getCompanyName centralizes fallback logic when the primary name is missing, and isValidMember enforces 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.