mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-07 22:06:38 +08:00
Update deployment docs and media library UI
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/ShukeBta/MediaStationGo/internal/config"
|
||||
"github.com/ShukeBta/MediaStationGo/internal/model"
|
||||
"github.com/ShukeBta/MediaStationGo/internal/repository"
|
||||
)
|
||||
|
||||
func TestAIStatusUsesDatabaseOpenAIConfig(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.APIConfig{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
repo := &repository.Container{DB: db}
|
||||
crypto := NewCryptoService("test-secret", zap.NewNop())
|
||||
apiConfig := NewAPIConfigService(zap.NewNop(), repo, crypto)
|
||||
key := "sk-test"
|
||||
baseURL := "https://example.test/v1"
|
||||
enabled := true
|
||||
if _, err := apiConfig.Update(context.Background(), "openai", APIConfigPatch{
|
||||
APIKey: &key,
|
||||
BaseURL: &baseURL,
|
||||
Enabled: &enabled,
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ai := NewAIService(&config.Config{
|
||||
AI: config.AIConfig{
|
||||
Enabled: false,
|
||||
Model: "gpt-4o-mini",
|
||||
},
|
||||
}, zap.NewNop(), apiConfig)
|
||||
|
||||
status := ai.Status(context.Background())
|
||||
if !status.Enabled {
|
||||
t.Fatalf("AI status disabled, want enabled from database config")
|
||||
}
|
||||
if status.Provider != "openai" {
|
||||
t.Fatalf("provider = %q, want openai", status.Provider)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAIStatusHonorsDisabledDatabaseOpenAIConfig(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.APIConfig{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
repo := &repository.Container{DB: db}
|
||||
apiConfig := NewAPIConfigService(zap.NewNop(), repo, NewCryptoService("test-secret", zap.NewNop()))
|
||||
key := "sk-test"
|
||||
enabled := false
|
||||
if _, err := apiConfig.Update(context.Background(), "openai", APIConfigPatch{
|
||||
APIKey: &key,
|
||||
Enabled: &enabled,
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ai := NewAIService(&config.Config{
|
||||
AI: config.AIConfig{
|
||||
Enabled: true,
|
||||
APIKey: "sk-file",
|
||||
Model: "gpt-4o-mini",
|
||||
},
|
||||
}, zap.NewNop(), apiConfig)
|
||||
|
||||
if ai.Status(context.Background()).Enabled {
|
||||
t.Fatalf("AI status enabled, want disabled when database config is explicitly disabled")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user