Files
MeBox/internal/service/emby_compat_test.go
T
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

68 lines
2.1 KiB
Go

package service
import (
"testing"
"time"
"go.uber.org/zap"
"github.com/truewhile/MeBox/internal/config"
"github.com/truewhile/MeBox/internal/model"
"github.com/truewhile/MeBox/internal/repository"
)
func newTestEmbyService(t *testing.T) *EmbyService {
t.Helper()
db := newServiceTestDB(t, &model.Library{}, &model.Series{}, &model.Media{}, &model.Favorite{}, &model.PlaybackHistory{}, &model.User{}, &model.Setting{})
// 内存库 + 异步探测协程:限制为单连接,避免连接池新建连接时
// 拿到一个空白的 :memory: 实例(no such table)。
if sqlDB, err := db.DB(); err == nil {
sqlDB.SetMaxOpenConns(1)
}
repos := repository.New(db)
return NewEmbyService(&config.Config{}, zap.NewNop(), repos)
}
func TestEmbyLatestItemsOrderByReleaseDate(t *testing.T) {
svc := newTestEmbyService(t)
lib := model.Library{Name: "电影", Path: `/media/movies`, Type: "movie", Enabled: true}
if err := svc.repo.Library.Create(t.Context(), &lib); err != nil {
t.Fatalf("create library: %v", err)
}
base := time.Now()
rows := []model.Media{
{
Base: model.Base{ID: "older-release-newer-scan", CreatedAt: base.Add(2 * time.Hour)},
LibraryID: lib.ID,
Title: "旧上映新入库",
Path: `/media/movies/old.mkv`,
Year: 2026,
ReleaseDate: "2026-01-10",
},
{
Base: model.Base{ID: "newer-release-older-scan", CreatedAt: base},
LibraryID: lib.ID,
Title: "新上映",
Path: `/media/movies/new.mkv`,
Year: 2026,
ReleaseDate: "2026-06-23",
},
}
for i := range rows {
if err := svc.repo.DB.Create(&rows[i]).Error; err != nil {
t.Fatalf("create media: %v", err)
}
}
items, err := svc.LatestItems(t.Context(), "", lib.ID, 10)
if err != nil {
t.Fatalf("latest items: %v", err)
}
if len(items) != 2 || items[0]["Id"] != "newer-release-older-scan" {
t.Fatalf("latest items should prefer release date over created_at, got %#v", items)
}
if _, ok := items[0]["PremiereDate"].(time.Time); !ok {
t.Fatalf("latest item should expose PremiereDate for Emby clients: %#v", items[0])
}
}