Add Database Integration Tests for All Models #2

Open
opened 2025-07-01 14:48:45 +12:00 by guisea · 0 comments
Owner

Overview

While unit tests use mocked datastores, we need integration tests that verify actual database operations, constraints, and migrations work correctly.

Current State

  • Unit tests with mocked database operations
  • Attachment model has database integration tests (reference implementation)
  • No database integration tests for other models
  • No migration testing
  • No database constraint validation

Required Database Integration Tests

Core Models

  • Accounts: CRUD operations, parent-child relationships, currency constraints
  • Transactions: Creation with splits, balance calculations, date filtering
  • Organizations: Creation, user associations, permissions
  • Users: Registration, authentication, organization membership
  • Splits: Transaction relationships, amount validations
  • Balances: Calculation accuracy, date-based queries

Database Features

  • Migrations: Test all migration scripts work correctly
  • Foreign Keys: Verify constraint enforcement
  • Indexes: Verify performance indexes exist and work
  • Binary UUID: Test UUID storage and retrieval
  • Soft Deletion: Verify deleted records are properly handled

Implementation Notes

  • Use core/api/attachment_integration_test.go database setup pattern
  • Test with both SQLite (for CI) and MySQL (for production scenarios)
  • Include data validation and constraint testing
  • Test edge cases like circular references, invalid foreign keys
  • Verify GORM model definitions match actual database schema

Acceptance Criteria

  • All models have database integration tests
  • Migration testing is automated
  • Tests verify foreign key constraints
  • Tests work with both SQLite and MySQL
  • Performance queries are tested with realistic data volumes
## Overview While unit tests use mocked datastores, we need integration tests that verify actual database operations, constraints, and migrations work correctly. ## Current State - ✅ Unit tests with mocked database operations - ✅ Attachment model has database integration tests (reference implementation) - ❌ No database integration tests for other models - ❌ No migration testing - ❌ No database constraint validation ## Required Database Integration Tests ### Core Models - [ ] **Accounts**: CRUD operations, parent-child relationships, currency constraints - [ ] **Transactions**: Creation with splits, balance calculations, date filtering - [ ] **Organizations**: Creation, user associations, permissions - [ ] **Users**: Registration, authentication, organization membership - [ ] **Splits**: Transaction relationships, amount validations - [ ] **Balances**: Calculation accuracy, date-based queries ### Database Features - [ ] **Migrations**: Test all migration scripts work correctly - [ ] **Foreign Keys**: Verify constraint enforcement - [ ] **Indexes**: Verify performance indexes exist and work - [ ] **Binary UUID**: Test UUID storage and retrieval - [ ] **Soft Deletion**: Verify deleted records are properly handled ## Implementation Notes - Use `core/api/attachment_integration_test.go` database setup pattern - Test with both SQLite (for CI) and MySQL (for production scenarios) - Include data validation and constraint testing - Test edge cases like circular references, invalid foreign keys - Verify GORM model definitions match actual database schema ## Acceptance Criteria - [ ] All models have database integration tests - [ ] Migration testing is automated - [ ] Tests verify foreign key constraints - [ ] Tests work with both SQLite and MySQL - [ ] Performance queries are tested with realistic data volumes
guisea added the enhancement label 2025-07-01 14:48:54 +12:00
guisea self-assigned this 2025-07-01 14:49:00 +12:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: guisea/openaccounting-server#2