feat(publish): 德穆兰选项支持后台开关并默认打开下赛季通行证

This commit is contained in:
yml2213
2026-10-31 18:26:05 +08:00
parent ecdffb3f2b
commit 9c379b7e0c
9 changed files with 86 additions and 5 deletions
@@ -106,6 +106,53 @@ func TestNormalizePublishOptionsValuePreservesCurrentSchema(t *testing.T) {
}
}
func TestNormalizePublishOptionsValueMigratesSchemaV1Switches(t *testing.T) {
legacy := `{"schema_version":1,"next_season_pass_enabled":false,"server_options":["QQ"]}`
normalized, err := normalizePublishOptionsValue(legacy)
if err != nil {
t.Fatalf("规范化失败: %v", err)
}
var got PublishOptionsDTO
if err := json.Unmarshal([]byte(normalized), &got); err != nil {
t.Fatalf("解析规范化结果失败: %v", err)
}
if got.SchemaVersion != publishOptionsSchemaVersion {
t.Fatalf("schema_version = %d, want %d", got.SchemaVersion, publishOptionsSchemaVersion)
}
if got.UnlockDemulanEnabled {
t.Fatal("v1 升级后「是否解锁德穆兰」应默认关闭")
}
if !got.NextSeasonPassEnabled {
t.Fatal("v1 升级后「下赛季是否购买通行证」应默认打开")
}
}
func TestNormalizePublishOptionsValueKeepsSchemaV2Switches(t *testing.T) {
options := DefaultPublishOptions()
options.UnlockDemulanEnabled = true
options.NextSeasonPassEnabled = false
raw, err := json.Marshal(options)
if err != nil {
t.Fatalf("构造配置失败: %v", err)
}
normalized, err := normalizePublishOptionsValue(string(raw))
if err != nil {
t.Fatalf("规范化失败: %v", err)
}
var got PublishOptionsDTO
if err := json.Unmarshal([]byte(normalized), &got); err != nil {
t.Fatalf("解析规范化结果失败: %v", err)
}
if !got.UnlockDemulanEnabled {
t.Fatal("v2 配置中后台手动开启的德穆兰开关不应被覆盖")
}
if got.NextSeasonPassEnabled {
t.Fatal("v2 配置中后台手动关闭的通行证开关不应被覆盖")
}
}
func TestNormalizePublishOptionsValueRepairsMojibake(t *testing.T) {
options := DefaultPublishOptions()
raw, err := json.Marshal(options)