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 }