2026-07-18 16:49:31 -04:00
|
|
|
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() {
|
2026-09-25 18:06:10 -04:00
|
|
|
ds.Album().(*tests.MockAlbumRepo).SetData(model.Albums{{ID: "a1", Name: "One"}})
|
2026-07-18 16:49:31 -04:00
|
|
|
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() {
|
2026-09-25 18:06:10 -04:00
|
|
|
ds.Album().(*tests.MockAlbumRepo).SetError(true)
|
2026-07-18 16:49:31 -04:00
|
|
|
_, err := model.GetEntityByID(ctx, ds, "a1")
|
|
|
|
|
Expect(err).To(HaveOccurred())
|
|
|
|
|
Expect(err).ToNot(MatchError(model.ErrNotFound))
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-08-19 16:25:12 -04:00
|
|
|
|
|
|
|
|
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() {
|
2026-09-25 18:06:10 -04:00
|
|
|
ds.Album().(*tests.MockAlbumRepo).SetData(model.Albums{{ID: "a1"}})
|
2026-08-19 16:25:12 -04:00
|
|
|
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))
|
|
|
|
|
})
|
|
|
|
|
})
|