Files
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

94 lines
2.7 KiB
Go

package service
import (
"context"
"testing"
"time"
"github.com/truewhile/MeBox/internal/model"
"github.com/truewhile/MeBox/internal/repository"
"go.uber.org/zap"
)
func TestRecordProgressPreservesDurationWhenMissing(t *testing.T) {
db := newServiceTestDB(t, &model.PlaybackHistory{}, &model.Media{})
repos := repository.New(db)
userID := "user-1"
mediaID := "local-movie-1"
if err := db.Create(&model.PlaybackHistory{
Base: model.Base{ID: "hist-1"},
UserID: userID,
MediaID: mediaID,
PositionMs: 30_000,
DurationMs: 120_000,
WatchedAt: time.Now(),
}).Error; err != nil {
t.Fatalf("seed history: %v", err)
}
svc := NewPlaybackService(zap.NewNop(), repos)
if err := svc.RecordProgress(context.Background(), userID, mediaID, 60_000, 0); err != nil {
t.Fatalf("RecordProgress: %v", err)
}
var hist model.PlaybackHistory
if err := db.Where("user_id = ? AND media_id = ?", userID, mediaID).First(&hist).Error; err != nil {
t.Fatalf("find history: %v", err)
}
if hist.DurationMs != 120_000 {
t.Fatalf("expected duration preserved, got %d", hist.DurationMs)
}
if hist.PositionMs != 60_000 {
t.Fatalf("expected position updated, got %d", hist.PositionMs)
}
}
func TestGetProgressReturnsNilWhenMissing(t *testing.T) {
db := newServiceTestDB(t, &model.PlaybackHistory{})
repos := repository.New(db)
svc := NewPlaybackService(zap.NewNop(), repos)
row, err := svc.GetProgress(context.Background(), "user-1", "missing-media")
if err != nil {
t.Fatalf("GetProgress: %v", err)
}
if row != nil {
t.Fatalf("expected nil progress, got %#v", row)
}
}
func TestListFavouritesIncludesLocalAndRemoteIDs(t *testing.T) {
db := newServiceTestDB(t, &model.Favorite{}, &model.Media{})
repos := repository.New(db)
userID := "user-1"
local := model.Media{
Base: model.Base{ID: "local-movie-1"},
Title: "Local Movie",
}
if err := db.Create(&local).Error; err != nil {
t.Fatalf("create local media: %v", err)
}
remoteID := EncodeEmbyRemoteID("mount-1", "remote-series-1")
favs := []model.Favorite{
{Base: model.Base{CreatedAt: time.Now().Add(-time.Minute)}, UserID: userID, MediaID: remoteID},
{Base: model.Base{CreatedAt: time.Now()}, UserID: userID, MediaID: local.ID},
}
for i := range favs {
if err := db.Create(&favs[i]).Error; err != nil {
t.Fatalf("create favorite %d: %v", i, err)
}
}
svc := NewPlaybackService(zap.NewNop(), repos)
items, err := svc.ListFavourites(context.Background(), userID)
if err != nil {
t.Fatalf("ListFavourites: %v", err)
}
if len(items) != 1 {
t.Fatalf("expected one hydrated local favourite without remote service, got %d: %#v", len(items), items)
}
if items[0].ID != local.ID {
t.Fatalf("expected local favourite first by created_at desc, got %#v", items[0])
}
}