mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-09 06:46:37 +08:00
fix media organize and subscription workflows
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/ShukeBta/MediaStationGo/internal/model"
|
||||
)
|
||||
|
||||
func TestOrganizeScanRootUsesActualOrganizedTarget(t *testing.T) {
|
||||
@@ -85,3 +87,44 @@ func TestOrganizePipelineFailsWhenEveryOrganizeItemErrors(t *testing.T) {
|
||||
t.Fatalf("task details = %#v, want transfer error detail", task.Details)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizePipelinePrefersCurrentMediaLibraryAfterMediaOrganize(t *testing.T) {
|
||||
repos := newOrganizerTestRepo(t)
|
||||
sourceLib := model.Library{Name: "待整理", Path: filepath.Join(t.TempDir(), "incoming"), Type: "tv", Enabled: true}
|
||||
targetLib := model.Library{Name: "国产剧", Path: filepath.Join(t.TempDir(), "media", "电视剧", "国产剧"), Type: "tv", Enabled: true}
|
||||
if err := repos.Library.Create(t.Context(), &sourceLib); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := repos.Library.Create(t.Context(), &targetLib); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
media := model.Media{
|
||||
LibraryID: targetLib.ID,
|
||||
Title: "南部档案",
|
||||
Path: filepath.Join(targetLib.Path, "南部档案", "Season 01", "南部档案 - S01E01.mkv"),
|
||||
SeasonNum: 1,
|
||||
EpisodeNum: 1,
|
||||
ScrapeStatus: "matched",
|
||||
}
|
||||
if err := repos.Media.Upsert(t.Context(), &media); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pipeline := NewOrganizePipelineService(zap.NewNop(), repos, nil, nil, nil)
|
||||
got := pipeline.scanPreferredLibraryID(t.Context(), OrganizePipelineRequest{
|
||||
Scope: OrganizeScopeMedia,
|
||||
MediaID: media.ID,
|
||||
})
|
||||
if got != targetLib.ID {
|
||||
t.Fatalf("preferred library = %q, want current media library %q", got, targetLib.ID)
|
||||
}
|
||||
|
||||
got = pipeline.scanPreferredLibraryID(t.Context(), OrganizePipelineRequest{
|
||||
Scope: OrganizeScopeMedia,
|
||||
MediaID: media.ID,
|
||||
PreferredLibraryID: sourceLib.ID,
|
||||
})
|
||||
if got != sourceLib.ID {
|
||||
t.Fatalf("explicit preferred library = %q, want %q", got, sourceLib.ID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user