feat(features): 功能开放 - 增加自定义渠道开关
This commit is contained in:
1 parent
b2a7eef35d
commit
f83ff03df3
16 files changed
+154
-30
No files matched your search
@@ -18,7 +18,23 @@ func TestFeatureAvailabilityDefaultsToEnabled(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if setting.Configured || !setting.ShortDramaEnabled || !setting.TaskCenterEnabled || !setting.CreditsEnabled {
|
||||
if setting.Configured || !setting.ShortDramaEnabled || !setting.TaskCenterEnabled || !setting.CreditsEnabled || !setting.CustomChannelsEnabled {
|
||||
t.Fatalf("FeatureAvailability() = %#v", setting)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeatureAvailabilityLegacySettingKeepsCustomChannelsEnabled(t *testing.T) {
|
||||
svc, db := newFeatureAvailabilityTestService(t)
|
||||
legacy := &model.SystemSetting{Key: featureAvailabilitySettingKey, ValueJSON: `{"shortDramaEnabled":false,"taskCenterEnabled":true,"creditsEnabled":true}`}
|
||||
if err := db.Create(legacy).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
setting, err := svc.FeatureAvailability()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if setting.ShortDramaEnabled || !setting.CustomChannelsEnabled {
|
||||
t.Fatalf("FeatureAvailability() = %#v", setting)
|
||||
}
|
||||
}
|
||||
@@ -26,13 +42,13 @@ func TestFeatureAvailabilityDefaultsToEnabled(t *testing.T) {
|
||||
func TestUpdateFeatureAvailabilityPersistsAndAudits(t *testing.T) {
|
||||
svc, db := newFeatureAvailabilityTestService(t)
|
||||
actor := &model.User{ID: "admin-1", Role: model.UserRoleAdmin}
|
||||
want := FeatureAvailability{ShortDramaEnabled: false, TaskCenterEnabled: true, CreditsEnabled: false}
|
||||
want := FeatureAvailability{ShortDramaEnabled: false, TaskCenterEnabled: true, CreditsEnabled: false, CustomChannelsEnabled: true}
|
||||
|
||||
setting, err := svc.UpdateFeatureAvailability(actor, want)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !setting.Configured || setting.ShortDramaEnabled || !setting.TaskCenterEnabled || setting.CreditsEnabled {
|
||||
if !setting.Configured || setting.ShortDramaEnabled || !setting.TaskCenterEnabled || setting.CreditsEnabled || !setting.CustomChannelsEnabled {
|
||||
t.Fatalf("UpdateFeatureAvailability() = %#v", setting)
|
||||
}
|
||||
if err := svc.RequireFeature(FeatureShortDrama); err == nil {
|
||||
@@ -52,10 +68,33 @@ func TestUpdateFeatureAvailabilityPersistsAndAudits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCustomChannelTaskInputRequiresFeature(t *testing.T) {
|
||||
svc, _ := newFeatureAvailabilityTestService(t)
|
||||
actor := &model.User{ID: "admin-1", Role: model.UserRoleAdmin}
|
||||
if _, err := svc.UpdateFeatureAvailability(actor, FeatureAvailability{ShortDramaEnabled: true, TaskCenterEnabled: true, CreditsEnabled: true, CustomChannelsEnabled: false}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
customInput, err := normalizeTaskInput(map[string]any{"config": providerConfig{BaseURL: "https://example.com", APIKey: "private-key", Model: "text-model"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := svc.requireCustomChannelsForTaskInput(customInput); err == nil {
|
||||
t.Fatal("custom channel task must be rejected when the feature is disabled")
|
||||
}
|
||||
systemInput, err := normalizeTaskInput(map[string]any{"config": providerConfig{ChannelID: "system-1", BaseURL: "/api/ai/system/system-1", APIKey: "system", Model: "text-model"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := svc.requireCustomChannelsForTaskInput(systemInput); err != nil {
|
||||
t.Fatalf("system channel task error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskBillingOrderSkipsPricingWhenCreditsDisabled(t *testing.T) {
|
||||
svc, _ := newFeatureAvailabilityTestService(t)
|
||||
actor := &model.User{ID: "admin-1", Role: model.UserRoleAdmin}
|
||||
if _, err := svc.UpdateFeatureAvailability(actor, FeatureAvailability{ShortDramaEnabled: true, TaskCenterEnabled: true, CreditsEnabled: false}); err != nil {
|
||||
if _, err := svc.UpdateFeatureAvailability(actor, FeatureAvailability{ShortDramaEnabled: true, TaskCenterEnabled: true, CreditsEnabled: false, CustomChannelsEnabled: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user