mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
* feat(cmd): make artwork explain/refresh accept an id without its kind The kind can now come from the id itself: a full artwork id (al-<id>) carries it in the prefix, and a bare id is resolved across tables via GetEntityByID. The explicit <kind> <id> leader still works. * fix(cmd): keep refreshing resolvable ids when others fail to resolve resolveArtworkTargets now collects a self-describing id it cannot resolve as a failure instead of aborting, so refresh reports and skips the bad ones and still queues the rest, matching refreshItems per-item behavior. explain stays strict and rejects any unresolved input.
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package model_test
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/tests"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("GetEntityByID", func() {
|
|
var ds *tests.MockDataStore
|
|
var ctx context.Context
|
|
|
|
BeforeEach(func() {
|
|
ds = &tests.MockDataStore{}
|
|
ctx = GinkgoT().Context()
|
|
})
|
|
|
|
It("returns the entity matching the id", func() {
|
|
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: "a1", Name: "One"}})
|
|
entity, err := model.GetEntityByID(ctx, ds, "a1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(entity).To(BeAssignableToTypeOf(&model.Album{}))
|
|
Expect(entity.(*model.Album).ID).To(Equal("a1"))
|
|
})
|
|
|
|
It("returns ErrNotFound when no entity matches", func() {
|
|
_, err := model.GetEntityByID(ctx, ds, "missing")
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
})
|
|
|
|
It("propagates unexpected repository errors instead of reporting not-found", func() {
|
|
ds.Album(ctx).(*tests.MockAlbumRepo).SetError(true)
|
|
_, err := model.GetEntityByID(ctx, ds, "a1")
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err).ToNot(MatchError(model.ErrNotFound))
|
|
})
|
|
})
|
|
|
|
var _ = Describe("GetEntityKindByID", func() {
|
|
var ds *tests.MockDataStore
|
|
var ctx context.Context
|
|
|
|
BeforeEach(func() {
|
|
ds = &tests.MockDataStore{}
|
|
ctx = GinkgoT().Context()
|
|
})
|
|
|
|
It("returns the artwork kind for the matching id", func() {
|
|
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: "a1"}})
|
|
kind, err := model.GetEntityKindByID(ctx, ds, "a1")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(kind).To(Equal(model.KindAlbumArtwork))
|
|
})
|
|
|
|
It("returns ErrNotFound when no entity matches", func() {
|
|
_, err := model.GetEntityKindByID(ctx, ds, "missing")
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
})
|
|
})
|