thread-master/backend/internal/model/threads_account/usecase/connection_prefs_test.go

49 lines
1.2 KiB
Go
Raw Permalink Normal View History

2026-06-27 14:49:17 +00:00
package usecase
import (
"testing"
domusecase "haixun-backend/internal/model/threads_account/domain/usecase"
)
func TestApplyConnectionPatchSearchSourceInFormalMode(t *testing.T) {
current := formalConnectionPrefs()
2026-06-27 14:49:17 +00:00
patch := domusecase.ConnectionPrefsPatch{
SearchSourceMode: strPtr("threads_crawler"),
2026-06-27 14:49:17 +00:00
}
next := applyConnectionPatch(current, patch)
if next.SearchSourceMode != "threads_brave" {
t.Fatalf("expected crawler mode stripped to threads_brave, got %s", next.SearchSourceMode)
2026-06-27 14:49:17 +00:00
}
if next.DevMode {
t.Fatal("expected dev_mode to stay disabled")
2026-06-27 14:49:17 +00:00
}
}
func TestNormalizeConnectionPrefsKeepsScrapeReplies(t *testing.T) {
prefs := formalConnectionPrefs()
prefs.ScrapeReplies = true
next := normalizeConnectionPrefs(prefs)
if !next.ScrapeReplies {
t.Fatal("expected scrape_replies to persist")
2026-06-27 14:49:17 +00:00
}
if next.PublishViaApi != true || !next.SearchViaApi {
t.Fatal("expected formal API routing")
2026-06-27 14:49:17 +00:00
}
}
func TestApplyConnectionPatchIgnoresLegacyDevMode(t *testing.T) {
current := formalConnectionPrefs()
enabled := true
next := applyConnectionPatch(current, domusecase.ConnectionPrefsPatch{
DevMode: &enabled,
})
if next.DevMode {
t.Fatal("account dev_mode should not enable crawler routing")
2026-06-27 14:49:17 +00:00
}
}
func strPtr(v string) *string {
return &v
2026-06-27 16:03:28 +00:00
}