turash/bugulma/backend/internal/domain/domain_test.go
Damir Mukimov 000eab4740
Major repository reorganization and missing backend endpoints implementation
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools

Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
  * GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
  * GET /api/v1/users/me/organizations - User organizations
  * POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue

API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules

Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
2025-11-25 06:01:16 +01:00

84 lines
2.3 KiB
Go

package domain
import (
"testing"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func TestOrganization_TableName(t *testing.T) {
org := Organization{}
assert.Equal(t, "organizations", org.TableName())
}
func TestSite_TableName(t *testing.T) {
site := Site{}
assert.Equal(t, "sites", site.TableName())
}
func TestResourceFlow_TableName(t *testing.T) {
rf := ResourceFlow{}
assert.Equal(t, "resource_flows", rf.TableName())
}
func TestResourceFlowVersion_TableName(t *testing.T) {
rfv := ResourceFlowVersion{}
assert.Equal(t, "resource_flow_versions", rfv.TableName())
}
func TestSharedAsset_TableName(t *testing.T) {
sa := SharedAsset{}
assert.Equal(t, "shared_assets", sa.TableName())
}
func TestMatch_TableName(t *testing.T) {
match := Match{}
assert.Equal(t, "matches", match.TableName())
}
func TestUser_TableName(t *testing.T) {
user := User{}
assert.Equal(t, "users", user.TableName())
}
func TestSiteOperatingBusiness_TableName(t *testing.T) {
sob := SiteOperatingBusiness{}
assert.Equal(t, "site_operating_businesses", sob.TableName())
}
func TestMatch_BeforeUpdate(t *testing.T) {
match := &Match{Version: 1}
db, _ := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
err := match.BeforeUpdate(db)
assert.NoError(t, err)
assert.Equal(t, 2, match.Version)
}
func TestSite_AfterCreate(t *testing.T) {
// Test with PostgreSQL-like conditions
site := &Site{ID: "test-1", Latitude: 55.7558, Longitude: 37.6173}
db, _ := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
// Note: AfterCreate uses raw SQL to update geometry column
// This test verifies the hook doesn't crash on SQLite
err := site.AfterCreate(db)
assert.NoError(t, err)
// Note: location_geometry column is managed separately via PostGIS migrations
// and is not part of the GORM model struct
}
func TestSite_AfterUpdate(t *testing.T) {
site := &Site{ID: "test-1", Latitude: 55.7558, Longitude: 37.6173}
db, _ := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
// Note: AfterUpdate uses raw SQL to update geometry column
// This test verifies the hook doesn't crash on SQLite
err := site.AfterUpdate(db)
assert.NoError(t, err)
// Note: location_geometry column is managed separately via PostGIS migrations
// and is not part of the GORM model struct
}