Skip to content

test suite and admin interface enhancements#82

Merged
cybervoid0 merged 5 commits intomasterfrom
security-upgrades
Apr 10, 2026
Merged

test suite and admin interface enhancements#82
cybervoid0 merged 5 commits intomasterfrom
security-upgrades

Conversation

@cybervoid0
Copy link
Copy Markdown
Owner

Summary

Comprehensive test suite and admin interface enhancements for reference data management:

  • Materials & Movement Types Management: New dedicated admin pages (/admin/materials/ and /admin/movements/) with full CRUD operations (create, read, update, delete)
  • Server Actions: Complete server-side implementations with Zod validation and error handling for both materials and movement types
  • Test Coverage: Added comprehensive unit tests for server actions (materials, movements, auth, barometers, brands, documents, files, reports, registration) with 38+ test cases covering success paths, error handling, and edge cases
  • Testing Infrastructure: Mock module system for consistent test setup across the codebase
  • UI/UX: Reusable reference data components with form validation, edit dialogs, and delete confirmations following project patterns

Changes

Server Layer

  • server/materials/ - Actions, schemas, and tests for material CRUD
  • server/movements/ - Actions, schemas, and tests for movement type CRUD
  • Both implement proper error handling (P2002 for uniqueness, P2003 for foreign key constraints)
  • Cache tag management (Tag.materials, Tag.movements, Tag.barometers) for data consistency

Admin UI

  • app/(pages)/admin/_components/ - Shared components (ReferenceDataList, EditDialog, DeleteAlert)
  • app/(pages)/admin/materials/ and app/(pages)/admin/movements/ - Dedicated management pages
  • Form validation with react-hook-form + zodResolver
  • Disabled form submission until valid
  • Optimistic UI updates with router.refresh()

Testing

  • Created server/testing/mocks.ts with comprehensive mock module setup
  • Added 38+ unit tests across all server actions
  • Tests cover authorization, validation, success/error paths, and constraint handling

Routes

  • Added /admin/materials/ and /admin/movements/ routes
  • Updated admin dashboard with links to new pages

Test plan

  • Test adding new material/movement type via admin form
  • Test updating existing material/movement type
  • Test deleting material/movement type (with confirmation)
  • Test form validation (empty name, long description)
  • Test that barometer collection pages reflect new materials/movements immediately
  • Test error messages for duplicate names and foreign key violations
  • Verify all 38 unit tests pass: npm test -- server/

- Added middleware for protected routes using NextAuth.
- Introduced session management functions to enforce admin access.
- Refactored admin layout to utilize session data for redirection.
- Created reusable logout button component for user session management.
- Updated various server actions to require admin privileges and validate input data using Zod schemas.
- Enhanced security headers in the Next.js configuration for improved application security.
- Updated the estimatedPrice field in UpdateBarometerSchema to require positive values, enhancing data integrity and validation. This change ensures that only valid price entries are accepted.
…er, brand, document, and file actions

- Introduced unit tests for authentication actions, ensuring proper session handling and role validation.
- Added tests for barometer actions, covering create, update, and delete functionalities with validation checks.
- Implemented tests for brand actions, validating creation, updating, and deletion processes.
- Created tests for document actions, ensuring correct handling of document creation, updates, and deletions.
- Developed tests for file actions, including file saving, deletion, and temporary file creation, with admin access checks.
- Enhanced overall test coverage and reliability across various server modules.
…ments

- Introduced a new Reference Data page in the admin section for managing materials and movement types.
- Implemented the ReferenceDataList component to handle creation and deletion of materials and movements.
- Added server actions for creating and deleting materials and movements with appropriate validation.
- Updated routing to include the new Reference Data page.
- Enhanced the admin page with a link to manage materials and movements.
…agement

- Updated the admin page to include links for managing materials and movement types.
- Introduced new components for handling deletion and editing of reference data.
- Created dedicated pages for managing materials and movements, utilizing the ReferenceDataList component.
- Implemented server actions for creating, updating, and deleting materials and movements with validation.
- Removed the old reference data page to streamline the admin interface.
@cybervoid0 cybervoid0 self-assigned this Apr 10, 2026
@cybervoid0 cybervoid0 merged commit 1004182 into master Apr 10, 2026
1 check failed
@cybervoid0 cybervoid0 deleted the security-upgrades branch April 10, 2026 20:43
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.

1 participant