mirror of
https://github.com/navidrome/navidrome.git
synced 2026-06-19 07:37:15 +00:00
e6680c904b
* fix(playlists): allow toggling auto-import (sync) via REST API The updatePlaylistEntity handler was not applying the sync field from incoming requests, causing the auto-import toggle in the UI to have no effect. Apply the sync value for file-backed playlists only. * fix(playlists): enhance update logic for playlist metadata and sync toggle Signed-off-by: Deluan <deluan@navidrome.org> * fix(playlists): address code review feedback - Add pointer equality short-circuit in rulesEqual before reflect.DeepEqual - Guard against empty ID in Put's partial-update path - Only apply Sync when it actually differs from current value, preventing zero-value overwrites from partial payloads * fix(playlists): remove unused parameters from Update method Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
112 lines
2.3 KiB
Go
112 lines
2.3 KiB
Go
package tests
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/deluan/rest"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/id"
|
|
)
|
|
|
|
func CreateMockPlaylistRepo() *MockPlaylistRepo {
|
|
return &MockPlaylistRepo{
|
|
Data: make(map[string]*model.Playlist),
|
|
PathMap: make(map[string]*model.Playlist),
|
|
}
|
|
}
|
|
|
|
type MockPlaylistRepo struct {
|
|
model.PlaylistRepository
|
|
Data map[string]*model.Playlist // keyed by ID
|
|
PathMap map[string]*model.Playlist // keyed by path
|
|
Last *model.Playlist
|
|
Deleted []string
|
|
Err bool
|
|
TracksRepo model.PlaylistTrackRepository
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) SetError(err bool) {
|
|
m.Err = err
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) Get(id string) (*model.Playlist, error) {
|
|
if m.Err {
|
|
return nil, errors.New("error")
|
|
}
|
|
if m.Data != nil {
|
|
if pls, ok := m.Data[id]; ok {
|
|
return pls, nil
|
|
}
|
|
}
|
|
return nil, model.ErrNotFound
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) GetWithTracks(id string, _, _ bool) (*model.Playlist, error) {
|
|
return m.Get(id)
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) Put(pls *model.Playlist, _ ...string) error {
|
|
if m.Err {
|
|
return errors.New("error")
|
|
}
|
|
if pls.ID == "" {
|
|
pls.ID = id.NewRandom()
|
|
}
|
|
m.Last = pls
|
|
if m.Data != nil {
|
|
m.Data[pls.ID] = pls
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) FindByPath(path string) (*model.Playlist, error) {
|
|
if m.Err {
|
|
return nil, errors.New("error")
|
|
}
|
|
if m.PathMap != nil {
|
|
if pls, ok := m.PathMap[path]; ok {
|
|
return pls, nil
|
|
}
|
|
}
|
|
return nil, model.ErrNotFound
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) Delete(id string) error {
|
|
if m.Err {
|
|
return errors.New("error")
|
|
}
|
|
m.Deleted = append(m.Deleted, id)
|
|
return nil
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) Tracks(_ string, _ bool) model.PlaylistTrackRepository {
|
|
return m.TracksRepo
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) Exists(id string) (bool, error) {
|
|
if m.Err {
|
|
return false, errors.New("error")
|
|
}
|
|
if m.Data != nil {
|
|
_, found := m.Data[id]
|
|
return found, nil
|
|
}
|
|
return false, nil
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) Count(_ ...rest.QueryOptions) (int64, error) {
|
|
if m.Err {
|
|
return 0, errors.New("error")
|
|
}
|
|
return int64(len(m.Data)), nil
|
|
}
|
|
|
|
func (m *MockPlaylistRepo) CountAll(_ ...model.QueryOptions) (int64, error) {
|
|
if m.Err {
|
|
return 0, errors.New("error")
|
|
}
|
|
return int64(len(m.Data)), nil
|
|
}
|
|
|
|
var _ model.PlaylistRepository = (*MockPlaylistRepo)(nil)
|