2026-06-27 14:49:17 +00:00
|
|
|
package usecase
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
domusecase "haixun-backend/internal/model/threads_account/domain/usecase"
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-01 08:42:51 +00:00
|
|
|
func TestApplyConnectionPatchSearchSourceInFormalMode(t *testing.T) {
|
|
|
|
|
current := formalConnectionPrefs()
|
2026-06-27 14:49:17 +00:00
|
|
|
patch := domusecase.ConnectionPrefsPatch{
|
2026-07-01 08:42:51 +00:00
|
|
|
SearchSourceMode: strPtr("threads_crawler"),
|
2026-06-27 14:49:17 +00:00
|
|
|
}
|
|
|
|
|
next := applyConnectionPatch(current, patch)
|
2026-07-01 08:42:51 +00:00
|
|
|
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
|
|
|
}
|
2026-07-01 08:42:51 +00:00
|
|
|
if next.DevMode {
|
|
|
|
|
t.Fatal("expected dev_mode to stay disabled")
|
2026-06-27 14:49:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-01 08:42:51 +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
|
|
|
}
|
2026-07-01 08:42:51 +00:00
|
|
|
if next.PublishViaApi != true || !next.SearchViaApi {
|
|
|
|
|
t.Fatal("expected formal API routing")
|
2026-06-27 14:49:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-01 08:42:51 +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-07-01 08:42:51 +00:00
|
|
|
}
|