Files
MeBox/internal/service/media_library_roots_test.go
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* Rebrand MMTL to MeBox across codebase and assets

Rename the project display name, Go module path, environment variable
prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl
to MeBox/mebox. Replace logo assets with the new MeBox icon and keep
legacy SQLite migration support for existing mmtl.db deployments.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* Fix logo icons: use cube-only crop without truncated text

Previous icon generation cropped too much of the source image, including
partial MeBox wordmark text that was cut off in square icon containers.
Regenerate logo-64/192/512, favicon, and SVG from cube-only region.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
2026-09-02 16:26:28 +08:00

101 lines
3.2 KiB
Go

package service
import (
"path/filepath"
"testing"
"go.uber.org/zap"
"github.com/truewhile/MeBox/internal/config"
"github.com/truewhile/MeBox/internal/model"
"github.com/truewhile/MeBox/internal/repository"
)
func TestCreateLibraryWithRootsAppendsToExistingLogicalLibrary(t *testing.T) {
rootA := t.TempDir()
rootB := t.TempDir()
db := newServiceTestDB(t, &model.Library{}, &model.LibraryRoot{}, &model.Media{})
repos := repository.New(db)
svc := NewMediaService(&config.Config{}, zap.NewNop(), repos)
first, err := svc.CreateLibraryWithRoots(t.Context(), "欧美电影", "movie", []LibraryRootInput{
{Name: "硬盘1", Path: rootA},
})
if err != nil {
t.Fatal(err)
}
second, err := svc.CreateLibraryWithRoots(t.Context(), "欧美电影", "movie", []LibraryRootInput{
{Name: "硬盘2", Path: rootB},
})
if err != nil {
t.Fatal(err)
}
if second.ID != first.ID {
t.Fatalf("second library id = %q, want existing %q", second.ID, first.ID)
}
var libraryCount int64
if err := db.Model(&model.Library{}).Count(&libraryCount).Error; err != nil {
t.Fatal(err)
}
if libraryCount != 1 {
t.Fatalf("library count = %d, want one logical library", libraryCount)
}
roots, err := repos.Library.ListRoots(t.Context(), first.ID)
if err != nil {
t.Fatal(err)
}
if len(roots) != 2 {
t.Fatalf("roots = %#v, want 2", roots)
}
if roots[0].Path != filepath.Clean(rootA) || roots[1].Path != filepath.Clean(rootB) {
t.Fatalf("root paths = %#v, want %q then %q", roots, filepath.Clean(rootA), filepath.Clean(rootB))
}
}
func TestCreateLibraryWithRootsStoresAndUpdatesCustomCover(t *testing.T) {
db := newServiceTestDB(t, &model.Library{}, &model.LibraryRoot{}, &model.Media{})
repos := repository.New(db)
svc := NewMediaService(&config.Config{}, zap.NewNop(), repos)
lib, err := svc.CreateLibraryWithRootsAndCover(t.Context(), "收藏", "movie", "https://example.com/cover.jpg", []LibraryRootInput{{Path: t.TempDir()}})
if err != nil {
t.Fatal(err)
}
if lib.CoverURL != "https://example.com/cover.jpg" {
t.Fatalf("cover_url = %q", lib.CoverURL)
}
if err := svc.UpdateLibraryCover(t.Context(), lib.ID, "https://example.com/new.jpg"); err != nil {
t.Fatal(err)
}
updated, err := repos.Library.FindByID(t.Context(), lib.ID)
if err != nil {
t.Fatal(err)
}
if updated.CoverURL != "https://example.com/new.jpg" {
t.Fatalf("updated cover_url = %q", updated.CoverURL)
}
}
func TestCreateLibraryWithRootsKeepsDifferentTypesSeparate(t *testing.T) {
rootMovie := t.TempDir()
rootTV := t.TempDir()
db := newServiceTestDB(t, &model.Library{}, &model.LibraryRoot{}, &model.Media{})
repos := repository.New(db)
svc := NewMediaService(&config.Config{}, zap.NewNop(), repos)
if _, err := svc.CreateLibraryWithRoots(t.Context(), "综合", "movie", []LibraryRootInput{{Path: rootMovie}}); err != nil {
t.Fatal(err)
}
if _, err := svc.CreateLibraryWithRoots(t.Context(), "综合", "tv", []LibraryRootInput{{Path: rootTV}}); err != nil {
t.Fatal(err)
}
var libraryCount int64
if err := db.Model(&model.Library{}).Count(&libraryCount).Error; err != nil {
t.Fatal(err)
}
if libraryCount != 2 {
t.Fatalf("library count = %d, want separate libraries for different types", libraryCount)
}
}