mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
59 lines
2.5 KiB
Go
59 lines
2.5 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/model"
|
|
)
|
|
|
|
func TestSelectSiteSearchCandidatesPrefersSeriesPack(t *testing.T) {
|
|
sub := &model.Subscription{Name: "间谍过家家 自动订阅", Filter: "间谍过家家 2022", MediaType: "tv"}
|
|
results := []SearchResult{
|
|
{Title: "间谍过家家 S01E01 1080p", DownloadURL: "https://pt/download/1", Seeders: 80},
|
|
{Title: "间谍过家家 S01 Complete 1080p", DownloadURL: "https://pt/download/pack", Seeders: 50},
|
|
{Title: "间谍过家家 S01E02 1080p", DownloadURL: "https://pt/download/2", Seeders: 70},
|
|
}
|
|
|
|
got := selectSiteSearchCandidates(results, sub, map[string]struct{}{})
|
|
if len(got) != 1 {
|
|
t.Fatalf("selected %d candidates, want 1", len(got))
|
|
}
|
|
if got[0].Download != "https://pt/download/pack" || !got[0].Pack {
|
|
t.Fatalf("selected %#v, want complete pack", got[0])
|
|
}
|
|
}
|
|
|
|
func TestSelectSiteSearchCandidatesQueuesDistinctEpisodesWhenNoPack(t *testing.T) {
|
|
sub := &model.Subscription{Name: "葬送的芙莉莲 自动订阅", Filter: "葬送的芙莉莲", MediaType: "anime"}
|
|
results := []SearchResult{
|
|
{Title: "葬送的芙莉莲 S01E01 1080p", DownloadURL: "https://pt/download/1a", Seeders: 90},
|
|
{Title: "葬送的芙莉莲 S01E01 2160p", DownloadURL: "https://pt/download/1b", Seeders: 80},
|
|
{Title: "葬送的芙莉莲 S01E02 1080p", DownloadURL: "https://pt/download/2", Seeders: 70},
|
|
{Title: "葬送的芙莉莲 S01E03 1080p", DownloadURL: "https://pt/download/3", Seeders: 60},
|
|
}
|
|
|
|
got := selectSiteSearchCandidates(results, sub, map[string]struct{}{})
|
|
if len(got) != 3 {
|
|
t.Fatalf("selected %d candidates, want 3", len(got))
|
|
}
|
|
if got[0].Episode != 1 || got[1].Episode != 2 || got[2].Episode != 3 {
|
|
t.Fatalf("episodes = %d,%d,%d; want 1,2,3", got[0].Episode, got[1].Episode, got[2].Episode)
|
|
}
|
|
if got[0].Download != "https://pt/download/1a" {
|
|
t.Fatalf("duplicate episode should keep first/best result, got %q", got[0].Download)
|
|
}
|
|
}
|
|
|
|
func TestSelectSiteSearchCandidatesKeepsMovieSingleBest(t *testing.T) {
|
|
sub := &model.Subscription{Name: "Inception 自动订阅", Filter: "Inception 2010", MediaType: "movie"}
|
|
results := []SearchResult{
|
|
{Title: "Inception 2010 1080p", DownloadURL: "https://pt/download/1080", Seeders: 90},
|
|
{Title: "Inception 2010 2160p", DownloadURL: "https://pt/download/2160", Seeders: 80},
|
|
}
|
|
|
|
got := selectSiteSearchCandidates(results, sub, map[string]struct{}{})
|
|
if len(got) != 1 || got[0].Download != "https://pt/download/1080" {
|
|
t.Fatalf("selected %#v, want movie best only", got)
|
|
}
|
|
}
|