Skip to content

🧹 Add comprehensive test coverage across all layers #173

@fusion94

Description

@fusion94

Summary

The project currently has 14 test files covering 96 tests, but only 14.4% of testable files have any test coverage. Major gaps exist across server routes (0%), components (9%), and services (25%). This issue tracks the work needed to bring test coverage up to a reasonable baseline across all layers.

Current State

Category Tested Untested Coverage
Server Routes 0 9 0%
Frontend Services 4 12 25%
Components 5 50 9%
Utilities 1 2 33%
Contexts 2 1 67%
Types 2 9 18%

Existing Tests (14 files, 96 tests)

  • src/types/Item.test.ts (6), src/types/User.test.ts (5)
  • src/services/itemService.test.ts (14), src/services/userService.test.ts (6), src/services/authService.test.ts (3), src/services/storage.test.ts (6)
  • src/utils/export.test.ts (11)
  • src/contexts/AlertContext.test.tsx (9), src/contexts/ThemeContext.test.tsx (6)
  • src/components/common/Pagination.test.tsx (13), src/components/common/ConfirmModal.test.tsx (7), src/components/common/AlertDisplay.test.tsx (4), src/components/auth/ProtectedRoute.test.tsx (4), src/components/layout/Footer.test.tsx (2)

Missing Tests

Priority 1: Server Route Tests (0/9 covered)

These are the most critical gap — no API endpoint testing exists.

  • server/routes/items.ts — CRUD, children endpoint, bulk delete, reorder/low-stock queries
  • server/routes/auth.ts — Login, register, verify email, profile update, token generation
  • server/routes/inventoryTypes.ts — CRUD with schema validation, item dependency check before delete
  • server/routes/categories.ts — CRUD with type filtering, reorder by sortOrder
  • server/routes/stockHistory.ts — Filtered history queries, pagination
  • server/routes/costHistory.ts — Cost stats with trend analysis (up/down/stable)
  • server/routes/boms.ts — BOM CRUD with item arrays and cost calculations
  • server/routes/templates.ts — Template CRUD with defaultFields JSON
  • server/routes/users.ts — User management, role changes, password stripping

Priority 2: Untested Frontend Services (12 files)

  • src/services/api.ts — Core fetch wrapper, ApiError class, error handling
  • src/services/inventoryTypeService.ts — Type CRUD, schema validation, PRESET_TYPES
  • src/services/categoryService.ts — Category CRUD, filtering by type
  • src/services/bomService.ts — BOM CRUD, cost breakdown calculation
  • src/services/costHistoryService.ts — Cost history retrieval, stats
  • src/services/stockHistoryService.ts — Stock history with date/type filters
  • src/services/itemTemplateService.ts — Template CRUD, apply template
  • src/services/vendorService.ts — Mock vendor price lookup with 15-min cache

Priority 3: Untested Utilities & Contexts

  • src/utils/formatters.ts — formatCurrency, formatDate, formatDateTime, formatBytes, percentageChange
  • src/utils/imageOptimizer.ts — Image compression with configurable quality/dimensions
  • src/contexts/AuthContext.tsx — Auth state, login/logout/register flows, role management

Priority 4: Key Component Tests (highest-value 15 of 50 untested)

  • src/components/items/ItemList.tsx — Sorting, filtering, pagination, bulk actions, low stock
  • src/components/items/ItemDetail.tsx — Detail display, parent/child, vendor prices, delete
  • src/components/items/ItemForm.tsx — Create/edit form, custom fields, parent selection, validation
  • src/components/items/CustomFieldRenderer.tsx — Schema-driven field rendering (text/number/select/date/boolean)
  • src/components/items/ParentItemSelector.tsx — Parent dropdown, circular reference prevention
  • src/components/items/ChildItemsList.tsx — Child items table, type badges
  • src/components/items/ItemFilters.tsx — Search, category, type filter controls
  • src/components/items/BulkActions.tsx — Bulk delete/category change actions
  • src/components/common/LowStockAlert.tsx — Alert with type-filtered stock counts
  • src/components/common/EmptyState.tsx — Empty state rendering
  • src/components/reports/Dashboard.tsx — Stats cards, charts, recent activity
  • src/components/settings/InventoryTypeManager.tsx — Type CRUD, export buttons
  • src/components/settings/CategoryManager.tsx — Category CRUD, drag reorder
  • src/components/bom/BOMList.tsx — BOM table, cost breakdown
  • src/components/auth/Login.tsx — Login form, error handling

Acceptance Criteria

  • Server route tests for all 9 route files (supertest or direct handler testing)
  • Frontend service tests for remaining 12 untested services
  • Unit tests for formatters.ts and imageOptimizer.ts
  • AuthContext tests for login/logout/register flows
  • Component tests for at least the 15 highest-value components listed above
  • All new tests pass alongside existing 96 tests
  • No regressions in TypeScript compilation

Additional Context

This should be broken into multiple PRs by priority tier to keep reviews manageable. Each PR should target one tier or a logical subset of files.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions