Skip to content

[optikt-app] Test coverage infrastructure + 469 new unit tests (Phase 0–2)#31

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/explore-codebase-measure-test-coverage
Draft

[optikt-app] Test coverage infrastructure + 469 new unit tests (Phase 0–2)#31
Copilot wants to merge 5 commits intomainfrom
copilot/explore-codebase-measure-test-coverage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Test coverage was ~9% with 361 tests across 25 spec files. This PR establishes coverage measurement infrastructure and adds comprehensive tests for all pure functions, schemas, enums, and server-side logic that require no database.

Phase 0: Coverage Infrastructure

  • Installed @vitest/coverage-v8, added test:coverage script
  • Added v8 coverage config to vite.config.ts (text, lcov, json-summary reporters)
  • CI workflow now runs with --coverage and uploads reports as artifacts

Phase 1: Pure Function Tests (+423 tests)

  • Utils (5 files): opticalRange, prescription, products, csv, generateUUID
  • Schemas (10 files): auth, brands, customers, exchangeRates, lenses, reports, search, settings, suppliers, users — validates parsing, transforms, refinements, defaults
  • Shared enums/contracts (8 files): purchaseTypes, currencyTypes, lensTypes, supplierTypes, inventoryTypes, salesTypes, common, search — covers enum values, label functions, badge colors, predicates, fallbacks

Phase 2: Server-Side Logic (+46 tests)

  • guards.spec.ts — mocks $app/server and @sveltejs/kit error to test requireAuth, requireRole, requireAdmin, requireSuperuser (401/403 paths)
  • audit/utils.spec.tscalculateDiff, createChangeRecordForCreate, createChangeRecordForDelete, hasChanges including excluded fields, Date normalization, nested objects

Result

Metric Before After
Test files 25 50
Test cases 361 830

Pre-existing failure (auth.spec.ts requires DATABASE_URL) is unchanged. Remaining untested areas (DB queries, remote functions, components, routes, E2E) are tracked for Phase 3–6.

Copilot AI and others added 5 commits April 12, 2026 17:55
Add spec files for opticalRange, prescription, products, csv, and generateUUID
utils with 70 tests covering all exports, edge cases, and null handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: NanezX <81595884+NanezX@users.noreply.github.com>
Add test coverage for auth, brands, customers, exchangeRates, lenses,
reports, search, settings, suppliers, and users schemas. Tests cover:
- Valid inputs with safeParse success
- Required field validation
- Invalid types and boundary lengths
- Default value application
- Transform behavior (trim, lowercase, coercion)
- Refinements and cross-field validation
- Edge cases (empty strings, boundary values)

220 tests across 10 new spec files, all passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: NanezX <81595884+NanezX@users.noreply.github.com>
Add 133 tests across 8 new spec files covering:
- purchaseTypes (status, item type, labels, badge colors)
- currencyTypes (codes, labels, symbols, base currency)
- lensTypes (6 enums, labels, badge colors)
- supplierTypes (types, labels, badge colors)
- inventoryTypes (movements, references, adjustments, loss reasons)
- salesTypes (status, payment, discount, refund)
- contracts/common (PatientEye enum)
- contracts/search (SearchScope, prefixes, labels)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: NanezX <81595884+NanezX@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants