package services import ( "context" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gorm.io/driver/sqlite" "gorm.io/gorm" "github.com/nutcas3/telecom-platform/apps/api-server/internal/config" "github.com/nutcas3/telecom-platform/apps/api-server/internal/database" ) // newChargingService builds a ChargingService backed by an in-memory SQLite DB. // NOTE: We intentionally do not AutoMigrate models.Subscriber / models.Session because // they embed structs (PLMN, SNSSAI, QoSProfile) without Valuer/Scanner implementations, // which GORM cannot map to SQLite. Tests that exercise those tables are skipped. func newChargingService(t *testing.T) *ChargingService { gormDB, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{}) require.NoError(t, err) db := &database.Database{DB: gormDB} cfg := &config.Config{ ChargingEngine: config.ChargingEngineConfig{ BaseURL: "http://localhost:3001", Timeout: 1 * time.Second, }, } return NewChargingService(db, cfg) } func TestGetHealthStatus(t *testing.T) { service := newChargingService(t) health, err := service.GetHealthStatus(context.Background()) require.NoError(t, err) require.NotNil(t, health) // GetHealthStatus currently returns hardcoded values (no DB access) assert.True(t, health.RedisConnected) assert.True(t, health.ActiveSync) assert.False(t, health.LastSync.IsZero()) assert.Greater(t, health.MemoryUsage, float64(0)) } func TestGetSystemStats(t *testing.T) { t.Skip("GetSystemStats depends on Subscriber/Session models whose embedded structs " + "(PLMN/SNSSAI/QoSProfile) lack Valuer/Scanner and can't be migrated by GORM into SQLite. " + "Covered by integration tests running against Postgres.") } func TestGetUsageStats(t *testing.T) { t.Skip("Requires Subscriber/Session models - see TestGetSystemStats note.") } func TestGetRealTimeUsage(t *testing.T) { t.Skip("Requires Subscriber/Session models - see TestGetSystemStats note.") } func TestListUsageEvents(t *testing.T) { t.Skip("Requires Subscriber/Session models - see TestGetSystemStats note.") } func TestSearchUsageEvents(t *testing.T) { t.Skip("Requires Subscriber/Session models - see TestGetSystemStats note.") } func TestTriggerMaintenance(t *testing.T) { t.Skip("Requires Subscriber/Session models - see TestGetSystemStats note.") }